Jump to content

Bullets above my player sprite?


Dower
 Share

Recommended Posts

This seems like a simple z-order or positional issue. But I have a simple top down shooting example, and I want to have a player at the bottom which can rotate in place and shoot. Now overall the example is working. But the problem I'm having is the bullets are above the player sprite location. In my test case, I have boxes, and the bullets are originating from the center anchor point of my sprite. I'm trying to figure out how I can hide that by moving the player above the bullets, or if possible reposition the firing to the front of the player. My initial test was to adjust the Y, but that doesn't work when the sprite rotates... Is there some sort of local coordinate system I should use for position the origin of the shots?

 

Here's my current example using Phaser Sandbox: http://phaser.io/sandbox/LsJAGKsr

 

In the sandbox demo it's only slightly noticeable, my local test with boxes, it's more evident.

Link to comment
Share on other sites

Oh god! I think I figured it out!!!!

It looks like if I just created my bullet group first, then my player, it appears in the order I want...

 

So my create function looks like this now, before this, the player was made before the bullets group... 

 

// Create our Bullet Group
this.bullets = game.add.group();
this.bullets.enableBody = true;
this.bullets.createMultiple(5,"bullet");
this.bullets.setAll("anchor.x", 0.5);
this.bullets.setAll("anchor.y", 0.5);
this.bullets.setAll('outOfBoundsKill', true);
this.bullets.setAll('checkWorldBounds', true);
this.bullets.z = 1;
 
// Put the player on the screen, centered
this.player = game.add.sprite(game.world.stage.width/2,game.world.stage.height-25,"player");
this.player.anchor.setTo(0.5);
this.player.angle = -90;
 
If anyone has any other more elegant way of handling z-order, please let me know.
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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