作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想杀死子弹,因为它与小行星重叠,但它不起作用。请看一下我的代码。我多次查看代码,但一切看起来都正确。我还想在小行星上进行碰撞。
game.js
var bullets;
var Game = {
preload: function() {
// Load the needed image for this(play) game screen.
//load the menu screen
this.load.image('menu', './assets/images/menu.png');
// Here we load all the needed resources for the level.
// background image screen
this.load.image('playgame', './assets/images/back.png');
// globe image screen
// this.load.image('playgame', './assets/images/back.png');
this.load.image('spaceship', './assets/images/spaceship.png');
// Astroid image screen
this.load.image('astroid1', 'assets/images/asteroid1.png');
this.load.image('astroid2', 'assets/images/asteroid2.png');
this.load.image('astroid3', 'assets/images/asteroid3.png');
this.load.image('astroid4', 'assets/images/asteroid4.png');
//Load the bullet
this.load.image('bullet', 'assets/images/bullet.png');
},
create: function() {
// By setting up global variables in the create function, we initialise them on game start.
// We need them to be globally available so that the update function can alter them.
//this will show the physics of background
game.physics.startSystem(Phaser.Physics.ARCADE);
// The scrolling starfield background
gameback = game.add.tileSprite(0, 0, 800, 600, 'playgame');
textStyle_Value = {
font: "bold 20px Segoe UI",
fill: defTextColor,
align: "center"
};
textStyleAns = {
font: "bold 22px 'Comic Sans MS', 'Comic Sans'",
fill: ansTextColor,
wordWrap: true,
wordWrapWidth: 10,
align: "center"
};
textStyleQues = {
font: "bold 20px 'Comic Sans MS', 'Comic Sans'",
fill: defTextColor,
wordWrap: true,
wordWrapWidth: 10,
align: "center"
};
// Loading questionbar image
this.questionbar();
// csll fun. for place astroid
this.astroid();
// call fun. for Ans
this.generateQues();
this.generateAns();
// Call fun. for ques
this.comeQus();
// Call fun. for ques
this.comeAns();
// Loading Diamond image
this.diamond();
// Start timer
this.startTimer();
// Set timer.
this.setTimer();
this.initLoader();
bullets = game.add.group();
bullets.enableBody = true;
bullets.physicsBodyType = Phaser.Physics.ARCADE;
bullets.createMultiple(500, 'bullet', 150, false);
// bullets.setAll('anchor.x', 0.5);
// bullets.setAll('anchor.y', 0.5);
bullets.setAll('outOfBoundsKill', true);
bullets.setAll('checkWorldBounds', true);
sprite = game.add.sprite(400, 530, 'spaceship');
sprite.anchor.set(0.4);
// Playing backgroud music
fun_bckg = this.add.audio('fun_bckg', 1, true);
fun_bckg.volume = 0.5;
this.playFx('fun_bckg');
// Bullet fire music
fire_bullet = this.add.audio('fire_bullet', 1, true);
fire_bullet.volume = 0.5;
//this.playFx('fire_bullet');
},
astroid: function() {
astroid1 = this.add.button(25, 100, 'astroid1', this.astroidClicked, this);
astroid2 = this.add.button(250, 30, 'astroid2', this.astroidClicked, this);
astroid3 = this.add.button(400, 40, 'astroid3', this.astroidClicked, this);
astroid4 = this.add.button(570, 100, 'astroid4', this.astroidClicked, this);
},
fire: function() {
this.playFx('fire_bullet');
if (game.time.now > nextFire && bullets.countDead() > 0) {
nextFire = game.time.now + fireRate;
var bullet = bullets.getFirstDead();
bullet.reset(sprite.x - 0, sprite.y - 140);
game.physics.arcade.moveToPointer(bullet, 300);
}
}
}
function collisionHandler(bullets, astroid1) {
alert("hello");
// When a bullet hits an alien we kill them both
bullets.kill();
astroid1.kill();
}
.
最佳答案
据我所知,您应该将碰撞检查放入更新函数中,如下所示:
update: function() {
// check for collisions
game.physics.arcade.collide(bullets, asteroid, this.bulletHitAsteroid, null, this);
}
并杀死该函数中的 Sprite (在本例中为bulletHitAsteroid 函数)。
bulletHitAsteroid(_bullets, _asteroid): function() {
_bullet.kill();
_asteroid.kill();
}
我希望这会有所帮助。
关于javascript - game.physical.arcade.overlap() 在移相器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38637358/
现在我正在尝试实现 flash programming specification对于 PIC32MX。我正在使用 PIC32MX512L 和 PIC32MX512H。 PIC32MX512L最终必须
我是一名优秀的程序员,十分优秀!