Room resets the BG when leaving the room

Started by AndreasBlack, Sun 15/05/2022 09:41:36

Previous topic - Next topic

AndreasBlack

I have two bakground images one with Lights and one without, so to flip the light switch in the room, i obviously call "SetBakgroundframe(1)", etc.
Everything was working fine, until i realised that the light keeps resetting itself when leaving the room.
So obvious would be to put something in "leaves room" i suppose, tried that, no success. or "Room load".


I've tried various codes, but they all come down to the same outcome visually, which is that for a microsecond the lights are the "standard state when loading the room with SetBakground" and then changes back to the correct BG image (Lights on=true/false), which is obviously not what i want.

This was my last try in the globalscripts repeatedly_execute_always()



Code: ags

if (player.Room==1 && Lights_On==false)
 {
   SetBackgroundFrame(0);
 }


else if (player.Room==1 && Lights_On==true)
 {
   SetBackgroundFrame(1);
 }






Matti

The manual says "The frame lock is released when the game changes rooms." so this is normal behavior.

Putting SetBackgroundFrame(); in room_load should work though, because it sets the background before the screen fades in. You should try that (again) and post your code in case it really doesn't work.

AndreasBlack

Jesus, that was the first thing i've tried and i think the screen flickered between the two frames?! I must have done something to mess up the code that i did not notice last night (laugh) Thanks anyways! Nothing wrong with the code itself that's posted, just where it's placed in the room. Beginners take notice :)

Khris

This should be enough:
Code: ags
function room_Load() {
   SetBackgroundFrame(Lights_On); // bool becomes 0 or 1
}

AndreasBlack


SMF spam blocked by CleanTalk