on 27-05-2012 06:54 PM
Hey,
I'm using GameEngine2D to create a simple 2D game.
I currently have 2 sprites (the player and the weapon), I want to draw the player on top of the weapon when he is facing away from the screen, and the weapon on top of the player when he is facing towards the camera.
They are both already added to the scene, and It would have to happen inside of the update of the player or weapon.
Removing and adding them to the scene could work but seems highly inefficient. Also I found the Order integer that nodes have, but I have no clue how to use them.
Any help would be greatly appreciated.
Solved! Go to Solution.
28-05-2012 04:47 AM - edited 28-05-2012 04:59 AM
Hey,
First of all, as usual, sorry for my poor english ^^"
For me, you have two way to manage the draw order of your sprites.
1) Using AddChild and the Scene with GameEngine2D:
When you add a SpriteUV (for exemple), to you Scene using AddChild, you give as you say an int to specified the order.
Exemple (more pseudo-code than everything else):
Scene s; SpriteUV sp1; SpriteUV sp2; s.AddChild(sp1, 1); s.AddChild(sp2, 0);
Here, sp2 will be draw before sp1, the SDK will sort the drawing logic from the lowest to the highest order int.
Unfortunately i didn't find a way to change to drawing order, i think for now you can only remove the Sprite then add it with a new value =o/.
2) Your own logic.
Using the n-tree provide by the so nice node logic is not an obligation.
You can just call the Draw method provive in SpriteUV (or to be more precise, in SpriteBase)
So it's not a problem to create you own List or SpriteUV, sort them as you want, then iterate on it to draw them.
I saw there is a Draw method directy in Node, but i have to admit i didn't check what is exactly, i think its just used to place your sprite because on the documentation its only about pushing and poping matrices.
I think it can be a VERY good point to give more infromations in the documentation, especially with all the overridable ones. It's really not convenient for newbies like us to understand everything ^^.
on 28-05-2012 10:37 AM
Thank you for your reply!
My current solution to the problem is to create 2 weapons sprites, instead of 1.
Scene s; SpriteUV weapon1; SpriteUV weapon2; SpriteUV player; s.AddChild(weapon1, 0); s.AddChild(player, 1); s.AddChild(weapon2, 2);
Then in the update logic one of the weapons is hidden, depending on which side the character is facing.
I will take a look at you're 2nd way of doing this because it looks like a better way, although I like to use the simplicity of the Director.
Thanks again for the reply, helped a lot!
on 28-05-2012 03:10 PM
I'm not sure the second way is better, it's just doing the same thing in the different way.
According to me, for drawing, you certainly have a algorithm who go through all your tree, to sort SpriteUV in a list, to draw them by using the Order int (or something like that).
If you make your own list, it's the first step of creating your own game logic.
And i think the n-ary tree provides by Node is one of the best for me.
When your player is changing you can just remove then add again the child, it's working too.
Annnnnd i find something very strange, if an Admin can take a look.
the documentations says:
int Order [get] The draw order value that was set in ReorderChild() or AddChild().
Sounds good, but impossible to find ReorderChild().
It's totally what Ladoku needs here i thing ^^"
on 03-07-2012 08:00 PM
I also noticed Order referring to the private function ReorderChild, I could really do with that function being public as removing the node and readding it at a different z-order seems to be really slow.
Are there any other work arounds?
on 30-07-2012 05:25 PM
on 13-08-2012 03:41 AM
Hey thanks FlamFistAce, this helped me too.
I was looking for a way to do the layer depth or z-index in my game, and the sprite ordering does the same thing.
PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.
フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと
PSM DevPortalを一度ログアウトし、再度ログインしてください。


Website ©2013 Sony Computer Entertainment Europe
All content, game titles, trade names and/or trade dress, trademarks, artwork and associated imagery are trademarks and/or copyright material of their respective owners. All rights reserved. [more info]
%%http://community.eu.playstation.com/t5/Announcements/Beta-Trial-Information/td-p/11386362
best_shooter.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_driver.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_performer.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_footballer.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_fighter.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_creator.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
best_action_player.png%%http://community.eu.playstation.com/t5/Announcements/Introducing-Best-of-PlayStation/td-p/13741979
dev2.png%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/Producer-and-Developer-Ranks/td-p/18407352
trophy.gif%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/The-Community-Awards-FAQ/td-p/18407096
PSlogoSM.png%%http://community.eu.playstation.com/t5/Website-and-Forum-Help-Feedback/Online-Support-Coordinator-rank/td-p/18414870