LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

8-Directional Animated Sprite With D-Pad & Circle Pad

Root / FAQs / [.]

UltMarioCreated:
I'm using SPANIM loops for the animation and can handle the coding with BUTTON() functions but, I'm not sure how to handle the process with the circle pad since; it doesn't have a circle pad release/press function. This is my current code that works for the most part with the dpad (Each direction uses the same code as this). B=BUTTON():B2=BUTTON(2):B3=BUTTON(3) IF B==1 AND URUN==0 THEN SPANIM 0,2,ARRAY,0:URUN=1 IF B3==1 THEN URUN=0 My current animation for the dpad mostly works except... it won't change to diagonal sprites if dpad up/left/right/down is pressed then, changed to a diagonal press without release. Any ideas how I should approach this? I've tried many other ideas on my own but, I'm not having any luck.

First off, is that in a loop? Second, why do you have 3 BUTTON() statements? One BUTTON() will detect ALL button presses at the time it is called, like if I press up, and use BUTTON(), it detects up. Having three BUTTON()seems unnecessary. As for the circle pad... To use the circle, you can use
STICK OUT <x-var>,<y-var>
The amount of offset from neutral position (no movement) is the stored to whatever X and Y variables you give it. Like if I press up with the circle pad, it would make TY go up depending on how much I press up - if it's halfway up, then TY would be half (0.5). If I press it 2/3 of the way up, it would be about 0.66666 My explanations suck In summary use STICK OUT to get circle pad input.

First off, is that in a loop? Second, why do you have 3 BUTTON() statements? One BUTTON() will detect ALL button presses at the time it is called, like if I press up, and use BUTTON(), it detects up. Having three BUTTON()seems unnecessary. As for the circle pad... To use the circle, you can use
STICK OUT <x-var>,<y-var>
The amount of offset from neutral position (no movement) is the stored to whatever X and Y variables you give it. Like if I press up with the circle pad, it would make TY go up depending on how much I press up - if it's halfway up, then TY would be half (0.5). If I press it 2/3 of the way up, it would be about 0.66666 My explanations suck In summary use STICK OUT to get circle pad input.
Yes, the code is in a loop. I also have my sprite moving with the dpad & circlepad already but, animating the sprite is another story. I didn't include all of my coding to keep it short and to make sure the other coding wouldn't distract from the main focus. I can get the sprite to animate smoothly with the dpad but, I can't get the same results with the circle pad. The 3 BUTTON() statements are for storing the different BUTTON () Feature ID's into separate variables simply to use the 2nd & 3rd features which, change the button's values when pressed/released. I understand it detects the same button presses but, the timings are different for when each value is changed. Example; my code of IF B3==1 THEN URUN=0 allows me to trigger the instant you let go of the dpad after pressing up. I understand how to receive circle pad inputs with STICK OUT but, I'm struggling to smoothly animate my sprite since, there is no implemented STICK OUT functions to detect when the stick is changed/released in a similar fashion as BUTTON(3) & BUTTON(2). Thanks for taking the time to respond to my thread so quickly by the way! Sorry if I'm not being clear enough with my problem.

If I understand your situation correctly, this is how I would go about it. Every iteration of the loop, do STICK OUT SX#,SY#. From the values SX# and SY#, calculate the direction: maybe 0 for North-West, 1 for North, 2 for North-East, etc.. Calculate this value in a variable NEWDIRECTION%. Compare NEWDIRECTION% with another variable OLDDIRECTION% (initialized to the 'not moving' value at the beginning of the game, probably). If the two are equal, do nothing. If the two are not equal, update OLDDIRECTION%=NEWDIRECTION%, change the animation, and do anything else that happens when you start/stop/change direction. (If I misunderstood your intent, then this may well be useless to you.)

You can obtain the angle (in radians, mind you) the circle pad is pushed in from -180 degrees to 180 degrees with ATAN(STICK_Y#,STICK_X#). This might make checking which direction you're pushing in easier.

Not sure I understand completely either, but with your concern to not detecting a diagonal after up/left/right/down. I was thinking this is a tough situation in logic. I'm not great at figuring these things without testing, but I'm thinking some sort of logical operation could solve it. Something like an AND condition to check if one of the first directions is being held AND a diagonal is pressed. Then you can satisfy the third condition?

Thanks for the help everyone! I ended up using the platform game's sample code to synchronize the circle/d pad's input with the variable B which, made detecting the circle pad's direction simple enough.
SLV=.2
IF (SY>SLV) THEN B=B OR 1
IF (SY<-SLV) THEN B=B OR 2
IF (SX<-SLV) THEN B=B OR 4
IF (SX>SLV) THEN B=B OR 8
I used SquareFinger's method to imitate a button release logic so, I was able to remove
IF B3==1 THEN URUN=0
with
IF B==1 AND OLDDIRECTION!=NEWDIRECTION THEN OLDDIRECTION=NEWDIRECTION:URUN=0
. slackerSnail Although I didn't use your method, it's good to know of a way to receive angled values from the circle pad; thanks for the information! Krondelo I found a way around it. I was activating animations with BUTTON presses which, probably wouldn't count as one after pressing up/left/right/down when a player hasn't released it yet. My new method is checking if the button is held down and animation variable isn't active. I used this code for all directional inputs and it's changing to the diagonal sprites now.
IF B==9 AND NERUN==0 THEN SPANIM 0,2,ARRAY,0:NERUN=1
IF B==9 AND OLDDIR!=NEWDIR THEN OLDDIR=NEWDIR:NERUN=0
Again, thanks for the assistance everyone. I've got the animation wrapped around the circle/directional pad and it works the way I want it to.