cocos_creator之Flabby Bird

游戏主要逻辑

1,地板滚动

 两块地板循环滚动,没啥好说的。
核心代码:
this.groundNode[0].x += Constant.GROUND_VX;
        this.groundNode[1].x += Constant.GROUND_VX;
        if (this.groundNode[0].x + this._width/2 < - this._size.width/2) {
            this.groundNode[0].x = this.groundNode[1].x + this._width - 5;
        }
        if (this.groundNode[1].x + this._width/2 < - this._size.width/2) {
            this.groundNode[1].x = this.groundNode[0].x + this._width - 5;
        }

2,小鸟坠落与弹跳

坠落的效果需要让小鸟在Y轴负方向有一个加速度,即单位时间类的偏移量还有一个增量。弹跳只需要让原本为负的偏移值变为正。
在onLoad方法中:
this.velocity = 0; //初始下降速度为零
在onDrop方法中:
this.node.y  += this.velocity ;
this.velocity -= this.gravity;

3,管道生成逻辑

管道的定位需要五个参数
pipeMaxOffsetY   //Y轴最大偏移量
pipeMinGap        //管道最小间隙
pipeMaxGap       //管道最大间隙
pipeSpawnInterval      //管道生成时间间隔
pipeSpawnOffsetX      //管道屏幕外生成偏移量
核心代码:
spawnPipes: function() {
   
        // 从管道预制(上端),生成管道实例
        var pipeUp = cc.instantiate(this.pipePrefabs[Constant.PIPE_UP]);
        // 定义为上端类型
        pipeUp.getComponent('Pipe').init(Constant.PIPE_UP);
        // 获取管道的高度(上端与上端的相同)
        var pipeHeight = pipeUp.getComponent(
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值