Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Furwerkstudio on Thu 20/10/2022 00:27:58

Title: Changing object views,
Post by: Furwerkstudio on Thu 20/10/2022 00:27:58
I am trying to figure out how to have an object to change with each click, like a monitor that displays painting but one is a code slipped in there or rotating a stone pillar.

I understand that there is a "if else" statement used but I can't figure if it is view based and I have to stop on each frame or is there an easier trick to it?
Title: Re: Changing object views,
Post by: Khris on Thu 20/10/2022 07:57:20
Do you mean the object is animated and clicking it changes the animation?
Or is it static and a click is supposed to change the sprite?
The stone pillar thing sounds like an animation is used to transition between two static images.

In general you'll want to create a list of states and a variable to keep track of the current state.
The simplest thing is switching between sprites; if they have consecutive slot numbers, it's as simple as:

function oMonitor_Interact() {
  // sprites 123, 124 and 125
  int index = oMonitor.Graphic - 123;
  index = (index + 1) % 3; // move to next index
  oMonitor.Graphic = 123 + index;

  // or in one line:
  // oMonitor.Graphic = (oMonitor.Graphic - 122) % 3 + 123;
}