Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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 5109 times)
0 Members and 1 Guest are viewing this topic.
Offline Captain-Goatse

Junior Member




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 Member




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 Kernel


Medals: 361
Projects: 3
Exp: 16 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: 56
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.

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

Senior Newbie




Penfold?


« 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 »

Quote
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?

C├ędric
Offline princec

JGO Kernel


Medals: 361
Projects: 3
Exp: 16 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




Penfold?


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

Michael,

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.

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

atombrot (23 views)
2014-08-19 09:29:53

Tekkerue (22 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (57 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (29 views)
2014-08-08 02:01:56

Norakomi (36 views)
2014-08-06 19:49:38

BurntPizza (66 views)
2014-08-03 02:57:17
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!