gpt4 book ai didi

javascript - 移相器 : Key Down + Collision Kill

转载 作者:行者123 更新时间:2023-11-28 04:57:28 25 4
gpt4 key购买 nike

预警:半新手

基本上,如果用户将左光标向下并且“ token ”与lftRect发生碰撞,我想杀死该 token 。由于某种原因,我的碰撞终止回调函数无法正常工作(下面是相关代码):

gumballGoGo.Preloader = function(game){
this.player = null;
this.ground = null;
//this.tokens = null;
this.ready = false;
};

var cursors, lftInit, rghtInit, ground, testDrp, sprite, tokens, rect, lftRect, ctrRect, rghtRect, lftToken;
var total = 0;

function lftHit(lftRect, lftToken) {
if ( lftInit == true ){
lftToken.kill()
}
};

gumballGoGo.Preloader.prototype = {
preload: function(){
},

create: function() {

// LFT BOX
lftRect = this.add.sprite(0, this.world.height - 150, null);
this.physics.enable(lftRect, Phaser.Physics.ARCADE);
lftRect.body.setSize(100, 100, 0, 0);


// CNTR BOX
ctrRect = this.add.sprite(100, this.world.height - 150, null);
this.physics.enable(ctrRect, Phaser.Physics.ARCADE);
ctrRect.body.setSize(100, 100, 0, 0);


// RGHT BOX
rghtRect = this.add.sprite(200, this.world.height - 150, null);
this.physics.enable(rghtRect, Phaser.Physics.ARCADE);
rghtRect.body.setSize(100, 100, 0, 0);


// INIT TOKEN GROUP
tokens = this.add.group();
tokens.enableBody = true;
this.physics.arcade.enable(tokens);

testDrp = tokens.create(125, -50, 'token');
testDrp.body.gravity.y = 300;



// CONTROLS
this.cursors = this.input.keyboard.createCursorKeys();

},

update: function() {
this.ready = true;

if (this.cursors.left.isDown)
{
lftInit = true;
}
else if (this.cursors.right.isDown)
{
rghtInit = true;
}
else
{
lftInit, rghtInit = false;

}

if (total < 20)
{
tokenSpawn();
}

this.physics.arcade.collide(lftRect, lftToken, lftHit, null, this);

}
};


function tokenSpawn() {

lftToken = tokens.create(25, -(Math.random() * 800), 'token');

lftToken.body.gravity.y = 300;

total++;

}

最终目标是recreate this type of gameplay

还有一点需要注意:截至目前,我正在使用随机生成循环来丢弃“ token ”。我宁愿使用定时模式来掉落 token 。如果您对此有任何建议,也请分享。谢谢:]

最佳答案

不确定,所以这是一个猜测,但是您将“this”的最后一个参数应用于gumballGoGo.Preloader.prototype对象之外的函数“lfthit”。您在控制台中遇到什么错误?

关于javascript - 移相器 : Key Down + Collision Kill,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42428955/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com