# cant rotate sprite

## Recommended Posts

corner    122
im trying to rotate a sprite but its either i get it appear twice at the same time on my screen with one movin diagonally and the other not movin at all or it just doesnt rotate around its own centre but around the screen plz help

##### Share on other sites
Captain P    1092
I'm afraid that without more information, we won't be able to help you. If you can tell us how you're doing your rotation right now, what library/API you're using, and anything else that you think is relevant, then I think you'll receive some helpfull posts much sooner. :)

##### Share on other sites
corner    122
This is part of my code
rotate(posArr)
{
BITMAP* sprite[10];
int col=getpixel(sprite[obj[posArr].ptrSprite],x+sx,y=sy);//sx &sy are source of the bitmap pos
int px=obj[i].angle/10*obj[i].size;
int py=obj[i].angle/10*obj[i].size;//apprently the obj[i] is supposed to be an array of pics rotated at 10deg at a time i used obj[posArr]

rotate_sprite(screen_buffer,sprite[obj[posArr].ptrSprite],nX,nY,itofix(obj[posArr].ang));//im need to use a diff fuction

}

the part of the coding you dont get ill try to explain but ive tried to change it so many times ive end up confusin myself

corner    122
im using allegro

##### Share on other sites
Looks like Allegro to me.

What you need to realize is that Allegro doesn't use 360 degrees for a full circle - it uses 256. So rotating by 10 degrees in Allegro isn't the same as rotating in coordinate geometry. I'd check your function to make sure that isn't the problem (I doubt that it is, but it's something that could be fixed anyway).

I believe you're trying to use pivot_sprite instead of rotate_sprite, and I'm surprised you're not getting an error when calling the wrong function.

void pivot_sprite(BITMAP *bmp, BITMAP *spr, int x, int y, int px, int py, int angle)...where bmp is the destination, spr is the sprite, (x,y) is the destination on bmp, (px,py) is the point of rotation, and angle is the rotation (with 256 degrees being a complete circle).

Also, if that is your entire function, there are several declared and defined variables that you don't use, alongside several undeclared and undefined variables that you do, so you may want to try and clean up the function.

Last thing I see...

int col=getpixel(sprite[obj[posArr].ptrSprite],x+sx,[b]y=sy[/b]);

I have a feeling you want y+sy, but again, you don't even use col...so it shouldn't matter.