Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Sprite collision help - multiple sprites on elliptical orbit - how to best get position of visible pixels in the sprite?

Author
Message
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 18th Feb 2013 10:43
I'm looking for some ideas on how to handle the following problem:
The attached sprite rotates around the center an each of the arms of the ship are actually separate sprites so they can be removed as the ship is damaged. The image size for the arms is the same as the entire image so that the arms appear as if the rotate around the central body of the ship.
My problem is how to get the location of the center of the disc at the end of the arm. I need to do this to show the explosion animation correctly.

A couple ideas I have are:
1)Constantly update the sprite shape since that apparently ignores the transparency and detect where the last missile hit then show the explosion there. This would be OK, but I'd rather get the center of the disc at the end of the arm.

2)This method will require more coding and will be problematic. I'd hard code in the location of each disc's center in relation to the animation frames. The discs are in an ellipse, so this is possible, but it will be a bit painful since there will be 30 frames and the entire ship will move about the screen. But it should be pretty accurate once I get the equations right.


So.... if anyone has any recommendations on how to handle something like this, I'd love to hear it.

Thanks!

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Feb 2013 11:08 Edited at: 18th Feb 2013 11:08
I honestly don't think this will be possible using sprites. Certainly not to create a realistic 3D effect. You should do this in 3D.

You can position sprites on an ellipse relatively easily but even then a 3D ellipse is not so easy. For that I would set up a 3D object rotating around a point and store its position on the screen in 2D co-ordinates then use those co-ordinates to position my sprites. That way your positioning would appear correct for an ellipse in perspective, but the effect you want is best done fully in 3D.


this.mess = abs(sin(times#))
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 18th Feb 2013 11:50
If you're rotating around a given point for each arm (and not changing the size of the sprite or point of rotation) then you can work out the centre of the disc with a bit of trig. You'll have to know the distance of the centre of the disc from the point of rotation.

Let's say the distance is 70px then it'd be something like:
x# = cos(angle) * distance
y# = sin(angle) * distance

Where the angle is simply the angle you've rotated the sprite to. Depending on the sprite, you might have to offset this so if it doesn't look like it's working try adding different multiples of 90 inside the trig functions like
cos(angle+90) or cos(angle+180).

As baxslash says though, this probably isn't the best way to achieve the effect you're after.

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 18th Feb 2013 19:02
I think Hodgeys idea is correct. But you would have an xDistance and a yDistance, this would give you your oval shape(x bigger than y).

Create a test sprite and position it according to Hodgeys formula, increase the angle each frame(0-360) and the sprite should go around in an oval(or circle if xDistance and yDistance are the same).

All you need to do then is get the angle for the frame, if you have 30 frames and you are on frame 5 then the angle will be 360 / 30 * 5(I think?).

Hope that helps.

Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 19th Feb 2013 03:14
Thanks, guys. I'll likely be going the mathematical route.
The equation is a little bit of a bear, but I can do it!!

Cheers!

Login to post a reply

Server time is: 2024-05-02 16:27:52
Your offset time is: 2024-05-02 16:27:52