# Thread: Parabolic path and move a sprite at all angles

1. Hi

Please let me know is it possible to make a sprite follow a parabolic path and move or rotate sprite at all angles. I am trying to use parabolic equations but i am stuck in this.

2. Hi,

it is possible to move a sprite in any path that you can calculate. What you need is a simple function that will return position for any point in time. Something like:
f(t) = (t * vx, height - t * t * vy) = (x, y)

Let me explain:
- t = time in miliseconds
- vx = horizontal speed
- vy = vertical speed
- height = height of the screen

What you need to do is call this function in the Update method to get the position for that point in time and then use the result to position the sprite. Once you have a position, it is easy to draw it. As for rotation, this depends on the target framework.

Which framework are you using for game development?

3. Thanks for help

I am working in J2me. I was trying to implement something like this as i have already found angle.

Basically these are equations for projectile motion.

x =(initial_velocity*t_time*Cos(angle));
y =(initial_velocity*t_time*Sin(angle)-0.5*gravity*(t_time)^2);

4. Yes, the expressions in #3 are the correct ones.
For the rotation stuff, there is no direct, built-in support in Java ME. You can experiment with using 3D library for 2D rendering (if the target devices have M3G support), or you can implement some bitmap rotator algorithm yourself.

5. Ok i was able to move a sprite in parabolic path by moving sprite x,y each time.But that was not accurate as i can't use decimal values.

I have practically no knowledge of 3d library but i will try using M3G.
Can you give me slight idea about bitmap rotator algorithm?

Thanks for support

6. Originally Posted by dhruvpsaru
Ok i was able to move a sprite in parabolic path by moving sprite x,y each time.But that was not accurate as i can't use decimal values.
You can use fixed point arithmetics. Instead of working with x, work with x*100. Addition and subtraction remains the same, multiplication needs a division (x*100*y*100=(x*y*100)*100, so you need to divide back the result by 100). In your expression there are no real divisions, but that would also need "fixing" at the end as 100/100 disappears. For working with 0.5*gravity, you end up with 50*gravity of course, but that is more of a pre-calculated constant anyway.
In the computing world that 100 is usually a power of 2, like 256 (a complete byte, out of the 4 you have in a 32-bit integer), this way the "fixing" divisions/multiplications can be done with the shift operators ( >>8 instead of /256 ), which is faster.
I have practically no knowledge of 3d library but i will try using M3G.
Me neither, but it is absolutely sure that there are tutorials for it.
Can you give me slight idea about bitmap rotator algorithm?
I provided such stuff once, in http://www.developer.nokia.com/Commu...otate-an-image, just it is (Symbian) C++.
The idea is not difficult:
1- calculate the corners for the rotated shape (sin-cos things, you already know)
2a- walk the edges between these corners, also interpolating the texture coordinates
2b- store the leftmost/rightmost coordinates and the respective texture coordinates for each y-position you traverse while walking the edges
3- fill the lines: you have the leftmost(L) and rightmost(R) coordinates for each scanline, and the respective texture coordinates(LU,LV,RU,LV)

In step 1 the texture coordinates just rest.
In step 2 the "lines" should be interpolated vertically, since you need a single x coordinate for every y position
In step 3 the interpolation is horizontal, since you want to draw each pixel between L and R in the given line
You may want to ignore the DDA magic, and use fixed point stuff instead.

7. ok i will try that..
Thanks

8. Ok please let me know

Will using m3g slow my game?...

9. Originally Posted by dhruvpsaru
Will using m3g slow my game?...
I do not know, I have no experience with M3G.

10. ok ..
Thanks for support

11. By the way, it may be worth mentioning here that there are specialized Java ME boards hosted on this site too: http://www.developer.nokia.com/Commu...?3-Mobile-Java

12. thanks and i started with m3g and trying to get hold of it..

By the way thanks again

13. awesome!
Thanks for sharing with us

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.