Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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  
  Making a sprite jump?  (Read 1048 times)
0 Members and 1 Guest are viewing this topic.
Offline wreed12345
« Posted 2013-01-05 22:01:08 »

In order to make something simply jump would I use a parabola or something simpler?
Online matheus23

JGO Wizard


Medals: 72
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2013-01-05 22:09:43 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
public class JumpingThing {

   // You might want to play around with this:
  public static final float METER_TO_PIXELS = 32f;
   public static final float SECONDS_TO_FRAMES = 1f / 60f;
   // 9.81 [m/s²] is the average ground factor on earth. This is the value to play around,
  // if you want the game to play on the moon, for example
  public static final float GRAVITY = 9.81f * METER_TO_PIXELS * SECONDS_TO_FRAMES;

   // Play around with this value as well:
  public static final float JUMP_POWER = 10f; // The higher this value, the higher (stronger) it jumps.

   // Usually you'd also have X position and so on, but I leave it out, since it's only going up or down
  private float velocityY;
   private float positionY;

   public void update() {
      // Make the object accelerate towards the bottom
     velocityY += GRAVITY;
      // If you use this method names I'll kill you :P
     if (thisThingWantsToJump() && thisThingIsAbleToJump()) {
         // It's minus, because it's going down, not up.
        // Remove the minus, when you have your y values
        // increasing to the top.
        velocityY = -JUMP_POWER;
      }
      positionY += velocityY;
   }
} // That's it!

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Jimmt
« Reply #2 - Posted 2013-01-05 22:32:47 »

http://lmgtfy.com/?q=jumping+in+java

Seriously, you needed to create a new thread for this? There are countless examples and explanations online and even here on this forum.
Games published by our own members! Check 'em out!
Try the Free Demo of Titan Attacks
Online matheus23

JGO Wizard


Medals: 72
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2013-01-05 22:34:09 »

http://lmgtfy.com/?q=jumping+in+java

Seriously, you needed to create a new thread for this? There are countless examples and explanations online and even here on this forum.

I hate lmgtfy links, but basically you're right.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Best Username Ever

Junior Member





« Reply #4 - Posted 2013-01-05 22:36:12 »

Seriously?

Edit: Ninja'd. Search for gravity in games or something.
Offline sproingie
« Reply #5 - Posted 2013-01-05 22:45:44 »

In order to make something simply jump would I use a parabola or something simpler?

This endless parade of really basic questions is really starting to wear on people here.  You need to do some really basic research first, and if you're still stuck, flesh out your questions with something you've already tried.  Show a little effort.
Offline wreed12345
« Reply #6 - Posted 2013-01-05 22:48:35 »

I suppose you are right about that, i try and learn things quickly and often dont find results as quickly as I want so I come here... I will start spending more time researching from now on
Online matheus23

JGO Wizard


Medals: 72
Projects: 3


You think about my Avatar right now!


« Reply #7 - Posted 2013-01-05 22:49:57 »

I suppose you are right about that, i try and learn things quickly and often dont find results as quickly as I want so I come here... I will start spending more time researching from now on

Now, did my post help you, at least? Cheesy

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline wreed12345
« Reply #8 - Posted 2013-01-05 22:51:47 »

I have not tried it yet but should velocityY += GRAVITATION; in the second line of the update method be velocityY += GRAVITY; ?
Online matheus23

JGO Wizard


Medals: 72
Projects: 3


You think about my Avatar right now!


« Reply #9 - Posted 2013-01-05 23:35:35 »

I have not tried it yet but should velocityY += GRAVITATION; in the second line of the update method be velocityY += GRAVITY; ?
Yes. sorry, typo Smiley *fixing it*

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline wreed12345
« Reply #10 - Posted 2013-01-06 00:22:27 »

Thanks it works great! i now know I shouldnt ask things like this here
Offline ReBirth
« Reply #11 - Posted 2013-01-06 02:57:11 »

Also, this is wrong forum section. Should be Newbie Questions Pointing

Offline PeterNicholson

Senior Member


Medals: 3
Projects: 1



« Reply #12 - Posted 2013-01-06 14:32:11 »

Hmmm?? maybe wreed12345 doesent like doing his homework...  Shocked
Pages: [1]
  ignore  |  Print  
 
 

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (77 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (119 views)
2013-05-16 00:53:38

gouessej (113 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (156 views)
2013-05-14 15:56:26

kutucuk (179 views)
2013-05-12 17:10:36

kutucuk (179 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.153 seconds with 22 queries.