#136349 - Phantaseur - Tue Jul 31, 2007 8:31 pm
[Images not permitted - Click here to view it]
I have problems with sprite rotation. Example is on picture. I'm making simple snake game, there is example of rotation of snake's head on picture, I have correct image just when there is no rotation, in other cases I have some elements of sprite missed.
When rotating 90 degrees there is last column of pixels in sprite missed and sprite moved one pixel right; in case of 180 & 270 degrees there are same problems.
For initialization of rotation I used next code:
0 - no rotation, 1 - 90 degees, 2 - 180 degrees, 3 - 270 degrees.
For displaying sprite:
rd depends of orientation of head (can be 0,1,2 or 3), hy & hx are coordinates of snakehead in cell units, not in pixels.
What I have to do to get correctly rotated images?
I have problems with sprite rotation. Example is on picture. I'm making simple snake game, there is example of rotation of snake's head on picture, I have correct image just when there is no rotation, in other cases I have some elements of sprite missed.
When rotating 90 degrees there is last column of pixels in sprite missed and sprite moved one pixel right; in case of 180 & 270 degrees there are same problems.
For initialization of rotation I used next code:
Code: |
for(int i=0;i<4;i++){
snrot[i].hdx = COS[i*128 & 0x1FF] >> 4; snrot[i].hdy = SIN[i*128 & 0x1FF] >> 4; snrot[i].vdx = -snrot[i].hdy; snrot[i].vdy = snrot[i].hdx; |
For displaying sprite:
Code: |
snspr[0].attribute[0] = ATTR0_COLOR_256 | ATTR0_ROTSCALE | (hy*8&0x0ff);
snspr[0].attribute[1] = ATTR1_ROTDATA(rd) | ATTR1_SIZE_8 | (hx*8&0x01ff); snspr[0].attribute[2] = 0; for(int j=0;j<8*4;j++) SPRITE_GFX[j+0]=(snakehead[2*j+1]<<8)|snakehead[2*j]; |
What I have to do to get correctly rotated images?