Zorder Automatically set for you

From Game Editor

Jump to: navigation, search

Setting zorder automatically

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.

Place the following function code in your global code:

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:


tree->Create Actor script:


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.

This is a repost of my Forum submission.

See the Full Discussion:[1]