Z-Depth in Canvas

Non-platform specific questions.

Z-Depth in Canvas

Postby Hblade » Wed Oct 08, 2014 9:49 pm

I noticed that while using a canvas, it draws from the first line that it reads, so therefor if you want to dynamically change which appears first inside of a canvas, you'd have to write some sort of mega script... Is there a simple way to tell the canvas to read whats in front, before it reads other things?

For example, lets say you were using draw_from, and you had this set up:

draw_from(id1, x, y);
draw_from(id2, x, y);
draw_from(id3, x, y);
draw_from(id4, x, y);

id4 would always be in front of the other ids, so how would I change this lol?
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Z-Depth in Canvas

Postby skydereign » Thu Oct 09, 2014 7:15 am

You put all the things you want to draw into an array and sort them according to your desired z value. For instance if you were using this struct you could sort the array of structs via the z value.
Code: Select all
typedef struct
{
    char cloneName[30];
    int x, y, z;
} DrawOp;

DrawOp canvas_operations[100]; // you can add draw operations by adding it into this array
// then in your canvas' draw actor you sort by z and then loop through calling draw_from with each
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Z-Depth in Canvas

Postby Hblade » Thu Oct 09, 2014 4:27 pm

Thanks, I'll give it a try :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Z-Depth in Canvas

Postby Zivouhr » Sun May 31, 2015 11:03 pm

Interesting thread about zdepth.

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.

Here's what I tried. It works and as the appear from a higher spawning point, the enemies are layered properly, but just need a way to update it just in case the clones change position when going back up the screen towards the player. Since they're at the same speed, it's not as critical, but if I add new enemies in the mix at different speeds, this may become a bigger problem.

enemy/draw actor/script editor:

Code: Select all
if (yscreen>y)  //if the enemy clone’s yscreen position is greater than other clone’s Y
{
ChangeZDepth (“Event Actor”, 0.9);  //closer up layer
}
else
if(yscreen<y) //if the enemy clone’s yscreen position is less than other clone’s Y

{
ChangeZDepth (“Event Actor”, 0.1);  //farther back layer
}
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score

Re: Z-Depth in Canvas

Postby skydereign » Tue Jun 02, 2015 11:28 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Z-Depth in Canvas

Postby bat78 » Wed Jul 29, 2015 1:58 am

ACTUALLY
This is exactly what I was working on (for a day or less) in order to allow scrolling without re-rendering the entire canvas but only the amount I want!

(Before that I want to interject that you can do that by using savecanvas() (Although it saves only one state for the local canvas so you can only have 2D rendering, background and a foreground.. and it doesn't allow "overlapping")

I have a long-lasting experience in this actually.. but there is no point in me story-telling you.
gE canvas work only superficially. They cannot have LAYERS. One pixel, placed on top of another replaces it.

And the only way to simulate layers and be able to recover any part of the canvas, from a previous drawing
is to store the colours of each of the pixels placed on the corresponding position, relative to the canvas.
So I created "MDI" (or Mapping Drawing Interface) which allows you to easily do that and it does it in a very self-automatic manner.
It will be released soon along the parent project so worry not.
The future of "Game-Editor" here
User avatar
bat78
 
Posts: 816
Joined: Sun Dec 14, 2008 9:13 pm
Location: Bulgaria, Sofia
Score: 88 Give a positive score

Re: Z-Depth in Canvas

Postby Zivouhr » Sat Oct 03, 2015 12:08 am

That sounds promising Bat. 8)

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. :D
City of Rott Game created on Game Editor http://cityofrott.wordpress.com/
User avatar
Zivouhr
 
Posts: 549
Joined: Sat May 17, 2014 2:12 pm
Score: 59 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron