Jump to content

Basic Projectile Understanding


mhcdotcom
 Share

Recommended Posts

Hey All,

    var bomb = this.bombs.create(this.enemy1.x, this.enemy1.y, 'bomb');
    bomb.setGravityY(-1500);
    bomb.body.velocity.x = -400;

    bomb.outOfBoundsKill = true;

The bomb appears as expected.
With the above in place I don't get any console errors.
I got the `bomb.outOfBoundsKill  = true;` reference from multiple Phaser 2 resources but cannot find the equivalent for phaser 3.

I want to confirm it is being destroyed as expected but I cannot find a method for firing a callback when an image instance leaves the world bounds. 
I saw this one: `bomb.events.onOutOfBounds.add(functionName, this)` but this fires errors in the console.

If you could help me understand what is going on here, it would be much appreciated.

Link to comment
Share on other sites

On 10/30/2018 at 2:20 PM, samme said:

Phaser 3 has no Bullet class and no outOfBoundsKill property.

You can use the worldbounds event.

I don't know what a bullet classe is. 

The worldbounds event is useful for when the balls are set to collide with the world bounds(collideWorldBounds = true).

I want to detect when the ball has left the game world bounds when collideWorldBounds = false. 

Reason being, I want entities to get destroyed once they have left the world bounds so performance doesn't suffer. 

I'm seeing now after some research I could do something like:

if (bomb < this.scene.physics.world.bounds.left) {
 bomb.destroy()
}

Would that be an ideal method for what I want to accomplish?

Thanks for your time

Link to comment
Share on other sites

Thanks @samme

I appreciate your time. Your method for removing the bomb looks good.

Ideally i still want the bomb sprites to leave the screen before being disabled, with your method the bomb disappears as soon as it touches the world bounds.

What is the difference between
bomb.disableBody(true, true)
and 
bomb.destroy()
?

Is the method I mentioned in my previous comment not ideal?
I could update it to look like

if (bomb < this.scene.physics.world.bounds.left+bomb.width) {
 bomb.destroy()// or bomb.disableBody(true, true)
}

to ensure it is completely offscreen.

I hope you can still help.
Thanks again. 

Edited by mhcdotcom
clarity
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...