Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (731) Games in Android Showcase (217) games submitted by our members Games in WIP (799) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
 Home Help Search Login Register
Pages: [1]
 ignore  |  Print
 Make image follow designated path?  (Read 2514 times) 0 Members and 1 Guest are viewing this topic.
wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 2 years

https://github.com/wreed12345

 « Posted 2012-10-29 13:58:38 »

how can i make an image follow an intricate path. This is for a video game just saying. Currently i am using this code but it only makes it go right for about 200 pixels then back left for 200 and this goes in a loop. How can I make this more intricate?

homelessX is the x position of the image

 1  2  3  4  5  6  7  8  9  10  11  12 `      if(go == true){         homelessX += .04f;         if(homelessX > 800){            go = false;         }      }      if(go == false){         homelessX -= .04f;         if(homelessX < 600){            go = true;         }      }`

Joshua Waring
 « Reply #1 - Posted 2012-10-29 14:05:44 »

I don't know, but I assume you could use a Multiple quadratics and when it gets to the end of the path (curve) jump to the next equation to calculate the new positions.
Basically, break down the path into individual curves, use some tool to find the equation of that curve and use multiple equations to form a single long line, jumping between equations depending on the position.

I'm sure there's a better way, but that's my take on the situation.

The world is big, so learn it in small bytes.
wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 2 years

https://github.com/wreed12345

 « Reply #2 - Posted 2012-10-29 14:07:21 »

So do you mean use things like parabola equations?

 Games published by our own members! Check 'em out!
 « Reply #3 - Posted 2012-10-29 14:09:03 »

What is the starting point and what kind of path do you want the sprite to follow? A set path or something dynamic?
Joshua Waring
 « Reply #4 - Posted 2012-10-29 14:11:15 »

Cubic http://math1sfun.files.wordpress.com/2012/07/cubicequ.gif?w=584

EDIT - I'll make a nice picture with me 'amazing' paint skills to show what I mean

http://www.java-gaming.org/user-generated-content/members/130357/untitled.jpg

where it says Jump, you'd swap the equation.

The world is big, so learn it in small bytes.
wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 2 years

https://github.com/wreed12345

 « Reply #5 - Posted 2012-10-29 14:13:14 »

I want the sprite to follow a intricute path (dynamix is optional) just so the user wouldnt spend enough time figuring out the path, so dynamic if possible

wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 2 years

https://github.com/wreed12345

 « Reply #6 - Posted 2012-10-29 14:14:06 »

So I would just use these equations and put in the x value of the image as the x value of the equation?

Joshua Waring
 « Reply #7 - Posted 2012-10-29 14:21:36 »

Throw in sprite's X position or Y position depending on the equation you use and the shape it makes.
and it'll throw out the opposite value so Y = 2x^2 (which is a curve) at position x = 3 Y will be, 18. x = 4, Y will be 32

The world is big, so learn it in small bytes.
wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 2 years

https://github.com/wreed12345

 « Reply #8 - Posted 2012-10-29 14:24:34 »

Could you show me an example of this code in action? Like if the x value was derpX and the y value was derpY , i am not understanding how you implement the equation in the code

Joshua Waring
 « Reply #9 - Posted 2012-10-29 14:34:35 »

 1  2  3  4  5  6  7  8  9  10  11  12 `   double Posx = -20;    double Posy;    public void random(){        // render frame        for(int loop = -20; loop < 20; loop++){            Posx++;            // Posy = -0.5x^2            Posy = -0.5*Math.pow(Posx, 2) + 200;            System.out.println(Posy);        }            }`

That's only using one equation, but it gives you the idea, It prints out the values and what it would give in the end is something starting at x = -20 and y = 0 moving to y = 200 at x = 0 then y = 0 at x = 20 in a smooth curve. which you can graph at graph.tk

The world is big, so learn it in small bytes.
 Games published by our own members! Check 'em out!
wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 2 years

https://github.com/wreed12345

 « Reply #10 - Posted 2012-10-29 14:51:50 »

you completely lost me lol

StumpyStrust
 « Reply #11 - Posted 2012-10-29 15:19:45 »

Posy? cap for a variable name? no!!!!

Not trying to be rude but read up on equations a little

http://library.thinkquest.org/20991/prealg/graph.html

Once you get that, you will understand that by plugging in your x value into an equation, it will give you your y value. So as you tick x, your y will change.

 1  2  3  4  5  6  7  8 `int x = 1;int y = 1;public void tickObject(){      x++;      y = x + 2;   // This is your equation. It could be something more complicated like Sin(x^2)/arctan(blah blah blah) }`

Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 Archive (341 views) 2017-04-27 17:45:51 buddyBro (538 views) 2017-04-05 03:38:00 CopyableCougar4 (988 views) 2017-03-24 15:39:42 theagentd (1020 views) 2017-03-24 15:32:08 Rule (995 views) 2017-03-19 12:43:22 Rule (978 views) 2017-03-19 12:42:17 Rule (975 views) 2017-03-19 12:36:21 theagentd (1077 views) 2017-03-16 05:07:07 theagentd (997 views) 2017-03-15 22:37:06 theagentd (771 views) 2017-03-15 22:32:18
 List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05SF/X Librariesby SkyAphid2017-03-02 06:38:56SF/X Librariesby SkyAphid2017-03-02 06:38:32SF/X Librariesby SkyAphid2017-03-02 06:38:05SF/X Librariesby SkyAphid2017-03-02 06:37:51
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org