var res = { SACHIKO1 : "res/nawatobi/sachiko01.png", SACHIKO2 : "res/nawatobi/sachiko02.png", }; // Tag var MyLayerTag = 0; var MyLayerSpriteSachiko = MyLayerTag; var MyLayer = cc.KidspodLayer.extend({ init:function(){ this._super(); this.schedule(this.update); var size = cc.director.getWinSize(); // Sachiko var spriteSachiko = cc.Sprite.create(res.SACHIKO1); spriteSachiko.setPosition(cc.p(size.width/2, size.height/2)); spriteSachiko.setTag(MyLayerSpriteSachiko); this.addChild(spriteSachiko); // Animation var actionJump = cc.JumpBy.create(0.7, cc.p(0,0), 30, 1); var funcHappy = cc.CallFunc.create(function () { spriteSachiko.setTexture(cc.textureCache.addImage(res.SACHIKO2)); }, spriteSachiko); var spawn = cc.Spawn.create(actionJump, funcHappy); var funcNormal = cc.CallFunc.create(function () { spriteSachiko.setTexture(cc.textureCache.addImage(res.SACHIKO1)); }, spriteSachiko); var actionDelay = cc.DelayTime.create(1.5); var seq = cc.Sequence.create(spawn, funcNormal, actionDelay); spriteSachiko.runAction(cc.RepeatForever.create(seq)); return true; }, update:function(dt){ }, onMouseDown:function(event){ }, onKeyPressed:function(key, event){ }, onTouchBegan:function(touch, event){ }, onAccelerometer:function(accelero, event){ }, }); var MyScene = cc.Scene.extend({ onEnter:function (){ this._super(); var layer = new MyLayer(); layer.init(); this.addChild(layer); } });