Bahavior to access layers (for easy depth sorting/swapping)
Snow
Member Posts: 124
As the title says, I would like to be able to access or change what depth/layer an actor is on. I noticed yesterday, that if you have 2 actors on a single layer - they're put on individual layers/depths themselves. Swapping the order of them in the Scene Layers panel would put one in front of the other. I want to be able to access that from a behavior. In a Flash game I wrote, in Actionscript 2 there is the following line of code that does this very easily:
this.swapDepths(this._y) or just _y
As the actor moved down, it's depth number would change and would always ensure that it was in front of other actors or props with a lower number.
There was still a problem with this though as if 2 characters shared the same y-axis - they'd end up on the same depth which could result in problems. So, the actor still needed a specific number that was also unique. I came up with:
this.swapDepths(this._x + this._y*world_width);
Would it be possible for you guys to code this into the engine, based ont he above logic and add a single behaviour for it?
The behaviour could just be a boolean: Unique Depth = true/false
If true, then no matter where you are in the scene you have a unique depth and as long the Unique Depth function is incrementing or decrementing based on your orientation (landscape/portrate), your actor will properly be in front or behind of other actors.
For it to work properly, every actor you'd want to swap depths with would have to be on the same scene layer. That could get confusing, but if you're organized it's manageable.
This simple behaviour would make tons of different game types much more easily possible without resorting to trickery or complex schemes.
this.swapDepths(this._y) or just _y
As the actor moved down, it's depth number would change and would always ensure that it was in front of other actors or props with a lower number.
There was still a problem with this though as if 2 characters shared the same y-axis - they'd end up on the same depth which could result in problems. So, the actor still needed a specific number that was also unique. I came up with:
this.swapDepths(this._x + this._y*world_width);
Would it be possible for you guys to code this into the engine, based ont he above logic and add a single behaviour for it?
The behaviour could just be a boolean: Unique Depth = true/false
If true, then no matter where you are in the scene you have a unique depth and as long the Unique Depth function is incrementing or decrementing based on your orientation (landscape/portrate), your actor will properly be in front or behind of other actors.
For it to work properly, every actor you'd want to swap depths with would have to be on the same scene layer. That could get confusing, but if you're organized it's manageable.
This simple behaviour would make tons of different game types much more easily possible without resorting to trickery or complex schemes.