ccc 模拟重力

x=x+v
v=v+gr

cc.Class({
    extends: cc.Component,

    properties: {
        velocity:{
            default:null
        },
        grivatity:{
            default:null
        },

    },

    // use this for initialization
    onLoad: function () {
        this.velocity=30;
        this.grivatity=-1;
    },

    // called every frame, uncomment this function to activate update callback
    update: function (dt) {
        var now=this.node.position
        if(now.y<-250)
        {
            this.velocity=30;
        }
        now.y+=this.velocity;
        this.velocity+=this.grivatity;
        this.node.position=now;
        
    },
});

posted @ 2016-04-29 13:18  yufenghou  阅读(132)  评论(0)    收藏  举报