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

JGO Knight

Medals: 28
Projects: 3
Exp: 5 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: 5 years

https://github.com/wreed12345

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

So do you mean use things like parabola equations?

 « 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: 5 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: 5 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: 5 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.
wreed12345

JGO Knight

Medals: 28
Projects: 3
Exp: 5 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

 DesertCoockie (52 views) 2018-05-13 18:23:11 nelsongames (82 views) 2018-04-24 18:15:36 nelsongames (74 views) 2018-04-24 18:14:32 ivj94 (757 views) 2018-03-24 14:47:39 ivj94 (87 views) 2018-03-24 14:46:31 ivj94 (643 views) 2018-03-24 14:43:53 Solater (102 views) 2018-03-17 05:04:08 nelsongames (184 views) 2018-03-05 17:56:34 Gornova (426 views) 2018-03-02 22:15:33 buddyBro (1086 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List 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:05
 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