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;
        
    },
});

原文地址:https://www.cnblogs.com/yufenghou/p/5445979.html