Basically I'm having a sprite move using values I got from STICK. Thing is, I need the sprite to point towards whatever direction the stick is pointing in. For reference heres my code so far:
Spset 1,100,100,-64
@gameloop
Stick out POSINFOX,POSINFOY
POSX=POSX+POSINFOX*2:POSY=POSY-POSINFOY*2
Spofs 1,POSX,POSY
VSYNC 1
GOTO @gameloop
Rotating sprite to stick values?
Root / Programming Questions / [.]
NoxusCreated:
You want to rotate the sprite so it's pointing in the direction/angle the stick is pointed? Try this:
SPROT 1,DEG(ATAN(POSINFOX,POSINFOY)SPROT takes an angle (in degrees) and sets the rotation angle of the given sprite (in this case 1). ATAN(), when given 2 parameters, will determine the angle of the coordinate relative to the origin (in radians). We use DEG() to convert the result of ATAN() to a degree value.
I was working on this and had figured the trigonometry part with rotation, but there's a problem with rotation since the angle of rotation is based on the upper left corner, not the center. The problem causes the sprite to jump around when you alternate between two different directions (as in, pressing up, down, up, down will cause the sprite to jump left and right). I couldn't figure out how to fix that.
You want to rotate the sprite so it's pointing in the direction/angle the stick is pointed? Try this: SPROT 1,DEG(ATAN(POSINFOX,POSINFOY)) SPROT takes an angle (in degrees) and sets the rotation angle of the given sprite (in this case 1). ATAN(), when given 2 parameters, will determine the angle of the coordinate relative to the origin (in radians). We use DEG() to convert the result of ATAN() to a degree value.This is exactly the kind of idea I had in mind, you just worded it for me correctly. Thanks this helps a ton! I figured it was something close to that.
I was working on this and had figured the trigonometry part with rotation, but there's a problem with rotation since the angle of rotation is based on the upper left corner, not the center. The problem causes the sprite to jump around when you alternate between two different directions (as in, pressing up, down, up, down will cause the sprite to jump left and right). I couldn't figure out how to fix that.The angle of rotation with the sprite itself? I think I can change that with SPHOME, if not, I'll have a look at in. Thanks for the input!
Okay so I used the trig as mentioned earlier, but the problem is my triangle sprite rotates facing INWARDS to where I'm moving it, aka if I move the circle pad in a circle the triangle faces inwards/the opposite direction I want it to. This doesn't seem to be a problem with SPHOME, because if I use that it just changes where the rotation starts, and not the orientation itself. Make any sense?
It could be that the sprite is upside down.