advancing frames of a sprite foward and backward

Started by fire7side, Tue 10/06/2025 21:14:10

Previous topic - Next topic

fire7side

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.

Khris

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:
Code: ags
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.


SMF spam blocked by CleanTalk