Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Constantly changing background sprite  (Read 3800 times)

0 Members and 1 Guest are viewing this topic.

Other_Rick

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 3
    • View Profile
Constantly changing background sprite
« on: June 26, 2014, 12:10:16 PM »

SOLVED


I'm a beginner at wintermute so excuse me if I miss something simple,
An issue I've been having is that the background image doesn't change when the variable "Panel.Intro" is changed.
Panel.Intro is changed from 1, to 2 but the background remains on the sprite designated for 1.
Code: [Select]
global Panel;

var background = Scene.GetNode("background");


if(Panel.Intro==1)
{
background.SetSprite("interface\Cutscenes\Scenes\1.sprite");
}
if(Panel.Intro==2)
{
background.SetSprite("interface\Cutscenes\Scenes\2.sprite");
}
if(Panel.Intro==3)
{
background.SetSprite("interface\Cutscenes\Scenes\3.sprite");
}
« Last Edit: June 28, 2014, 03:03:02 AM by Other_Rick »
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Constantly changing background sprite
« Reply #1 on: June 26, 2014, 05:00:27 PM »

The code seems fine so you will need to provide some more details on how you use it. Where is this placed? When does it run? How are you certain that Panel.Intro value changes and the background does not? Did you debug?
Logged

Other_Rick

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 3
    • View Profile
Re: Constantly changing background sprite
« Reply #2 on: June 27, 2014, 06:37:17 AM »


The script is attached to the background Entity

The background is initially a blank square, and upon the the start of the room it successfully changes to "1.Sprite" since Panel.Intro is 1.
Panel 1:

Panel 2:

A button is pressed to change Panel.Intro from 1 to 2, the debug shows that Panel.Intro does indeed change.


But still as shown in the gif, it doesn't switch panels.
Just in case, the code for the button which changes the Panel.Intro variable:
Code: [Select]
global Panel;

on "LeftClick"
{
Panel.Intro = Panel.Intro + 1;
global Cutscene;
Game.UnloadObject(Cutscene);
}
And entirety of code I posted before:
Code: [Select]
#include "scripts\base.inc"

/////Cutscenes/////////////////
global Panel;
global Cutscene;

var background = Scene.GetNode("background");
var animation = background.GetSpriteObject();


if(Panel.Intro==1)
{
background.SetSprite("interface\Cutscenes\Scenes\1.sprite");
}
if(Panel.Intro==2)
{
background.SetSprite("interface\Cutscenes\Scenes\2.sprite");
}
if(Panel.Intro==3)
{
background.SetSprite("interface\Cutscenes\Scenes\3.sprite");
}

if(Panel.Static==true)
{
animation.Pause();
}
if(Panel.Static==false)
{
animation.Play();
}

Cutscene.Center();
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Constantly changing background sprite
« Reply #3 on: June 27, 2014, 05:04:21 PM »

Most probably the code which changes the background sprite only runs once. Where did you place the last piece of code (the one you posted twice which modifies the sprite)? If it is in a script that runs only once (for instance scene_init.script) it will not work as you would like which I suspect is the cause of the issue you have. You have to make certain that whenever Panel.Intro value changes to re-run that piece of code.
Logged

Other_Rick

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 3
    • View Profile
Re: Constantly changing background sprite
« Reply #4 on: June 28, 2014, 03:02:42 AM »

Thank you!
I didn't know that the script was only being ran once, so I did some editing so the script looped.
Logged

anarchist

  • Regular poster
  • ***
  • Karma: 5
  • Offline Offline
  • Gender: Male
  • Posts: 212
    • View Profile
Re: Constantly changing background sprite
« Reply #5 on: June 28, 2014, 08:24:38 AM »

Glad that it is solved but can you tell us some more details on how you solved it? You said you have the code looping. Perhaps constantly looping is not ideal, especially if the loop will continue in other scenes (or will it stop when the scene ends?). Perhaps each time an interaction happens that changes the background you call a function with the background change code.
Logged
 

Page created in 0.038 seconds with 24 queries.