九月28的项目

来源:互联网 发布:淘宝发货员累吗 编辑:程序博客网 时间:2024/04/30 21:52
flabby_bird






地板运动逻辑:
1. 两个底板都以每0.05秒香左5像素移动,即:
ground.x +=move_speed:
2一旦某一底板离开屏幕显示范围,就将其位置立即放到另一地板后


帧动画循环


图片规律123456


放置规律1234565432完成循环
地板向下移动代码
cc.Class({
    extends: cc.Component,


    properties: {
        //地板的移动速度
        move_speed: -5,
        //地板移动的时间间隔
        move_interval: 0.05,
        // 地板节点数组
        groundNode: {
            default: [],
            type: [cc.Node]
        },
        // 地板图片对象
        groundImg: {
            default: null,
            type: cc.Sprite
        },
    },


    // use this for initialization
    onLoad: function () {
        // 获取屏幕尺寸
        this._size = cc.winSize;
        // 获取地板图片的宽度
        this._height = this.groundImg.spriteFrame.getRect().height;
        // 启动“地板移动控制”计时器
        this.schedule(this.onGroundMove, this.move_interval);


    },


    onGroundMove: function() {
        this.groundNode[0].y += this.move_speed;
        this.groundNode[1].y += this.move_speed;
        if (this.groundNode[0].y + this._height/2 < - this._size.height/2) {
            this.groundNode[0].y = this.groundNode[1].y + this._height - 16;
        }
        if (this.groundNode[1].y + this._height/2 < - this._size.height/2) {
            this.groundNode[1].y = this.groundNode[0].y + this._height - 16;
        }
  },
原创粉丝点击