Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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 1206 times)
0 Members and 1 Guest are viewing this topic.
Offline wreed12345

JGO Knight


Medals: 24
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;
         }
      }

Offline Joshua Waring

Senior Member


Medals: 4
Projects: 2



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

JGO Knight


Medals: 24
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?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Vladiedoo
« 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?
Offline Joshua Waring

Senior Member


Medals: 4
Projects: 2



« Reply #4 - Posted 2012-10-29 14:11:15 »

Quadratic http://hotmath.com/images/gt/lessons/genericalg1/parabola.gif
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.
Offline wreed12345

JGO Knight


Medals: 24
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

Offline wreed12345

JGO Knight


Medals: 24
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?

Offline Joshua Waring

Senior Member


Medals: 4
Projects: 2



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

JGO Knight


Medals: 24
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

Offline Joshua Waring

Senior Member


Medals: 4
Projects: 2



« 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!
Legends of Yore - The Casual Retro Roguelike
Offline wreed12345

JGO Knight


Medals: 24
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


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

you completely lost me lol

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

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (38 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (61 views)
2014-09-21 02:42:18

BurntPizza (31 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (53 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!