don't click here

Animation format

Discussion in 'Engineering & Reverse Engineering' started by 1337rooster, Apr 29, 2008.

Thread Status:
Not open for further replies.
  1. 1337rooster

    1337rooster

    Member
    41
    0
    6
    Okay, so I've been trying to understand the animation sequences, and I can't seem to find any information on it.

    There was a bit of explanation in the spindash how to:

    Code (Text):
    1. SonAni_Spindash:    dc.b 0, $58, $59, $58, $5A, $58, $5B, $58, $5C, $58, $5D, $FF
    So from what I can tell, first byte is the speed and lower means faster animation. The ones following it are sprite frame numbers. Now, the last byte is confusing me. I imagine the last one is supposed to have some indication that this is the end of the animation or something. The value $FF was explained in the spin dash guide as telling the animation to repeat. I played with the value a bit, when I used $D0 it seemed like the animation would execute once and end. When I gave it the value $0, it started displaying random sprites at the end. So, what exactly are we supposed to feed the last byte? I want to execute the animation about 2 or 3 times and stop it.

    Now some of the animations are confusing me for example:
    Code (Text):
    1. SonAni_Spring:  dc.b $2F, $40, $FD, 0
    I would have thought this to have only 3 values, the first speed byte, the one frame it uses, and then the closing byte. Could someone explain how this one works too? what's with the $FD and 0?

    Thanks
     
  2. Rika Chou

    Rika Chou

    Tech Member
    5,276
    169
    43
    I think the FD closing value returns to a different animation, determined by the byte after it. In this case it's 0, and that's the walking animation.

    Anyway, here's a post I made at SGMC:

    To get it to animate two or three times, you have to add that to the animation script. Actuallly script that animation to repeat however many times you want, then close it.
     
  3. Hivebrain

    Hivebrain

    Administrator
    3,049
    163
    43
    53.4N, 1.5W
    Github
    From the future S1 disassembly:

    Code (ASM):
    1.  
    2. afEnd:      = $FF   ; return to beginning of animation
    3. afBack:     = $FE   ; go back (specified number) bytes
    4. afChange:   = $FD   ; run specified animation
    5. afRoutine:  = $FC   ; increment routine counter
    6. afReset:    = $FB   ; reset animation and 2nd object routine counter
    7. af2ndRoutine:   = $FA   ; increment 2nd routine counter
    8.  
    af stands for "animation flag". afReset is stupid and probably only used for one object.
     
  4. drx

    drx

    mfw Researcher
    2,254
    350
    63
    :rolleyes:
    You have to remember that sometimes a 0 is appended to the end of multi-byte data to align the ROM to a word.
     
  5. 1337rooster

    1337rooster

    Member
    41
    0
    6
    Thanks a lot guys, this really helped me. Theres a lot of stuff like this I just can't figure out on my own and that byte was just driving me crazy
     
  6. 1337rooster

    1337rooster

    Member
    41
    0
    6
    I don't want to make too many topics and this is sort of related, so maybe someone can help me with this.

    I was wondering what you can tell me about how sonic gets mirrored horizontally (when changing direction). I tried to add the spring animation from sonic CD to sonic 1. It seems to work fine and the animation looks nice but theres a wierd issue when you try to change sonics direction in the air. When sonic goes from looking left to looking right, sonic isn't getting mirrored from his center, sonic seems to be getting mirrored through a vertical axis just a bit off from his center. As a result sonic appears to jump a tiny gap and sort of shifts his position. If you imagine Sonic's nose as a point of reference (since it should be the center of this animation), basically his nose moves a few pixels to the right when you look change from facing right to left, and vice versa for left to right.

    So what I tried was setting sonics width to the new number of pixels (because the previous sprite has a width of 3 tiles, this one has 4). However, that didn't seem to change anything. So any ideas on why this might happen? Is there a way to define the axis where sonic should be mirrored? Some piece of code you could direct me to study?

    Oh and as a side question, when you change sonics animation, should you also change his width, height, collision width, collision height, etc? I was wondering how much of that I should be aware of and do manually, and how much of that is done automatically by existing code triggered from changing the animation.

    Thanks in advance
     
  7. Rika Chou

    Rika Chou

    Tech Member
    5,276
    169
    43
    It sounds like your spring animation isn't completely on center, so when he is mirrored he will appear to move a little. Edit the mappings, just move Sonic however many pixels over into the center until it works right. I really wish that SonMapEd had a grid like Lost Library.

    Unless the new animation is completely different sized than the original, then you shouldn't have to worry about it. I don't think any of that is changed when Sonic jumps on a spring anyways.
     
  8. Hayate

    Hayate

    Tech Member
    Press Ctrl+I in SonMapEd to see info about the sprite, including where the bounding box is. :P

    Also, may as well point out that the game doesn't care what the last value on a line of the source code is. Thus, if you put $FF in the middle of an animation list, everything between it and the next label will be completely ignored.
     
  9. 1337rooster

    1337rooster

    Member
    41
    0
    6
    Thanks, I was able to fix it by just moving the sprites to the right a bit in SonMapED. I think that SonMapED is hiding some of the underlying details of how sonic sprites are displayed on screen from me. Think I'm going to try adding some sprite mappings outside of SonMapED, hopefully that will be a bit more educational.
     
  10. 1337rooster

    1337rooster

    Member
    41
    0
    6
    So I've been adding quite a few sprites to sonic 1 (for sonic).

    I added a bunch to get the spring animation (where sonic does a flip) from sonic 2/3


    I noticed that when it gets to the $80 frame in the animation, the animation will freeze displaying the $7F sprite until the animation is changed.

    I changed $80 to a different sprite and the animation worked. This makes me think that you can only have up to $80 sprites in total? Thus any sprite from $80 onward simply can't be used? Is this correct? Is there a work around for this?
     
  11. Yeah, stock Sonic 1 can't have a frame number greater than $7F. The workaround is pretty simple though, it's here (in Jman's posts)
     
  12. 1337rooster

    1337rooster

    Member
    41
    0
    6
    Okay I used the two fixes, I changed

    Code (Text):
    1. SAnim_Do2:      ;modified to allow for more frames, paast $80
    2.         moveq   #0,d1
    3.         move.b  $1B(a0),d1; load current frame number
    4.         move.b  1(a1,d1.w),d0; read sprite number from script
    5.         cmpi.b  #$F0,d0
    6.         bcc.s   SAnim_End_FF; if animation is complete, branch
    This is the new code I have, and I changed the add.b d0,d0 to add.w d0, d0

    Now, the sprite appears but it comes with a bunch of garbage tiles too.
    [​IMG]

    I checked my sprite mapping and there were only 2 tiles for sonic (the ones I expected) in this frame(so it doesn't make sense to see these extra tiles all over the place). As far as I could tell I'm only getting this garbage in sprites $80 and beyond.
     
  13. Puto

    Puto

    Shin'ichi Kudō, detective. Tech Member
    2,013
    0
    16
    Portugal, Oeiras
    Part of Team Megamix, but haven't done any actual work in ages.
    You can fix that by adding one more line in loc_D700. After the <tt>subq.b #1,d1</tt>, add a line containing <tt>ext.w d1</tt>, and the problem SHOULD be fixed.
     
  14. 1337rooster

    1337rooster

    Member
    41
    0
    6
    Works perfectly, thanks for the help guys. Although, I wish I understood what was going on a bit more.

    I understand what's going on here:
    Code (Text):
    1.         move.b  1(a1,d1.w),d0; read sprite number from script
    2.         cmpi.b  #$F0,d0
    3.         bcc.s   SAnim_End_FF; if animation is complete, branch
    but I don't fully understand what the add.w d0,d0 and ext.w d1 changed did.
     
Thread Status:
Not open for further replies.