Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (569) Games in Android Showcase (154) games submitted by our members Games in WIP (618) 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 1409 times) 0 Members and 1 Guest are viewing this topic.
wreed12345

JGO Knight

Medals: 25
Projects: 2
Exp: 2 years

http://linebylinecoding.blogspot.com/

 « 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: 25
Projects: 2
Exp: 2 years

http://linebylinecoding.blogspot.com/

 « 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: 25
Projects: 2
Exp: 2 years

http://linebylinecoding.blogspot.com/

 « 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: 25
Projects: 2
Exp: 2 years

http://linebylinecoding.blogspot.com/

 « 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: 25
Projects: 2
Exp: 2 years

http://linebylinecoding.blogspot.com/

 « 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: 25
Projects: 2
Exp: 2 years

http://linebylinecoding.blogspot.com/

 « 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.

 Riven (23 views) 2015-04-16 10:48:47 Duke0200 (35 views) 2015-04-16 01:59:01 Fairy Tailz (27 views) 2015-04-14 20:13:12 Riven (29 views) 2015-04-12 21:36:37 bus hotdog (45 views) 2015-04-10 02:39:32 CopyableCougar4 (47 views) 2015-04-10 00:51:04 BurntPizza (46 views) 2015-04-06 22:06:58 ags1 (51 views) 2015-04-02 10:58:48 Riven (49 views) 2015-04-01 18:27:05 ags1 (66 views) 2015-03-31 10:55:12
 BurntPizza 24x theagentd 21x wessles 15x 65K 12x Rayvolution 12x kingroka123 11x alwex 10x KevinWorkman 9x kevglass 8x ra4king 8x phu004 8x Hanksha 7x SHC 7x Olo 7x Ecumene 7x chrislo27 7x
 How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21Resources for WIP gamesby kpars2014-12-18 10:26:14Understanding relations between setOrigin, setScale and setPosition in libGdx2014-10-09 22:35:00Definite guide to supporting multiple device resolutions on Android (2014)2014-10-02 22:36:02List of Learning Resources2014-08-16 10:40:00List of Learning Resources2014-08-05 19:33:27
 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