Graphics

Reply

Member

Member
Ladoku
Posts: 2
Registered: ‎27-05-2012
Message 1 of 7 (622 Views)
Accepted Solution

How to change the draw order of sprites

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.

Please use plain text.

Re : How to change the draw order of sprites

[ Edited ]

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 ^^.

When I get sad, I stop being sad, and be AWESOME instead.
Please use plain text.

Member

Member
Ladoku
Posts: 2
Registered: ‎27-05-2012
Message 3 of 7 (587 Views)

Re : How to change the draw order of sprites

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!

Please use plain text.

Re : How to change the draw order of sprites

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 ^^" 


When I get sad, I stop being sad, and be AWESOME instead.
Please use plain text.

Level 1

Level 1
Smoggie83
Posts: 20
Registered: ‎25-06-2012
Message 5 of 7 (471 Views)

Re : How to change the draw order of sprites

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?

Please use plain text.

Re : How to change the draw order of sprites

Thanks for the report FlamFistAce, we'll see if we can get this documentation error fixed.

- James
PlayStation®Mobile Dev Team
Please use plain text.

Level 1

Level 1
CheneysGotAGun
Posts: 27
Registered: ‎03-07-2012
Message 7 of 7 (371 Views)

Re : How to change the draw order of sprites

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.

Please use plain text.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

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を一度ログアウトし、再度ログインしてください。