ccc 模拟重力 正太分布

ball.js

cc.Class({
    extends: cc.Component,

    properties: {
        x_vel:{
            default:0
        },
        y_vel:{
            default:0
        },
        grivatity:{
            default:null
        },

    },

    onLoad: function () {
        
        this.grivatity=-1;
    },
    
    init:function ( x_vel,y_vel) {
        this.x_vel=x_vel
        this.y_vel=y_vel
    },

    update: function (dt) {

        var now=this.node.position
        now.y+=this.y_vel
        now.x+=this.x_vel
        this.y_vel+=this.grivatity
        this.node.position=now
        
        
        //销毁
        if(now.y<-320)
            this.node.destroy();
    },
});

Muller.js

cc.Class({
    extends: cc.Component,

    properties: {
        x_vel:{
            default:0
        },
        y_vel:{
            default:0
        },
        grivatity:{
            default:null
        },

    },

    onLoad: function () {
        
        this.grivatity=-1;
    },
    
    init:function ( x_vel,y_vel) {
        this.x_vel=x_vel
        this.y_vel=y_vel
    },

    update: function (dt) {

        var now=this.node.position
        now.y+=this.y_vel
        now.x+=this.x_vel
        this.y_vel+=this.grivatity
        this.node.position=now
        
        
        //销毁
        if(now.y<-320)
            this.node.destroy();
    },
});

posted @ 2016-04-30 13:25  yufenghou  阅读(229)  评论(0编辑  收藏  举报