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.
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.
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?
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);
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.
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
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.Me neither, but it is absolutely sure that there are tutorials for it.I have practically no knowledge of 3d library but i will try using M3G.I provided such stuff once, in http://www.developer.nokia.com/Commu...otate-an-image, just it is (Symbian) C++.Can you give me slight idea about bitmap rotator algorithm?
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.
awesome!
Thanks for sharing with us