Multi-step player animation?

User avatar
BentPawGames
Posts: 210
Joined: Wed Jan 16, 2019 10:29 pm

Multi-step player animation?

Post by BentPawGames » Thu May 21, 2020 3:51 am

I wanted to have my player have a multi-step animation for movement. Basically, what I want is when you start moving in a direction, there is a transition animation that plays once, followed by their movement animation that loops until they stop or change direction. This is easy enough with action steps for enemies, but the player object doesn't use action steps in the same way. I tried playing around with the action steps and looking at the input code, but what seemed like potentially intuitive solutions didn't work.
User avatar
jorotroid
Posts: 260
Joined: Wed Aug 08, 2018 7:48 pm
Location: California
Contact:

Re: Multi-step player animation?

Post by jorotroid » Thu May 21, 2020 7:25 am

Probably a lot of ways you could go about this, but this is what first came to my mind. You could set up a new variable that gets set to some value on direction pressed. The transition animation would be set to play here, too. Then on direction held, you decrement that variable by one and do a check to see if the variable has reached zero. If it has, switch to the movement animation. I think a value of 255 would give you about a 4.25 second timer, so a pretty low value should work fine for what you are doing.
User avatar
BentPawGames
Posts: 210
Joined: Wed Jan 16, 2019 10:29 pm

Re: Multi-step player animation?

Post by BentPawGames » Thu May 21, 2020 7:47 pm

Thanks! I'll think more about that. So far all I've done is experiment with action steps, to no avail.
User avatar
BentPawGames
Posts: 210
Joined: Wed Jan 16, 2019 10:29 pm

Re: Multi-step player animation?

Post by BentPawGames » Sat May 23, 2020 6:41 am

Ugh, I've spent so much time tinkering with this :/ At least I feel like I have learned something about different commands and stuff, but still can get it to do what I want. I'm a bit lost as to how to set the value of the variable. Do I set it when I create it under "user variables", or set it in the asm? Does DEC or SBC continuously subtract until it gets to the number you specify with CMP, or does it just subtract 1?
User avatar
jorotroid
Posts: 260
Joined: Wed Aug 08, 2018 7:48 pm
Location: California
Contact:

Re: Multi-step player animation?

Post by jorotroid » Sat May 23, 2020 8:17 pm

BentPawGames wrote:
Sat May 23, 2020 6:41 am
Ugh, I've spent so much time tinkering with this :/ At least I feel like I have learned something about different commands and stuff, but still can get it to do what I want. I'm a bit lost as to how to set the value of the variable. Do I set it when I create it under "user variables", or set it in the asm? Does DEC or SBC continuously subtract until it gets to the number you specify with CMP, or does it just subtract 1?
Create it in the user variables. Unlike modern languages, you don't really ever "create" variables in code. For the most part you give names to variables through NESmaker. There are some
borderline esoteric differences between DEC and SBC, but the gist of it is that DEC is a somewhat convenient way of of subtracting by 1 and it doesn't affect the value in the accumulator. For that second tidbit, that means if you use DEC and then want to use a CMP opcode, you'll have to LDA your variable in between the DEC and CMP lines. That said, DEC does affect the processor flag that determines if a value has reached zero that the BEQ command uses. This means you don't even need to use a CMP opcode to check if your variable has reached zero if you use the DEC opcode.

Here is an example of how I might write the timer decremented:

Code: Select all

	DEC transitionTimer
	BNE +
	;; put code here to change animation
+
	;; continue with the help direction code
You'll probably also want to do a check before this to make sure you are not already in the final looping animation, so when you are, it won't keep running the timer.
User avatar
BentPawGames
Posts: 210
Joined: Wed Jan 16, 2019 10:29 pm

Re: Multi-step player animation?

Post by BentPawGames » Sun May 24, 2020 4:41 am

Much appreciated! looks like I wasn't too far off with what I was doing, albeit over-complicating things with unncessary LDAs and CMPs. Still figuring out ASM but even with just this exercise the logic is clicking a bit more where it didn't before.
User avatar
BentPawGames
Posts: 210
Joined: Wed Jan 16, 2019 10:29 pm

Re: Multi-step player animation?

Post by BentPawGames » Sun May 24, 2020 4:59 am

