Daniel Manoiu Posted February 12, 2020 Share Posted February 12, 2020 Hello everyone, I'm new here and very new to Atari programming. I'm having some issues trying to figure out how to have my player character alternate between two frames of animation when moving. So far, this is the code that I came up with: AreWeChanging: lda P0FrameCounter cmp #10 bne ChangeSpriteBack ChangeSprite: lda #0 sta P0FrameCounter lda #<P0Sprite2 sta P0SpritePtr ; lo byte pointer for P0 Sprite lda #>P0Sprite2 sta P0SpritePtr+1 ; hi byte ptr for P0 Sprite jmp End ChangeSpriteBack: lda #<P0Sprite1 sta P0SpritePtr ; lo byte pointer for P0 Sprite lda #>P0Sprite1 sta P0SpritePtr+1 ; hi byte ptr for P0 Sprite End: jmp StartFrame Basically, it's just switching to the second sprite of the animation when the P0FrameCounter variable reaches 10 and then switches back. I am incrementing the variable when moving the joystick in any direction. This is not great for 2 reasons: it only changes to the seconnd sprite for one frame of animation then changes to the first one for 10 frames; and, seems to be a bit buggy if I'm testing it in the emulator and pressing two directional buttons, or moving diagonally. What approach should I use to alternate between the two sprites for an equal amount of time (let's say 10 frames per sprite), only when the directional buttons are pressed? Thanks in advance for your help! Quote Link to comment Share on other sites More sharing options...
DaveM Posted February 12, 2020 Share Posted February 12, 2020 (edited) Hi Daniel, I'm relatively new to Atari Programming too. I started working on my first game, Mr. Yo-Yo back in September, and it's still a work in progress. You can find a thread for it on this forum. Anyway, I had a similar issue, and I think this will solve it. Instead of doing a cmp, use an and. I'd also use 8 frames instead of 10, so you're only dealing with 1 bit. So your first part of code, the AreWeChanging section, would look like this: AreWeChanging: lda P0FrameCounter and #8 bne ChangeSpriteBack This isolates the #8 bit, so when it's set to 1, it branches. When it's a 0, it doesn't take the branch. Oh, and I should add that by doing it this way, there's no need to reset the P0FrameCounter to 0 in ChangeSprite. It can continue to count up, and since you're only checking one bit, you don't need a reset. Hope that helps! Dave Edited February 12, 2020 by DaveM 1 1 Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted February 12, 2020 Share Posted February 12, 2020 2 hours ago, Daniel Manoiu said: I'm having some issues trying to figure out how to have my player character alternate between two frames of animation when moving. My tutorial covers animating the players in step 14. I use a 4 frame animation, if you want just 2 frames then change the and #3 to and #1. Quote Link to comment Share on other sites More sharing options...
+Andrew Davie Posted February 13, 2020 Share Posted February 13, 2020 You could use your frame number as an index into a lo/hi table pair to give you a pointer to each frame. So, place the sprite data adress lo bytes into one table, hi bytes into another, load an index register (say, X) with the frame # Then, load LO,x --> P0SpritePtr and load HI,x --> P0SpritePtr+1 and bob's your uncle. Then you don't need lots of conditional code. Quote Link to comment Share on other sites More sharing options...
bogax Posted February 13, 2020 Share Posted February 13, 2020 (edited) perhaps you could keep the sprites in the same page and just flip the lo byte of the pointer something like AreWeChanging: lda P0FrameCounter cmp #10 bne SkipFlip FlipSpritePointer: lda #0 sta P0FrameCounter lda P0SpritePtr; lo byte pointer for P0 Sprite eor #<P0Sprite1 ^ <P0Sprite2 sta P0SpritePtr SkipFlip: or if a power of 2 will do for the count let the counter run and AND with a 2**n - 1 and bne Edited February 13, 2020 by bogax Quote Link to comment Share on other sites More sharing options...
Daniel Manoiu Posted February 13, 2020 Author Share Posted February 13, 2020 12 hours ago, DaveM said: Hi Daniel, I'm relatively new to Atari Programming too. I started working on my first game, Mr. Yo-Yo back in September, and it's still a work in progress. You can find a thread for it on this forum. Anyway, I had a similar issue, and I think this will solve it. Instead of doing a cmp, use an and. I'd also use 8 frames instead of 10, so you're only dealing with 1 bit. So your first part of code, the AreWeChanging section, would look like this: AreWeChanging: lda P0FrameCounter and #8 bne ChangeSpriteBack This isolates the #8 bit, so when it's set to 1, it branches. When it's a 0, it doesn't take the branch. Oh, and I should add that by doing it this way, there's no need to reset the P0FrameCounter to 0 in ChangeSprite. It can continue to count up, and since you're only checking one bit, you don't need a reset. Hope that helps! Dave @DaveM Thank you! The and #8 worked great for the simple animation I was going for. It did shift some things around with the change of sprite when player collides with enemy, but I think I can figure that out. @SpiceWare thank you, what a great resource! I got into Atari programming from the Udemy course, but I plan to follow all the steps in your tutorial to learn more. @Andrew Davie that seems like a way more efficient and less verbose way of doing this. I’ll give it a try. @bogax yes, the AND/ bne seems to work great, I didn’t really commit to the 10 frame switch, it was pretty arbitrary based on what I thought would look decent. But will definitely try the lo byte trick. I have an enemy sprite (P1) that I’d like to flip between two frames of animation at controlled random speeds, that will be a new challenge! 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.