Page 1 of 1

zorder automatically set for you

PostPosted: Sat Apr 28, 2007 12:24 pm
by DocRabbit
For those who don't want to fool with figuring out zorder by position, try this code to set it on launch by position. In other words, object near the top are farther away and farther down in the order. objects in front of your player appear over your player. This works with view parented to your player, or using the smooth scrolling method mak describes in this area. For static actors, like trees, rocks, etc., place the call to global code in the actor create call. For mobile actor (player) place call in draw actor.

Global code:
Code: Select all
void stackit(){
ChangeZDepth("Event Actor", ((y/240)+1)*.5);
              }

The 240 is actually half the window size, so adjust this for your window.

player->Draw Actor script:
Code: Select all
stackit();


tree->Create Actor script:
Code: Select all
stackit();


Everyone may already know this and be using it, but I haven't seen it posted anywhere and may not be the right way to do it, but it works for me and I thought maybe someone else might find it useful. :)

PostPosted: Sat Apr 28, 2007 7:35 pm
by Fuzzy
Good job. Probably a good place to post something that I use..

Put this in a text file then load it as global code.

#define HIDDEN -100
#define BACKGROUND 0
#define EARTH 0.1
#define GRASS 0.2
#define PAVEMENT 0.3
#define FOUNDATION 0.4
#define OBJECT 0.5
#define CREATURE 0.6
#define PLAYER 0.7
#define WEATHER 0.8
#define CLOUD 0.9
#define HUD 1.0

Used in conjunction with DocRabbits code, you could sort everything from top to bottom of the screen, using my #defines to sort them according to type.

One point for DocRabbit!

PostPosted: Sat Apr 28, 2007 11:48 pm
by Game A Gogo
interesting to both of you!
DocRabbit, that method is very useful for RPGs!

PostPosted: Sun Apr 29, 2007 2:21 am
by DocRabbit
After some trial and error using my code, I have come up with a couple of revisions that could be handy to keep player planted on ground and score planted above. Just use if statements to evaluate Global code for <0 and >.999 and force them to one or the other. That way score type can be 1.000 and float over all, and ground can be 0 and player won't disappear moving up if screen scrolls on big playing field.

PostPosted: Sun Apr 29, 2007 2:30 am
by Game A Gogo
yes, useful again ^^
I remember me using something similar.

PostPosted: Wed May 02, 2007 9:49 pm
by Sgt. Sparky
Game A Gogo wrote:yes, useful again ^^
I remember me using something similar.

I made my own zdepth calculation for my trees in my 3D verison(it was all calculation of positions on canvas and scale) and in my other fake 3D version that did not scale. :D