Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  Tricks to get smooth animation  (Read 8396 times)
0 Members and 1 Guest are viewing this topic.
Offline Captain-Goatse

Junior Devvie

I suck at teh 2D. XBOX IS BIG LOL!111

« Posted 2002-11-02 08:59:09 »

What affects the smoothness off animation:
-Frames per second
-The amount of images used and memory available
-The quality of rendered images(if cartoonlike animation)

My problem is that no matter what, my animation is never good enough for me. For examle, let's take Scott's scrollerexample, which is quite excellent work. I never noticed any animation flaws or anything, but with my own code I'm overly critical.

My scroller has minor slowdowns and although I have pretty high end system, the methods that I use are not the most efficient. Now I have spent 5 hours, just trying to find out what makes my engine slow down randomly.

I know there isn't any cut and paste sollution for this and I'm not trying to find one, but please.

In theory, what makes smooth animation? Should the rendering be priority and then all the other actions after the loop thread. If so how is it possible to concentrate all your input/output/interaction behind the rendering?
Offline zparticle

Senior Devvie

Thick As A Brick

« Reply #1 - Posted 2002-11-02 13:21:07 »

One big thing I'm sure you are already aware of is garbage collection. You want to avoid creating objects and allowing objects to get collected during animation in your code. This is especially true for things like full screen scrolling because the entire screen is changing it is much easier to notice the pauses.

Offline princec

« JGO Spiffy Duke »

Medals: 1033
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

« Reply #2 - Posted 2002-11-02 22:23:22 »

1. Thou shalt not create objects during the rendering loop.
2. Thou shalt have but one Thread, that that Thread shall do all things.
3. Thou shalt use a hires timer or be at the Mercy of Satan and all his hacks

Any more commandments?

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

Monkey for a head

« Reply #3 - Posted 2002-11-03 08:35:43 »

4. Thou shalt be deeply cautious with string manipulation.
5. Thou shalt be sparse with collections that create iterators every time.
6. Thou shalt avoid BufferedImage.getSubimage() like the plauge.

[ - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline kenrod

Senior Newbie


« Reply #4 - Posted 2002-11-03 20:10:26 »

This depends a lot on the type of animations you're doing. For example:

1) If you're not scrolling the screen, then it's likely that not ALL of your screen is changing each frame. In PacMan, for example, only Pac and the Ghosts and maybe a pill or two change each frame - large portions of the screen (though WHICH large portions varies) remain the same.

Therefore, you can do quite a bit with 'dirty rectangles' and 'setClip', updating only those parts of the screen which absolutely need it.

2) Using Java's built-in 'sleep' or 'wait' is never going to be as good as the 'hires Timer hack' on the 'Shared Code' section of these boards, which in turn is never going to be as good as a native hi-res timer. Being able to reliably space your frames 'exactly' the same amount of time apart increases the smoothness of your animation a great deal.

3) The quality of your graphics is unlikely to affect their speed unless you're rendering them each frame, in which case...

4) ...cache as many things as you can within temporary Images, ready to be quickly 'drawImage'd to the screen. Expire your caches when images in them aren't used (to save memory)

5) Use double buffering, or triple buffering if your frame rendering time can get quite high...

6) ...and use VolatileImages (hardware accelerated) to reduce frame rendering time

Just my two cents Smiley
Offline Cedric

Innocent Bystander

Java games rock!

« Reply #5 - Posted 2002-11-03 23:02:15 »

2. Thou shalt have but one Thread, that that Thread shall do all things.

---Java newbie; beware---
2-> I'm doing an applet, and the start() function is launching two threads: the hi-res timer, and the main "events(); repaint();" loop. Is that a sin, God?

Offline princec

« JGO Spiffy Duke »

Medals: 1033
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

« Reply #6 - Posted 2002-11-04 08:01:41 »

That would be an ecuminical matter.

Cas Grin

Offline mbishop78

Senior Newbie

« Reply #7 - Posted 2002-11-04 13:43:12 »

Actually, in the Pacman example, I found that redrawing the screen was necessary.  setClip() and dirty rectangles breaks a more important commandment; creating objects.  setClip() creates a new rectangle object every time you call it and causes the code to slow down.

To avoid recreating images as much as I could, I used a couple layers:

- The maze (never changes)
- The pills (same size as the maze, like an overlay.  Obviously, this one changes when you eat a pill)
- The sprites (Don't change, but they move)

    Of course, the possibility exists that I could've used setClip() wrong and maybe there's better performance to be had, but with what I've done, it didn't turn out well and I discovered the Rectangles being created in a profiler.

Michael Bishop
Offline kenrod

Senior Newbie


« Reply #8 - Posted 2002-11-04 21:45:11 »


I too found, when I originally profiled my application, that creating Rectangles (specifically, calling Area.addOp) is pretty costly - I mentioned that a little while ago on this board.

I found since then, however (with a bit of digging) that you can easily just...

a) Create a GeneralPath object OUTSIDE the main loop
b) Reset it on every iteration (no Object creation)
c) Manually called 'lineTo', 'lineTo', 'lineTo', 'closePath' to add each rectangle to the GeneralPath
d) Check other affected actors with GeneralPath.intersects(x,y,w,h) - and remember to blit them, but don't increase the clipping rectangle for them
d) Call setClip on the finished GeneralPath
e) Blit away!

I think this is pretty optimal 'dirty rectangle' code (you don't create any objects), works well with VolatileImages, and is certainly a significant speed increase in my app.

Pages: [1]
  ignore  |  Print  

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

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

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

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

nelsongames (156 views)
2018-04-24 18:15:36

nelsongames (155 views)
2018-04-24 18:14:32

ivj94 (896 views)
2018-03-24 14:47:39

ivj94 (157 views)
2018-03-24 14:46:31

ivj94 (809 views)
2018-03-24 14:43:53

Solater (173 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!