Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » pivot sprite help

This thread is locked; no one can reply to it. rss feed Print
pivot sprite help
MSGleader
Member #6,637
December 2005

ok, in my game i have a tank, and your looking at it from the side. and im trying to pivot the turret sprite so the turret rotates just like in the game pocket tanks, or the game worms, where you can aim everywhere... if im making any sense here, you should understand what i mean.

im having troubles with my pivot angle stuff...

i have :

pivot_sprite(buffer,turret_bmp,tanks[0].x+15,tanks[0].y+2,2,14,ftofix(tanks[0].angle));
textprintf_ex(buffer,font,20,320,makecol(255,0,0),-1,"Angle: %d",ftofix(tanks[0].angle));

The turret rotates... but when i want to show the angle it is at on the screen.
it doesnt show the correct number for the direction. it just shows a lot of numbers that dont make sense... and when i take the ftofix out of the textprint function... it just shows a 0.

my tanks[0].angle is just a float number. and i add 1 to it when i press right, and subtract 1 from it when i press left...

is there a special way to do this stuff, or am i just doing everything wrong?

Jonny Cook
Member #4,055
November 2003

%d is for integers. You want to use %f. Try this: "Angle: %.2f".

Go here for more info.

[edit]
Oh, nevermind. That's only part of your problem. Get rid of the ftofix in textprintf_ex.

textprintf_ex(buffer,font,20,320,makecol(255,0,0),-1,"Angle: %.2f",tanks[0].angle);

Assuming tanks[0].angle is indeed a float (or double), that should work. ftofix converts a float to a fixed point number. You only want to do that when, well, you need a fixed point number. In this case you don't.

The face of a child can say it all, especially the mouth part of the face.

MSGleader
Member #6,637
December 2005

thanx, i tried that, and it works now! :)
just one of those small things you overlook eh?

Tobias Dammers
Member #2,604
August 2002
avatar

To make it even more human-readable, you'll want to convert from allegro's 256-deg format to the usual 360 degrees:

textprintf_ex(buffer,font,20,320,makecol(255,0,0),-1,"Angle: %.2f",tanks[0].angle * 360.0f / 256.0f);

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Go to: