Sega Saturn Development > Share your code

Set the frame of a sprite animation!

(1/1)

Mr. Potatobadger:
Hey all!

I noticed that Jo Engine's sprite animator does not seem to have a function to set the frame of a sprite to whatever frame you like. I went ahead and added that feature, and figured I should share it, as it's fairly commonly needed, and very simple.

I will attach my sprite_animatior.h file for if you want to simply replace the file, but in case you've made additions like I have, here's a simple way to add it:

in "jo_engine_src\jo_engine\jo", you will see "sprite_animator.h". Open this up. I chose to put it under "jo_set_sprite_anim_frame_rate", as it seemed like the best spot.

Here is the code:


--- Code: ---
/** @brief Set animation frame
 *  @param anim_id Id returned by jo_create_sprite_anim()
 *  @param frame Frame of animation to be displayed, where 0 is the first frame.
 */
static __jo_force_inline int jo_set_sprite_anim_frame(int anim_id, unsigned char frame) { return __jo_sprite_anim_tab[anim_id].cur_frame = frame; }
--- End code ---

I made sure to keep it consistent with the usual Jo formatting standards   ;D
This seems to be the simplest way to do it. If someone has a better way to do it, please let me know.

Hoping to see this addition in the next official release of Jo!

EDIT:
Here's an example of it in action:
https://i.gyazo.com/7b2a8c29fef8bb04703a09ad9b561edc.mp4

I've set sonic's jumping animation to frame 5 for the sake of example. The code looks like this:

--- Code: ---
jo_set_sprite_anim_frame(sonic.anim_jump_id, 5);

--- End code ---

mindslight:
Hi Mr. Potatobadger :)

I integrate your function on the next release.

I just added some const and removed the return value.

New prototypes:


--- Code: ---
/** @brief Set animation frame
 *  @param anim_id Id returned by jo_create_sprite_anim()
 *  @param frame Frame of animation to be displayed, where 0 is the first frame.
 */
static __jo_force_inline void jo_set_sprite_anim_frame(const int anim_id, const unsigned char frame) { __jo_sprite_anim_tab[anim_id].cur_frame = frame; }

--- End code ---

Mr. Potatobadger:
Awesome!
 ;D

Navigation

[0] Message Index

Sitemap 1 2 3 4 5 6 7 8 9 10 
Go to full version