Forum rules - please read before posting.

Change background image?

Hi, I'm making a 2D game and I'm trying to change the scene background picture after I click on a hotspot. How would I be able to do that?

Comments

  • Welcome to the community, @thehazard.

    Create a second background and use the Object: Set visibility Action to make your two backgrounds visible/invisible as required.  Attach a Remember Visibility component to both so that changes will be saved.

  • I‘m achieving this by switching scenes. Would your recommendation be the more efficient way, Chris?
  • If all you're doing is changing the background, then switching scenes is a bit overkill.

    You can swap out the visibility of two objects as above, but if it occupies the same space (as is the case of background sprites), then the most efficient way is to use a single background sprite and swap the sprite using animation.  You can change a Sprite Renderer's Sprite field using an Animator Controller (see Unity's docs for more on this), and then manipulate it at runtime via AC's Object: Animate Action.
  • Thanks again, Chris. I will go for that then and suppose this will also reduce the file size of a built. By using my method my built resulted in 600 MB for about 8 scenes all in all. Yes, that sounds like an overkill. :)
  • Before I try to get my head around Animator Controllers, I would like to ensure that I got all this here right. (As english isn‘t my first language and we‘re talking techtalk here plus me being new to Unity, AC and programming in general, I hope you understand).

    The game I am developing is technically probably as basic as it can get:

    All you can see is static pictures of a room with things in it. (a bed, a hifi, a table, etc.).Within these pictures I create hotspots that changes the point of view in the room. For example:

    You see a closet (closed). I create a hotspot on it. When the player clicks on it, the closet opens up. So far I do this by creating a new scene with the picture of the opened closet. The interaction is then accomplished by „scene > switch“.

    So IF I got you right, Chris, then the way you described it is way more elegant and would also reduce the size of the actual game in Megabytes? The latter I ask because I was surprised that after running and exporting my dummy-game, I was ending up with 600 MB.
  • So basically the function I am looking for is to simply switch the background picture when clicking on the hotspot.
  • But then again i now just repeated the original posters question. Haha, silly me. Sorry for that.
  • Trying to get my head around the action type "Object" -> "Animate". So I can make use of this when I want to switch between to background images, right? In my case this would be:

    Picture 1: Closed closet being a hotspot.
    Then I want the player to click this hotspot. After he or she did that, the player logically opened the closet and I want him to see the picture with the open closet.  

    I created an Animator Controller now. From here on I´m ... tadaa ... stuck for now. :)

    This is how it looks like. See the two pictures I want to use for this action at the bottom.




  • I can only see the one linked picture, but the Animator has no animations inside it.  You'll need animation clips in there in order to have something to change.  As for the Action, you'll need to set the Animation engine field to Mecanim (this was Unity's term for the new Animator system when it was introduced).

    The Object: Animate Action can either play animation clips by name, or adjust parameters set up in your Animator Controller.  This is a Unity topic, but you can find more on this here.

    However, you hadn't said before about the background being linked to a Hotspot, and presumably you'd want a different Hotspot to be interactive when the cupboard is opened.  In this case, I'd say forget about swapping the background through animation, and just have them as two backgrounds side-by-side.

    You can then assign a separate camera for each background (i.e. each background has a camera that looks at it), and then have the Hotspot Interaction use the Camera: Switch Action to just change the active camera.  This would mean you could then also make a separate Hotspot for each background - so basically what you were doing before, but with each background side-by-side as opposed to separate scenes.

    This won't affect the file size much, though.  Scene files themselves take up very little space, and it's more down to the size of your assets.  Compression, atlasing etc, are all factors that affect your game's size, and this again is an aspect of using Unity rather than AC - and you can find many good resources about this on Unity's documentation pages.
  • edited February 2018

    Thanks again, Chris! Your help is well appreciated. I now at least understand the concept behind switching cameras and it makes perfectly sense to me and to what I want to achieve. 

    The thing is that I am confused about the camera-thingie: I now have a second camera and placed it above the opened closet – and then I create the Interaction Camera: Switch (pointing to the second camera) that is connected to the hotspot on the closed closet. Though, nothing happens.

    I´m trying to get my head around the basics when it comes to cameras. (Being a music composer for films and stuff it´s a new world to me, haha)




  • The active camera that the MainCamera is "sticking to" is listed at the bottom of the MainCamera component at runtime.  Does it show the correct camera name after the switch?

    Any screenshots you can post of the scene setup will help to understand the problem.
  • Chris, I made it and can finally move on. What a good feeling, and I really dig this kind of workflow. Thanks again for all the superb support, and I bet we‘ll see us again once 1000 new questions plop up. Just kidding ... ermmm ... probably not kidding. ;)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.