标签:c++ cocos2d cocos2d-x 开发人员 游戏
Cocos2d-JS提供了很多特效,这些特效事实上属于间隔动作,特效类cc.GridAction类,也称为网格动作,它的类图如下图所示。ctor: function (flagTag) { this._super(); this.flagTag = flagTag; this.gridNodeTarget = cc.NodeGrid.create(); ① this.addChild(this.gridNodeTarget); cc.log("MyActionLayer init flagTag " + this.flagTag); var size = cc.director.getWinSize(); var bg = new cc.Sprite(res.Background_png); bg.x = size.width / 2; bg.y = size.height / 2; this.gridNodeTarget.addChild(bg); var sprite = new cc.Sprite(res.hero_png); sprite.x = size.width / 2; sprite.y = size.height / 2; this.gridNodeTarget.addChild(sprite, 1, SP_TAG); var backMenuItem = new cc.MenuItemImage(res.Back_up_png, res.Back_down_png, function () { cc.director.popScene(); }, this); backMenuItem.x = 140; backMenuItem.y = size.height - 65; var goMenuItem = new cc.MenuItemImage(res.Go_up_png, res.Go_down_png, this.onMenuCallback, this); goMenuItem.x = 820; goMenuItem.y = size.height - 540; var mn = new cc.Menu(backMenuItem, goMenuItem); this.gridNodeTarget.addChild(mn, 1); mn.x = 0; mn.y = 0; mn.anchorX = 0.5; mn.anchorY = 0.5; return true; }上述代码第①行是创建NodeGrid类型成员变量gridNodeTarget,NodeGrid是网格动作管理类。MyActionScene.js中的onMenuCallback函数代码如下:
onMenuCallback: function (sender) { cc.log("Tag = " + this.flagTag); var size = cc.director.getWinSize(); switch (this.flagTag) { case ActionTypes.kFlipX3D: this.gridNodeTarget.runAction(cc.flipX3D(3.0)); ① break; case ActionTypes.kPageTurn3D: this.gridNodeTarget.runAction(cc.pageTurn3D(3.0, cc.size(15, 10))); ② break; case ActionTypes.kLens3D: this.gridNodeTarget.runAction(cc.lens3D(3.0, cc.size(15, 10), cc.p(size.width / 2, size.height / 2), 240)); ③ break; case ActionTypes.kShaky3D: this.gridNodeTarget.runAction(cc.shaky3D(3.0, cc.size(15, 10), 5, false)); ④ break; case ActionTypes.kWaves3D: this.gridNodeTarget.runAction(cc.waves3D(3.0, cc.size(15, 10), 5, 40)); ⑤ break; case ActionTypes.kJumpTiles3D: this.gridNodeTarget.runAction(cc.jumpTiles3D(3.0, cc.size(15, 10), 2, 30)); ⑥ break; case ActionTypes.kShakyTiles3D: this.gridNodeTarget.runAction(cc.shakyTiles3D(3.0, cc.size(16, 12), 5, false));⑦ break; case ActionTypes.kWavesTiles3D: this.gridNodeTarget.runAction(cc.wavesTiles3D(3.0, cc.size(15, 10), 4, 120)); ⑧ break; } }
第⑧行是使用WavesTiles3D实现3D瓦片波动特效,cc.wavesTiles3D函数第一个参数是持续时间,第二个参数是网格的大小,第三个参数动次数,第四个参数是振幅。
《Cocos2d-x实战 JS卷》现已上线,各大商店均已开售:
京东:http://item.
标签:c++ cocos2d cocos2d-x 开发人员 游戏
原文地址:http://blog.csdn.net/tonny_guan/article/details/44728229