pivot sprite help
MSGleader

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

%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.

MSGleader

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

Tobias Dammers

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);

Thread #579317. Printed from Allegro.cc