角色的移动和转身

来源:互联网 发布:mysql递归 编辑:程序博客网 时间:2024/06/06 00:40

properties: {
       bg: cc.Node,
       anim: cc.Animation,
       player : cc.Node,
    },

    // use this for initialization
    onLoad: function () {
        var num = 200
        var that = this
        this.bg.on(cc.Node.EventType.TOUCH_START,function(event){
           var pos = that.player.parent.convertToNodeSpaceAR(event.getLocation())
           var playerPos =that.player.getPosition()
           cc.log( pos,that.player.getPosition())
           if (playerPos.x<pos.x){
           that.player.getChildByName("anim").scaleX = -1
           }
           else {
               that.player.getChildByName("anim").scaleX = 1
           }
           var time = cc.pDistance(pos,playerPos)/num
           var moveto = cc.moveTo(time,pos)
           that.player.stopAllActions()
           that.player.runAction(moveto)
           that.anim.play('plyerRun')
           clearTimeout(that.timeOut)
           that.timeOut = setTimeout(function () {
               that.anim.play('plyerAnima')
           },time*1000)
        })
       
        // for (var i = 0;i<=113)
       
       
       
    },

0 0
原创粉丝点击