Author Topic: Is there a way to have a trigger change a room's background image?  (Read 1313 times)

PlasmaKaboom

  • Wannabe
  • Posts: 15
  • OS:
  • Windows 8.1/Server 2012 Windows 8.1/Server 2012
  • Browser:
  • Chrome 54.0.2840.99 Chrome 54.0.2840.99
    • View Profile
  • Playstyle: Keyboard
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

  • Guest
Re: Is there a way to have a trigger change a room's background image?
« Reply #1 on: December 14, 2016, 09:35:39 AM »
There is a draw background event

patrickgh3

  • Spike Dodger
  • Posts: 169
  • stay optimistic! :D
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 55.0.2883.87 Chrome 55.0.2883.87
    • View Profile
    • Github
  • Playstyle: Keyboard
Re: Is there a way to have a trigger change a room's background image?
« Reply #2 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.