I Wanna Community

Fangames => Game Design => Programming Questions => Topic started by: PlasmaKaboom on December 14, 2016, 01:49:10 AM

Title: Is there a way to have a trigger change a room's background image?
Post by: PlasmaKaboom on December 14, 2016, 01:49:10 AM
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.
Title: Re: Is there a way to have a trigger change a room's background image?
Post by: SpaceH3R0 on December 14, 2016, 09:35:39 AM
There is a draw background event
Title: Re: Is there a way to have a trigger change a room's background image?
Post by: patrickgh3 on December 15, 2016, 11:40:24 AM
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: [Select]
background_index = bgIndex;
instance_destroy();
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: [Select]
if (global.trigger[trg]) {
    background_index = bgIndex;
    instance_destroy();
}
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.