动画添加

var bg = new BgSp(res.bgPng)
         this.addChild(bg)


        /*cc.spriteFrameCache.addSpriteFrames(res.animation_plist); //加载plist文件
        var mExplodeFrames = [];
        for (var i=1;i<17;i++)
        {
            var frame = cc.spriteFrameCache.getSpriteFrame("explosion_"+("00"+i).slice(-2)+".png");
            mExplodeFrames.push(frame);
        }
        var anim = new cc.Animation(mExplodeFrames, 0.04);*/




        /*cc.spriteFrameCache.addSpriteFrames(res.animation_plist);
        var animFrames = [];
        var str = "";
        for (var i = 1; i < 35; i++) {
            str = "explosion_" + (i < 10 ? ("0" + i) : i) + ".png";
            animFrames.push(cc.spriteFrameCache.getSpriteFrame(str));
        }
        var animation = new cc.Animation(animFrames, 0.025);
        cc.animationCache.addAnimation(animation, "Explosion");
        var anim = cc.animationCache.getAnimation("Explosion")*/
        var that = this
        var listener = cc.EventListener.create({
            event:cc.EventListener.TOUCH_ONE_BY_ONE,
            swallowTouches:true,
            onTouchBegan:function(touch, event){
                var sp = new cc.Sprite()
                sp.setPosition(touch.getLocation())
                that.addChild(sp)
                sp.runAction(cc.sequence(cc.animate(anim), cc.fadeOut(0.5))) //点击的位置播放动画
                return true;
            },
        });

        cc.eventManager.addListener(listener, this)






var BgSp = cc.Sprite.extend({
    sp1:null,
    sp2:null,
    moveSpeed:10,
    ctor:function(res){
        this._super()
        this.sp1 = new cc.Sprite(res)
        this.sp2 = new cc.Sprite(res)
        this.addChild(this.sp1)
        this.addChild(this.sp2)
        this.sp1.setAnchorPoint(0,0)
        this.sp1.setPosition(0,0)
        this.sp2.setAnchorPoint(0,0)
        this.sp2.setPosition(0, this.sp2.height)
        this.scheduleUpdate()
    },
    update:function(){
        this.sp1.y-= this.moveSpeed
        this.sp2.y-= this.moveSpeed
        if(this.sp1.y< -this.sp1.height){
            this.sp1.y = this.sp2.y+this.sp2.height
        }
        if(this.sp2.y< -this.sp2.height){
            this.sp2.y = this.sp1.y+this.sp2.height
        }
    }
})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值