forums

TNT Basic Forums > Programming Q&A
Rotating 1 sprite around another
< Last Thread     Next Thread >
Author
Thread        Post A Reply

05-04-2003 02:30

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

I want to have a sprite, which can be anywhere anytime, and be able to rotate a sprite around it. The rotating sprite will always be 50 pixels away from the centre one, however it can be anywhere around the first sprite.

I know I'll have to use a mathematical formula, but I cannot figure out what it is.

BTW, is there a way to find out if the mouse is currently moving? I wan't my mouse cursor to be hidden, but to re-appear when they move it.

05-04-2003 04:24

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

you could try making the sprite that has to rotate around the other with enough empty space so that when it rotates it appears to be rotating around the other sprite. just position the rotating sprite's pivot point - i think it's called the "hotspot" - so that it will always line up with the other sprite.

as for detecting if the mouse is moving, in fact from the computers point of view the mouse is never moving. the program repeatedly evaluates the mouses location, so to your application it is always stationary, or at least that's my understanding. but that doesn't mean that you can't do whatever it is you want to do, i just donít know how to do it.

05-04-2003 09:06

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

About the mouse, I could just check before every screen update whether the mouses xy co-ords are the same as they were in the last screen update. If not, the mouse had moved.

About rotating the sprite, I never actually realised what the hotspot was, but yeah, that idea might well work.

05-04-2003 14:02

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

The math formula is :

x=(cos(deg)*5)+xx
y=(sin(deg)*5)+YY

where x and y are the coords od the rotating sprite, deg is the amount to rotate in degrees, 5 is the radius, xx and yy are the coords indicating the center of the rotation.

Another tip:

x=(cos(deg)*5)+x
y=(sin(deg)*5)+y
sprite 1,x,y,0

This moves sprite 1 of 5 pixels in the direction contained in deg.

05-05-2003 05:35

Posted by:
eekaydee

Location:
CA, USA

Click Here to Email eekaydee   Find more posts by eekaydee

Doesn't the game "Beans" rotate sprites around others? Maybe you could check how Beans does it

05-05-2003 09:48

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

Yeah I tried the first idea, discovered Set Sprite Rotation requires hardware mode, so enable it. It cut my FPS from ~90 down to lees than 5.
Anyway, thanks for the formula, I'm just gonig to try it now.

05-06-2003 07:09

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

I tried that formula, it didnt work. Could you send it in a project maybe, so that I can see exactly how it works?

05-06-2003 16:24

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

int deg,x,y,xx,yy,execution=true

while execution

xx=mouse x ' place the aimer choords at mouse
yy=mouse y

sprite 2,x,y,1 'show the rotating sprite
sprite 1,xx,yy,1 'show the aimer

x=(cos(deg)*5)+xx 'rotate x and y choords
y=(sin(deg)*5)+YY

deg=deg+2 'if you keep the same deg it won't rotate

wend

05-11-2003 06:49

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

dude, are you sure that code will work? I have the following code:

int deg,x,y,xx,yy,execution=true
graphics mode 1152, 864
VBL Sync off
while not pressed(12)
xx=mouse x ' place the aimer choords at mouse
yy=mouse y
sprite 2,x,y,0 'show the rotating sprite
sprite 1,xx,yy,1 'show the aimer
x=(cos(deg)*5)+xx 'rotate x and y choords
y=(sin(deg)*5)+YY
deg=deg+2 'if you keep the same deg it won't rotate
Draw Frame
wend

And it doesn't work.

05-11-2003 07:00

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

Oops sorry, I forgot to add a "Load images 128" in there.
TNT really needs to check for that!!

05-19-2003 10:00

Posted by:
Jason Anderson

Location:
Doylestown, PA

Click Here to Email Jason Anderson   Find more posts by Jason Anderson

I want to thank you guys, even though I'm not making a game with rotating sprites, the Cos/Sin stuff was something I didn't know how to do. You guys helped me out so much. Inadvertantly. Now my Asteroids clone is gonna come out great.

05-23-2003 04:56

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

OK, I have another problem now:

When my player is facing right, the sight is on the right and thats all good. However, when he faces left, the sight stays on the right. How can I make the sight flip over to be facing the right way?
Also, how can I prevent the sight from rotating around so much that it ends up behind the player. eg. make it only able to rotate until its directly above or below them. I have this code to rotate the sprite,
if Pressed(126)
sightX=(cos(deg)*50)+w1X
sightY=(sin(deg)*50)+w1Y
deg = deg - 2
(thats for the up key, rotates up)
I had an if statement to only rotate if deg was less than 90 (or more, I can't remember), but that meant it would only rotate up, not down any more. And it still went past vertical.

Anyone able to help?

Thanks, Sam.

05-24-2003 23:19

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

Anyone?

05-25-2003 14:26

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Well, you could try and do it by yourself :)

Seriously, I don't know by hearth. You should try soething with if statements, like:

if ( changeSide )

if deg>0 and deg<90 then deg=deg+180
etc.


end if

05-26-2003 09:10

Posted by:
Freefall

Click Here to Email Freefall   Find more posts by Freefall

I have tried it myself. I have spent most the time since I got a working peice of code for rotating the sprite trying to figure out those 2 things. The code I was using, I have found no problems with, it just doesn't work. I can't figure out what the problem is.
I am trying to figure out all this maths stuff, but with me being only in 5th form, I'm not particualry good at it.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.