Jump to content

Simpler method of adjusting depth?


NewGuy
 Share

Recommended Posts

Hello again, guys.

I've seen quite a few questions on here addressing object depth and ways of sorting their depth order and whatnot, but so far I'm yet to get a nice solution to my problem. I'll lead with an image;

example.png.d21e1da02f7c249b2b2852f54d1d

What we have here is my attempt at a 2.5D type game, where the purple rectangle represents the player, the red lines show the perspective and the green lines are trying to demonstrate the depth of the flags coming towards the player.

My issue is simple but quite important for the mechanics of the game, the flags move towards the player and the player zig zags around them (like Slalom skiing!), my issue is I need to have the flags behind the player and then once past the dotted line (foot of the player) they move to in front of the player. I've seen techniques that involve moving the items back and forth from a background and foreground group, I take issue with this method as I recycle my flags (object pooling) and their place in the pool group is important and I'm not sure if I can move them through another group without stuffing with my pooling.

I think I've explained the problem, any body have a suggestion or solution? Any words welcomed!

(ps. sorry for wall of text) :)

Link to comment
Share on other sites

Thanks for replying, Rich! Also sorry because I didn't explain myself properly . . at all. The idea is I want the flags to move infront/behind the player, this in my mind required creation order be foreground group> player > background group and I'd move the flags from foreground to background and my issue was the flags already reside in their object pool. I hacked a solution where I created my player inside the flag pool and sorted on the y like you said and that worked. Feel like that's a bit gross, though.

Hope that made a little more sense? (:

Link to comment
Share on other sites

Yeah I understood what you were after, and doing a Group.sort on the y property would shuffle the objects around properly, ordering them in display order based on the y depth down the screen. It would however require that the player was part of the same Group, to be included with the sort. It could easily be filtered out from any Group iteration though to avoid breaking your pooling (although if you think about it, the Player would never be 'dead' anyway, so wouldn't ever be considered as valid for pool recycling).

I agree it's not elegant, but with the way the Groups are display lists in their own right there's no alternative in Phaser (beyond rolling your own of course, maybe extending Pixi.DisplayObjectContainer and adding what you need to that - or creating your own pool manager)

Link to comment
Share on other sites

42 minutes ago, rich said:

Yeah I understood what you were after, and doing a Group.sort on the y property would shuffle the objects around properly, ordering them in display order based on the y depth down the screen. It would however require that the player was part of the same Group, to be included with the sort. It could easily be filtered out from any Group iteration though to avoid breaking your pooling (although if you think about it, the Player would never be 'dead' anyway, so wouldn't ever be considered as valid for pool recycling).

I agree it's not elegant, but with the way the Groups are display lists in their own right there's no alternative in Phaser (beyond rolling your own of course, maybe extending Pixi.DisplayObjectContainer and adding what you need to that - or creating your own pool manager)

Thanks, Rich. I moved the player to the flag pool and the ordering works and that's all I need. Thanks for replying. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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