Cocos2d-Js动画笔记

按照锚点来
        layer1.ignoreAnchorPointForPosition(false);//不忽略锚点
        layer1.setAnchorPoint(0.5,0.5);//默认的锚点就是node的中心,这句可以不写

    npc.stopAllActions();
暂停动画..
避免重复动画问题

延迟加载:
    this.scheduleOnce(this.remove, 1);

资源速度提升

    if(this.sprite==null)
    {
        this.sprite=new cc.SpriteBatchNode("res/h2.png",1);
        this.addChild(this.sprite);
    }
    var sp2=new cc.Sprite(this.sprite.texture/*,cc.rect(0,0,195,270)*/);
    sp2.setScale(0.01);
    this.sprite.addChild(sp2);
    sp2.setPosition(Math.random()*cc.winSize.width,Math.random()*cc.winSize.height);
    sp2.runAction(act);


移除不能删除的节点

    this.removeChildByTag(99);
    this.removeChildByTag(100);
    this.removeChildByTag(110);
    this.removeChildByTag(120);

动画整个流程
    
    var sphero=new cc.Sprite();
    var animation=new cc.Animation();
    for(var i=1;i<=5;i++){
        var frameName="res/walk0"+i+".png";
        animation.addSpriteFrameWithFile(frameName);//
    }
    animation.setDelayPerUnit(0.2);//new cc.Animation(frameUp,0.2);
    var act=cc.animate(animation);
    this.addChild(sphero);
    sphero.runAction(act.repeatForever());
    sphero.setPosition(200,200);

点击
    
    onEnter:function()
    {
        this._super();
        cc.log("初始化完成");
        
        cc.eventManager.addListener({
            event:cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches:true,//吞噬事件 不再传递
            onTouchBegan:this.touchbegan,
            onTouchMoved:this.touchmoved,
            onTouchEnded:this.touchended
        },this)
        
    },

获取动作
    
    var hero=event.getCurrentTarget().getChildByTag(200);
    var run=hero.getActionByTag(300);


//添加系统内置粒子效果
ParticleExplosion。爆炸粒子效果,属于半径模式。
ParticleFire。火焰粒子效果,属于重力径模式。
ParticleFireworks。烟花粒子效果,属于重力模式。
ParticleFlower。花粒子效果,属于重力模式。
ParticleGalaxy。星系粒子效果,属于半径模式。
ParticleMeteor。流星粒子效果,属于重力模式。
ParticleSpiral。漩涡粒子效果,属于半径模式。
ParticleSnow。雪粒子效果,属于重力模式。
ParticleSmoke。烟粒子效果,属于重力模式。
ParticleSun。太阳粒子效果,属于重力模式。
ParticleRain。雨粒子效果,属于重力模式

posted @ 2016-06-30 08:54  Guangmang  阅读(457)  评论(0编辑  收藏  举报