TNT Basic Forums > Programming Q&A
How to make objects rotate around a point.
< Last Thread     Next Thread >
Thread        Post A Reply

01-16-2002 17:48

Posted by:

Click Here to Email   Find more posts by

In other words.

Say I have a game and I wanna make it so when the character picks up an object a group of stars (Or some other thing) will spin around the character.

Anyone have an example of how to have an object moving around a specified point? Make it customizable in distance from center, speed of objects and number of objects.

Help would be appreciated.


01-18-2002 04:53

Posted by:
Alex Ni

Click Here to Email Alex Ni   Find more posts by Alex Ni

Pixels spin about a point

I've hacked up this little example to give you an idea how to
do this sort of thing. The basic idea is that you can convert
an angle and a radius into x and y by using sine, cosine, and
some multiplication. That is, if you have angle a and radius r,
you can get point (x,y) by

( cos(a) * r, sin(a) * r )

Here's the example, where a bunch of pixels spin around the

' Graphics init- needs to be done only once
Graphics Mode 640,480
Set Framerate 60
Vbl Sync On

Global int kStarMax=100
' Data for each star
Global float gStarAngle[kStarMax]
Global float gStarRadius[kStarMax]

' Initialize to random
Procedure InitStars()
int n
for n=0 to kStarMax-1
gStarAngle[n] = Random(0,360) ' degrees
gStarRadius[n] = Random(0,170) ' pixels
next n
End Proc 'InitStars

' Cycle through until user clicks
int oldmousex, oldmousey, mousex, mousey
oldmousex = Mouse X
oldmousey = Mouse Y

while not (Mouse Button)
int n
mousex = Mouse X
mousey = Mouse Y
for n=0 to kStarMax-1
int starx, stary
' erase old
starx = oldmousex + gStarRadius[n] * Cos(gStarAngle[n])
stary = oldmousey + gStarRadius[n] * Sin(gStarAngle[n])
' You could do Sprite() here if you wanted to instead of
' Set Pixel Colour.
Set Pixel Colour starx, stary, Make Colour (0, 0, 0)
' Increase angle for animation
gStarAngle[n] = mod(gStarAngle[n] + 5, 360)
' draw new
starx = mousex + gStarRadius[n] * Cos(gStarAngle[n])
stary = mousey + gStarRadius[n] * Sin(gStarAngle[n])
Set Pixel Colour starx, stary, Make Colour (255, 255, 255)
next n
Draw Frame
' save mouse x and y for next time
oldmousex = mousex
oldmousey = mousey
wend 'not (Mouse Button)

- Alex

01-18-2002 06:19

Posted by:

Click Here to Email   Find more posts by


The code works, I have created an Example of it. I will have to play around with it later.

Thank you. This will help me do some neat effects.

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.