Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (806)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
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  
  Animation Hiccup  (Read 3303 times)
0 Members and 1 Guest are viewing this topic.
Offline jerryq27

Senior Newbie


Medals: 1
Exp: 1 year



« Posted 2015-02-12 22:52:35 »

Hi, this is my first post to Java-Gaming (Newbie alert),
and I'm having a little trouble with Animation,
I used a custom 2D Animation class for a game I am working on
and the animation of the sprite runs well, it's just
When I first move up, the sprite disappears for a split second, then reappears,
same results when I move down. It's only the initial press of the keys, after that, the animation is smooth,
oddly enough, the right/left movement doesn't have the hiccup on the first press of the keys.
Any idea what could be the cause for this?
Hope I explained it well-enough, if not, let me know!
Note: I am only using the standard Java libraries

Here's the Animation class (runAnimation() is called in 'update', drawAnimation() is called in 'render'):
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  
30  
31  
32  
33  
import java.awt.Graphics;
import java.awt.image.BufferedImage;

public class Animation {

   private int animSpeed; //Animation speed.
   private int count = 0; //Works with the animSpeed, to control the animation speed.
   private int frames; //Number of frames in the animation.
   private int index = 0; //Current frame.
   private BufferedImage[] animation;
   private BufferedImage currentImage; //The current image in the animation.
   
   public Animation(BufferedImage[] images, int speed) {
      animation = images;
      animSpeed = speed;
      frames = animation.length;
   }

   public void runAnimation() {
      count++;
     
      if(count > animSpeed)
      {
         count = 0;
         currentImage = animation[index % frames]; //Change the image for drawAnimation.
          index++; //For next image.    
      }
   }
   
   public void drawAnimation(Graphics g, int x, int y, int scaleX, int scaleY) {
      g.drawImage(currentImage, x, y, scaleX, scaleY, null);
   }  
}
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2015-02-12 23:13:33 »

set currentImage to animation[0] in the constructor

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline jerryq27

Senior Newbie


Medals: 1
Exp: 1 year



« Reply #2 - Posted 2015-02-13 00:15:33 »

set currentImage to animation[0] in the constructor

You sir, are awesome, and you deserve a cookie.
Thank you
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 383
Projects: 11
Exp: 4 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #3 - Posted 2015-02-13 03:46:07 »

set currentImage to animation[0] in the constructor

You sir, are awesome, and you deserve a cookie.
Thank you

Not that Riven really needs any more, but you can press the appreciate button on his post to give him some magical [citation needed] internet points called medals.

Offline jerryq27

Senior Newbie


Medals: 1
Exp: 1 year



« Reply #4 - Posted 2015-02-13 05:26:14 »

set currentImage to animation[0] in the constructor

You sir, are awesome, and you deserve a cookie.
Thank you

Not that Riven really needs any more, but you can press the appreciate button on his post to give him some magical [citation needed] internet points called medals.

I wish I could, but I don't see it next to the 'quote' button, I guess I don't have enough experience.
Offline CopyableCougar4
« Reply #5 - Posted 2015-02-13 05:58:57 »

I wish I could, but I don't see it next to the 'quote' button, I guess I don't have enough experience.


Either wandering the forum or programming. Most likely the latter Smiley

Github: http://github.com/CopyableCougar4
Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2015-02-13 07:12:00 »

JGO medals piggyback on SMF karma, which has some odd post count requirement.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (587 views)
2019-09-04 15:33:17

hadezbladez (5528 views)
2018-11-16 13:46:03

hadezbladez (2410 views)
2018-11-16 13:41:33

hadezbladez (5790 views)
2018-11-16 13:35:35

hadezbladez (1233 views)
2018-11-16 13:32:03

EgonOlsen (4669 views)
2018-06-10 19:43:48

EgonOlsen (5688 views)
2018-06-10 19:43:44

EgonOlsen (3205 views)
2018-06-10 19:43:20

DesertCoockie (4104 views)
2018-05-13 18:23:11

nelsongames (5125 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04: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!