Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (540)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
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 3059 times)
0 Members and 1 Guest are viewing this topic.
Offline wreed12345

JGO Knight


Medals: 25
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Posted 2013-01-05 21:01:08 »

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

Offline matheus23

JGO Kernel


Medals: 114
Projects: 3


You think about my Avatar right now!


« Reply #1 - Posted 2013-01-05 21: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
« League of Dukes »

JGO Kernel


Medals: 139
Projects: 4
Exp: 3 years



« Reply #2 - Posted 2013-01-05 21: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!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 114
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2013-01-05 21: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 Devvie





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

Seriously?

Edit: Ninja'd. Search for gravity in games or something.
Offline sproingie

JGO Kernel


Medals: 202



« Reply #5 - Posted 2013-01-05 21: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

JGO Knight


Medals: 25
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #6 - Posted 2013-01-05 21: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

Offline matheus23

JGO Kernel


Medals: 114
Projects: 3


You think about my Avatar right now!


« Reply #7 - Posted 2013-01-05 21: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

JGO Knight


Medals: 25
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #8 - Posted 2013-01-05 21:51:47 »

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

Offline matheus23

JGO Kernel


Medals: 114
Projects: 3


You think about my Avatar right now!


« Reply #9 - Posted 2013-01-05 22: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!
Legends of Yore - The Casual Retro Roguelike
Offline wreed12345

JGO Knight


Medals: 25
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #10 - Posted 2013-01-05 23:22:27 »

Thanks it works great! i now know I shouldnt ask things like this here

Offline ReBirth
« Reply #11 - Posted 2013-01-06 01:57:11 »

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

Offline PeterNicholson

Senior Devvie


Medals: 3
Projects: 1



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

Hmmm?? maybe wreed12345 doesent like doing his homework...  Shocked

Subscribe to me on YouTube: http://youtube.com/javaprogrammerguy
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.

Mr.CodeIt (20 views)
2014-12-23 03:34:11

rwatson462 (52 views)
2014-12-15 09:26:44

Mr.CodeIt (45 views)
2014-12-14 19:50:38

BurntPizza (81 views)
2014-12-09 22:41:13

BurntPizza (110 views)
2014-12-08 04:46:31

JscottyBieshaar (78 views)
2014-12-05 12:39:02

SHC (89 views)
2014-12-03 16:27:13

CopyableCougar4 (93 views)
2014-11-29 21:32:03

toopeicgaming1999 (155 views)
2014-11-26 15:22:04

toopeicgaming1999 (150 views)
2014-11-26 15:20:36
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!