Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fire7side on Tue 10/06/2025 21:14:10

Title: advancing frames of a sprite foward and backward
Post by: fire7side on Tue 10/06/2025 21:14:10
I can program but I'm a beginner in AGS.  I would like to set up part of a puzzle where a padlock sprite can be rotated left or right maybe even one frame at a time.  The frame rotations would be done in an art program, so the sprite would have 39 frames.  I know AGS can rotate also, but it sounds kind of complicated.  Anyway, any thoughts on the simplest way to do it would be appreciated or just pointing me in the right direction.
Title: Re: advancing frames of a sprite foward and backward
Post by: Khris on Wed 11/06/2025 11:37:20
If you import the sprites in numerical order and use an object for the padlock dial, you can change the .Graphic property using a simple calculation.

39 frames means if you start the import at sprite slot 12, the last sprite is in slot 50. So the code could look like this:
function RotateLockBy(int by) {
  int first = 12, last = 50; // sprite slots
  int slot = oPadlock.Graphic + by;
  if (slot < first) slot = last;
  else if (slot > last) slot = first;
  oPadlock.Graphic = slot;
}

Put this above your arrow hotspot click handlers and simply call RotateLockBy(-1); and RotateLockBy(1); respectively.
Title: Re: advancing frames of a sprite foward and backward
Post by: fire7side on Wed 11/06/2025 17:31:18
I'll check that out. Thanks.