Changing object views,

Started by Furwerkstudio, Thu 20/10/2022 00:27:58

Previous topic - Next topic

Furwerkstudio

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?

Khris

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:

Code: ags
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;
}

SMF spam blocked by CleanTalk