Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411616 Posts in 69390 Topics- by 58447 Members - Latest Member: sinsofsven

May 10, 2024, 07:09:43 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsGame Maker - Using only a subset of sprites from a sheet for animation?
Pages: [1]
Print
Author Topic: Game Maker - Using only a subset of sprites from a sheet for animation?  (Read 4783 times)
Destral
Level 10
*****


Climbing that mountain...


View Profile WWW
« on: September 11, 2010, 12:16:54 PM »

Hi folks, it's me again with more noob questions about Game Maker.

Up until now I've been using 4 different animated sprites of 4 frames each for the protagonist to have a walking cycle in each of the four directions, but I'm trying to cut down on the numbers of sprites, and I got to thinking that maybe I could combine all 16 sprites into one sheet and then use GML somehow to cycle through each 4-frame walk cycle within the sprite sheet for each of the four directions. Is this actually possible? And if so, could I possibly get some pointers on how to go about it?

Thanks! Gentleman

EDIT: Oh! So sorry, I was convinced I was in the Technical forum, not tutorials. Could I possibly get this moved there, mods? Thanks, and sorry!  Beg
Logged

Currently working on: Sword Surfer
Shiny
Level 0
***


View Profile
« Reply #1 on: September 11, 2010, 02:24:04 PM »

Under those conditions, you could use modulo to wrap the image_index and then offset to whichever sub-animation you wish to play. Not the most flexible solution (all must be the same length), but it lets you roughly adhere to Game Maker's own system, and without much extra work.

Code: (Create event)
// Direction constants.
// Animations should be ordered in sequence according to these.
DIR_UP    = 0;
DIR_DOWN  = 1;
DIR_LEFT  = 2;
DIR_RIGHT = 3;
// Direction that the object is currently facing.
facing = DIR_UP;

Code: (Draw event)
// "4" in this case is the number of frames per sub-animation.
draw_sprite(sprite_index, floor(image_index mod 4) + (facing * 4), x, y);

Keep in mind that, when using this method, image_index cannot be relied on for frame-specific logic unless you perform the modulo again.
Logged
Destral
Level 10
*****


Climbing that mountain...


View Profile WWW
« Reply #2 on: September 11, 2010, 05:42:52 PM »

That worked beautifully for my purposes, thankyou very much!  Gentleman
Logged

Currently working on: Sword Surfer
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic