Fangames > Programming Questions

Is there a way to have a trigger change a room's background image?

(1/1)

PlasmaKaboom:
Hello. I am new to GameMaker Studio and have little to no experience with coding. Is there a relatively easy way to change a background image ingame with a trigger?

I have been working on my first fangame for over a month now (following Klazen's tutorial). So I at least know where most things are in GameMaker, but In terms of triggers, I have no clue how to set a trigger to effect anything other than objects. I want a trigger to change the room's background image when touched by the player. I do not seem to see a way to do this. I figure it has something to do with the "draw background" instance but I'm not sure where to apply that instance. Under which event?

If anybody can help me with this it would be greatly appreciated.

SpaceH3R0:
There is a draw background event

patrickgh3:
Hi Plasma. There are multiple ways to do this.

Strategy 1: Create a new trigger object objTriggerChangeBg, this will be competely seperate from all the other trigger systems in the game. Set the sprite to sprTriggerMask, set visible to unchecked, and click Add Event -> Collision -> objPlayer. Drag "execute a piece of code" into the actions list. The code will be

--- Code: ---background_index = bgIndex;
instance_destroy();
--- End code ---
Place the object in the room, right click -> Creation code and assign bgIndex. (bgIndex = bgReallyCoolBackground;)

Strategy 2: Use the existing trigger system. Create an object objEffectChangeBg, with no sprite. Click Add Event -> Step, drag "execute a piece of code" into the actions list. The code will be

--- Code: ---if (global.trigger[trg]) {
    background_index = bgIndex;
    instance_destroy();
}
--- End code ---
Place the object in the room, right click -> Creation code and assign trg and bgIndex. (trg = 5; bgIndex = bgReallyCoolBackground;) Also add an objFreeTrigger in your room and assign trg to be matching.

Navigation

[0] Message Index

Go to full version