The Importance of Layers in Running your App

pHghostpHghost London, UKMember Posts: 2,342

Possibly uncommonly, this is not a question, but a tip.

I just had an issue with my game, and could not solve what was going on. I have a rocket in the game, and some flames behind it. The ship and the flames are two separate actors. I am constraining the location and rotation of the ship to a global attribute and then loading those numbers into the fire actor so that both stay in sync. For the first several hours of development, it worked fabulously. And then suddenly, it stopped working. The flame was suddenly sliding behind instead of perfectly locking to the ship.

I was baffled. What had happened? Did I step over a line somewhere, making the rules too complicated for the game to be able to run everything smoothly? I tried turning off rules to try and get back to the perfect sync. It wasn't getting me anywhere, the problem persisted. But I KNEW it worked just an hour before.

After digging around a little, I remembered something I read on the forums at one point.

LOGIC -- all rules and so on, inside an actor, are run by the app from top to bottom.
ACTORS -- as they are listed in the scene layers tab, are resolved by the app from the bottom up.

I always knew this was important to understand in terms of constructing your internal logic, but it turns out the layers are crucial as well, and that was what tripped me up.

You see, I placed the flame actor under the ship actor in the layer list. And suddenly that meant that the flame was processed before the ship was. Which meant that the ship hadn't yet given its position for that frame -- and the position stored in the global attribute was the position of the ship from the PREVIOUS frame. That was why they were out of sync. Simply swapping them solved the issue.

Now everything works fine again. There is no 'lag,' and I know I can add more nested rules. ;)

I don't know if this is common knowledge, and something GS developers keep in their mind all the time. So, next time you have an issue with something which you know SHOULD work just by looking at the rules, but it doesn't -- it might be the layers tripping you up.

Sign In or Register to comment.