Solved Change setlayer in spawn level

Question that is answered or resolved.

dantedevil

Well-known member
I have this entity that in the header of its txt has setlayer -2. This entity is characterized by having many custom animations, plus I always place it against the background.
Code:
spawn   codes
@script
void main() {
    performattack(getlocalvar("self"), openborconstant("ANI_freespecial1"));
} @end_script
coords  143 188
flip    1
at      0

Now I'm going to use one of their custom spawns, but I want to put it ahead of the players (like a frontpanel).
Because this entity already have a lot of "follows", instead of creating an anim follow new with different setlayer, I thought about placing the setlayer, in the spawn in level script.


So here my try:
Code:
spawn  codes
@script
void main() {
  void self = getlocalvar("self");

  changeentityproperty(self, "setlayer", 2);
  }
    performattack(getlocalvar("self"), openborconstant("ANI_freespecial2"));
}
@end_script
coords  370 271
flip    1
at  0

Unfortunately, it did not work ...
Am I doing something wrong, or is that the setlayer function can not be used in the spawn in level?
 
Last edited:
Solution
I'm sure it's doable in level spawnscript, try this:

Code:
spawn  codes
@script
void main() {
   void self = getlocalvar("self");

   changeentityproperty(self, "setlayer", 2);
   performattack(getlocalvar("self"), openborconstant("ANI_freespecial2"));
}
@end_script
coords  370 271
flip    1
at  0
I'm sure it's doable in level spawnscript, try this:

Code:
spawn  codes
@script
void main() {
   void self = getlocalvar("self");

   changeentityproperty(self, "setlayer", 2);
   performattack(getlocalvar("self"), openborconstant("ANI_freespecial2"));
}
@end_script
coords  370 271
flip    1
at  0
 
Solution
I recommend sortid as well , setlayer will look weird in some rare instances .IT takes care of displaying one entity on top or behind other ones.

Code:
spawn  pla2
@script void main() {
  changeentityproperty(getlocalvar("self"), "sortid", 1);
} @end_script
        map 0
	coords  100  360 20
	at  0
 
maxman said:
??? What does "sortid" do anyway?

It's used in conjunction with Z position to determine what draws over what. Here's a more detailed explanation I wrote elsewhere:

Drawing order is determined by a combination of sort ID and position on the Z axis. Lower numbered items draw first, meaning higher numbered items appear over top of them. For example, if entity1 and entity2 are on the same Z axis, a sortid of -1 on entity2 puts it one lower in drawing order compared to entity1. Entity2 therefore appears behind entity1. If Z position and sorting ID are both identical, drawing order is whichever entity updates first on each engine cycle, resulting in possible flicker back and forth.

This is why obstacles spawned right on top of each other will flicker sometimes. A quick sort id adjustment would fix it instantly.

It never happens with mobile entities because internally positions are very precise floating decimals. Once an entity moves it's virtually impossible for any position axis to be identical with another unless they're bound together. When binds are in play (native grab system and script bind), default sort Id adjustments prevent flicker (thats what puts the grabbed entity behind).

DC
 
Thanks to all for the help friends!
Finally, use the Bloodbane method, with a 999 setlayer, so that it always looks above everything. Since with the other method it was seen above the Background, but behind the player.
 
Back
Top Bottom