Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [GM6] Looping segments of a sprite's subimages  (Read 951 times)

0 Members and 1 Guest are viewing this topic.
[GM6] Looping segments of a sprite's subimages
« on: November 27, 2006, 02:45:07 am »
  • Official Forum Hippie/Writer
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 200
The way I have my movement engine set up is that rather than having 4 separate sprites for my different directions, I have 1 sprite that holds the animations (in my debugging example, I have 3 subimages per animation, resulting in 12 total subimages [0-11]) and through code, I check the frames of the animation against a facing variable (that can be 0, 1, 2, or 3) multiplied by the number of subimages in the animation (in This case 3).  here is the code to give you a better idea:
Code: [Select]
sprite_index=spr_run;
if (image_index < (2 + facing * 3) && image_index >= facing * 3)
{
      image_index+=1;
}
else
{
      image_index=facing*3;
}
I was just wondering if this, combined with externally loading the sprite would be more efficient that having 4 separate sprites do the job.
« Last Edit: March 01, 2007, 01:20:18 am by 4Sword »
Logged

Goodnight

Once and future Captain
Re: [GM6] Looping segments of a sprite's subimag...
« Reply #1 on: November 27, 2006, 03:21:40 am »
  • With a Capital G
  • *
  • Reputation: +1/-0
  • Offline Offline
  • Gender: Male
  • Posts: 706
If I understand this right, then you can shorten that code. Just let the animation run as normal and put this in the Step event. Don't feel 'outdone', because I wouldn't have thought of doing it the way you have. :P

Code: [Select]
image_index = (image_index mod 3) + 3*facing
As for being more efficient, I think it depends on what the sprites look like. With four sprites, you can crop each one to its minimum size, but if the four are different dimensions then you could end up with excess space in some or all frames when they're combined. That's only something to worry about if you're a perfectionist or the sprites are very big.
Logged
Re: [GM6] Looping segments of a sprite's subimag...
« Reply #2 on: November 28, 2006, 02:08:04 am »
  • Official Forum Hippie/Writer
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 200
Ha, wow, that does work better.  I wonder why I didn't think of using mod?  Oh well, it's been a while since I used it last I guess.  Thanks Goodnight
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.185 seconds with 43 queries.

anything