×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    8

    Parabolic path and move a sprite at all angles

    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. #2
    Registered User
    Join Date
    Dec 2012
    Location
    Zagreb, Croatia
    Posts
    73

    Re: Parabolic path and move a sprite at all angles

    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. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    8

    Re: Parabolic path and move a sprite at all angles

    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. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: Parabolic path and move a sprite at all angles

    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. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    8

    Re: Parabolic path and move a sprite at all angles

    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. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: Parabolic path and move a sprite at all angles

    Quote Originally Posted by dhruvpsaru View Post
    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. #7
    Registered User
    Join Date
    Jan 2013
    Posts
    8

    Re: Parabolic path and move a sprite at all angles

    ok i will try that..
    Thanks

  8. #8
    Registered User
    Join Date
    Jan 2013
    Posts
    8

    Re: Parabolic path and move a sprite at all angles

    Ok please let me know

    Will using m3g slow my game?...

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: Parabolic path and move a sprite at all angles

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

  10. #10
    Registered User
    Join Date
    Jan 2013
    Posts
    8

    Re: Parabolic path and move a sprite at all angles

    ok ..
    Thanks for support

  11. #11
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,567

    Re: Parabolic path and move a sprite at all angles

    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. #12
    Registered User
    Join Date
    Jan 2013
    Posts
    8

    Re: Parabolic path and move a sprite at all angles

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

    By the way thanks again

  13. #13
    Registered User
    Join Date
    Jul 2012
    Posts
    1

    Re: Parabolic path and move a sprite at all angles

    awesome!
    Thanks for sharing with us

Similar Threads

  1. how to move view window at angles
    By rocksvick in forum Mobile Java General
    Replies: 0
    Last Post: 2010-11-19, 06:23
  2. parabolic movement ....
    By custom_made in forum Mobile Java Games
    Replies: 15
    Last Post: 2008-09-05, 09:36
  3. Parabolic effect
    By sssmails in forum Mobile Java General
    Replies: 4
    Last Post: 2008-09-05, 09:31
  4. Sprite GameCharacter Movement & Sprite Deletion
    By bloodyknight in forum Mobile Java General
    Replies: 2
    Last Post: 2004-07-10, 02:34

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •