That sounds promising Bat.
skydereign wrote:Zivouhr wrote:Would a canvas be the easiest way to change the zdepth depending on whether the enemy clones are lower in the screen (near) or higher in the screen (farther)? And would it work for spawned enemies from an enemy spawner?
Trying to create a side scrolling beat em up game and have some clumsy ways to change the zdepth, including using different region rectangles that are contacted by the bottom of the enemy to change the enemy clone's zdepth, but it doesn't work smoothly when the closer enemy has to overlap the farther enemy.
You can use yscreen as a way of setting zdepth.
- Code: Select all
ChangeZDepth("Event Actor", yscreen);
You can batch it as well if you need to by using yscreen/view.height or similar. Another thing I'd recommend is setting zdepth by the bottom of the actor (so use yscreen+height/2 instead). That way you can have any sized sprite and it should sort properly.
Cool. I forgot to check back in this thread, but thank you for the idea and format of the code! I'll test it out. Thank you Skydereign!
The most success I've had earlier before revisiting this thread, was to create a group of 4 infinite X horizontal blocks (visibility state not drawn but events active) and line them up from bottom to top so each time the bottom of the enemy or player hits it (repeat on), then they try to adjust accordingly based on the zdepth block they're contacting onscreen.
The zdepth blocks (0 through 2 for example = 3 clones) managing the code under collision/bottom side of/player: Script Editor
- Code: Select all
if(cloneindex==0) //bottom of screen placed block, "front of screen", this is zblock.0
{
ChangeZDepth("Event Actor", 0.9 );
}
if(cloneindex==1) //middle of screen placed block, "middle range of screen", this is zblock.1
{
ChangeZDepth("Event Actor", 0.6 );
}
if(cloneindex==2) //top of screen placed block, "back of screen"
{
ChangeZDepth("Event Actor", 0.1 );
}
EDIT: I need more practice with this code, but here's a rough idea of what I'm attempting to assemble for code:
EDIT 2: Just copy/pasted my code below into the draw actor fields of the enemy and the player. The enemy layering is working perfect so far. The player though, gets tucked underneath the enemies even when standing in front (at the bottom of the screen), so I got to figure out how to adjust for the player.
enemy (and player) /draw actor/script editor: //and then put this code in with the draw actor of the enemy script editor. No other code needed other than in the draw event of the characters, including the player and the separate enemies.
- Code: Select all
if(yscreen+height/2>collide.yscreen+height/2) //I only half understand what this does. ;)
{
ChangeZDepth("Event Actor", yscreen+height/2);
}
else
if(yscreen+height/2<collide.yscreen+height/2)
{
ChangeZDepth("Event Actor", yscreen-height/2); //This is the same as above, but I made a minus after yscreen.
}
//That worked really well so far for the enemies forming from below and above, over 20 enemies blending into the right order as intended in front and behind so far.
Just need to get the player to stand out in front of them now, as his identical code isn't setting him up front probably because he's got the same code as the enemies.
EDIT 3: SUCCESS! Now it's working perfect for the ZDepth layers of the characters onscreen, smoothly and consistently moving from front to back and vice versa without glitching back and forth awkwardly as my other coding was doing.
It works! I've been trying to figure this stuff out for weeks/months.
The reason the player wasn't working like the enemies is because I forgot to remove the old code from his collision with the enemies.
This is seriously the best zdepth layering code I've been able to implement to the side scrolling brawler style game. Thanks again Skydereign for the initial spark to figure this out.