jorotroid wrote:
Thu May 21, 2020 7:25 am
You could set up a new variable that gets set to some value on direction pressed. The transition animation would be set to play here, too. Then on direction held, you decrement that variable by one and do a check to see if the variable has reached zero. If it has, switch to the movement animation. I think a value of 255 would give you about a 4.25 second timer, so a pretty low value should work fine for what you are doing.
Is this just a matter of literally loading that variable (whose value is established in User Variable tab of Nesmaker) in the direction pressed script? I wasn't sure if loading it would do anything if it then switches to the hold left script.
User avatar
jorotroid
Posts: 260
Joined: Wed Aug 08, 2018 7:48 pm
Location: California
Contact:

Re: Multi-step player animation?

Post by jorotroid » Sun May 24, 2020 5:45 am

Well, first a bit of background information. So the way variables work is that RAM has a bunch of slots called addresses that can hold a value. In a modern programming language, you can define a variable mid-program which will run some background process to find a free spot in RAM and use that address going forward for variable you are using. On the NES, there is no functionality to find a free spot of RAM, so you have to define all your variables outside of the program like in NESmaker. By "define" what I mean is that an address is given a name for it to be easier to know which address you are using to store a value. You could use and address without giving it a name, but that would make your code harder to read. You define your variable outside of the program, but you initialize it within the program. When you give it an initial value in NESmaker, at the beginning of the game's code there is a routine that runs through all the variables you have defined in NESmaker and sets them to their initial value. The addresses are always there where you uses them or not, and you can use any of them at any time.

What I think I am trying to get at is that you don't really need to worry about the initial value of your variable when you set up your variable in NESmaker. The only time that you want this timer code running is when you are holding down a direction. So any time a direction is not being held the value in that address doesn't matter. What matters is when you set the variable. In your on direction pressed code, you should store a value into that variable. Something like this:

Code: Select all

LDA #$40 	;; The amount of time you want your timer to last
STA transitionTimer
If you are doing a platformer, then you don't need to worry about what happens when the player switches going from left to right or right to left because when they switch you should have the same timer setting code in the on left pressed as you do in the on right pressed code. If you are doing a top down game were it could be possible to go in two directions at once like up and left, then this could get a little more complicated.

I hope this answered your question.

Also for convenience you could set up a constant in NESmaker for your timer length add use that in both your left and right pressed code so you can change the constant to tweak the timer length instead of having to change it in both the left and right pressed scripts every time you want to tweak it. It would look something like this:

Code: Select all

LDA #TRANSITION_TIMER_LENGTH
STA transitionTimer
User avatar
BentPawGames
Posts: 210
Joined: Wed Jan 16, 2019 10:29 pm

Re: Multi-step player animation?

Post by BentPawGames » Mon May 25, 2020 1:02 am

Great thanks! This is similar-ish to what I was attempting. I found an older thread where MistSonata explained timers, LDA the number, etc.

This should hopefully get me there. Thanks for explaining it and walking through it in detail.
User avatar
BentPawGames
Posts: 210
Joined: Wed Jan 16, 2019 10:29 pm

Re: Multi-step player animation?

Post by BentPawGames » Mon May 25, 2020 1:45 am

IT WORKS! :o :lol: Still a few quirks to sort out. Sometimes it skips this and seems to go straight to the idle animation while still moving left, but I think I can sort that out easily enough now. Thanks a ton! It's just a small little detail in the movement but I really wanted it for this game. :D

For the press left script I have:

Code: Select all

LDX player1_object
    GetCurrentActionType player1_object
CMP #$01
BEQ +

ChangeObjectState #$06,#$02

LDA #$10 	;; The amount of time you want your timer to last
STA TransitTimer
And then for the hold left script I have:

Code: Select all

LDX player1_object
    GetCurrentActionType player1_object
	CMP #$01
	BEQ ++
	;;;;;; Then, we will begin moving.
    StartMoving player1_object, MOVE_LEFT
++ ;; skipped the start movement.
;;;;;; Lastly, we will change the facing direction.
	;; comment out if you do not want this dpad push to change
	;; the facing direction.
    FaceDirection player1_object, FACE_LEFT
   
DEC TransitTimer
	BNE +
ChangeObjectState #$01, #$04 ;;
+
	
++	
	
Post Reply