学习一个新的游戏引擎最好的办法莫过于多看示例代码了,本文主要是学习 \Samples\Sprites 示例后自己写的一个简单的多帧动画。
代码片段如下:
加载动画:
var PIAnimation = Core.Class.singleton({
initialize: function(){
var coinEffect = new GL2.Animation() ;
coinEffect.pushFrame(new GL2.Animation.Frame('Content/ui/effect/coin01.png',
300, [40, 26], [0.5, 0.5], [0,0,1,1])) ;
coinEffect.pushFrame(new GL2.Animation.Frame('Content/ui/effect/coin02.png',
300,[40,26],[0.5,0.5],[0,0,1,1])) ;
this._coinAnim = coinEffect ;
},
getCoinAnim: function(){
return this._coinAnim ;
}
}) ;
/**金币动画*/
var Coin = Core.MessageListener.subclass({
initialize: function(){
// anim
var coinAnim = PIAnimation.getCoinAnim() ;
// node
this._node = new GL2.Node() ;
this._node.setPosition(110,27) ;
// sprite
this._sprite = new GL2.Sprite();
this._sprite.setAnimation(coinAnim) ;
this._node.addChild(this._sprite) ;
Core.UpdateEmitter.addListener(this, this.onUpdate);
},
onUpdate: function(delta){
},
getCoinNode: function(){
return this._node ;
},
destroy: function(){
this._sprite.destroy() ;
this._node.destroy() ;
}
}) ;
/**金钱动画*/
var coinNode = new Coin() ;
this.sBackground.addChild(coinNode.getCoinNode()) ;