应该是有踏板的,结果我运行的时候没有踏板显示
处理加载这个预制体的 代码有没有, 附上代码看看
好的好的!!!
cc.Class({
extends: cc.Component,
properties: {
ballNode:cc.Node,
blockPreab:cc.Prefab,
blockAreaNode:cc.Node,
},
onLoad () {
this.initPhysics();
this.node.on('touchstart', this.boost, this);
this.gameStart = 0;
this.initBlock();
},
onDestory(){
this.node.off('touchstart', this.boost, this);
},
update(dt){
if(this.gameStart){
let speed = -450 * dt;
for(let blockNode of this.blockNodeArr){
blockNode.x = speed;
}
}
},
//初始化跳板
initBlock(){
this.lastBlockPosX = this.ballNode.x;//最后一个方块的x轴
this.blockNodeArr = [];
for (let i = 0; i < 10; i++){
let blockNode = cc.instantiate(this.blockPrefab);
blockNode.x = this.lastBlockPosX;
blockNode.y = 0;
this.blockAreaNode.addChild(blockNode);
this.BlockNodeArr.push(blockNode);
this.lastBlockPosX += 200;
}
},
//初始化物理引擎
initPhysics(){
let manager = cc.director.getPhysicsManager();
manager.enabled = true;
manager.gravity = cc.v2(0, -2400);
},
//加速
boost(){
if(this.ballNode.getComponent('ball').initVel){
let rigidbody = this.ballNode.getComponent(cc.RigidBody);
rigidbody.linearVelocity = cc.v2(0, -1600);
this.gameStart = 1;
}
},
});
这个是根据b站 阿信OL大佬视频一起做的,但是出了这种状况,我就解决不了了,麻烦大佬帮助一下我,太感谢了!!
那个踏板叫做block,谢谢您!!!
这个你写错了吧