Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (778)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
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  
  fast scroller question  (Read 2614 times)
0 Members and 1 Guest are viewing this topic.
Offline role

Junior Devvie




Java manmoth is coming!


« Posted 2003-04-03 22:32:58 »

anyone have made any efficient smooth background scroller?
i have tried three method to make a 1440 x 1216 background that could scrolled
constructed with many 32x32 tiles

first, the easiest one, i make a big image 1440 x 1216 large, put all tiles in initialize
then scroll it with g.drawImage(image, -x, -y, null);
takes 40% cpu usage with 46,850K memory consumptions

second (i used now) i create a 640 x 480 image (as large as the resolution)
and each frame, i scan and put the tiles into the images
imageGraphics.drawImage(tiles[pos], x, y, null);
then i put the image into screen g.drawImage(image, 0, 0, null);
takes 70% cpu usage with 34,680K memory consumptions

and the last, i create a 640 x 480 image  and then fill it with
grass tile (the basic tile) in initialize and put the image
g.drawImage(image, 0, 0, null);
then scan through all the tiles whereas the tile different from the grass i put it with
g.drawImage(differentTiles, x, y, null);
not implemented yet

the first takes too large memory
(every changing the background it takes about 10megs memory consumptions increment)
the second takes too many cpu time, make the fps drops.
(cos with 640 x 480 large cause the tiles drawn 640/32 = 20 for horizontal scanning and
480/20 = 15 for vertical and the result 300 tiles must be drawn every frame)
the last one is the best one, but i haven't got the point Sad
only drawing grass tiles takes 40% cpu usage with 37,932K memory consumptions
all method i observe in windows xp with windowed mode,
using volatile image (passive rendering), and
the result same as using buffer strategy (active rendering)
and the image is png files using BufferedImage

so what's the best way to do this??

thanxx in advance  Grin

Golden T Game Engine - Java2D/OpenGL Game Engine
Golden T Website | Golden T Forum
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #1 - Posted 2003-04-03 22:44:06 »

Go to http://java.dnsalias.com and download the GAGE2D package. You'll find an example scroller in there. Also, Planetation by ZParticle does high speed scrolling and was the inspiration for GAGE. Here' s the URL for that:

http://www.scottshaver2000.com/template/template.php?page=planetation_main

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Homer J Simpson

Junior Newbie





« Reply #2 - Posted 2003-04-05 21:38:39 »

Your second idea isn't as bad as it sounds. You can make it faster if you scroll your offscreen image with copyArea() and then only draw the tiles at the edges. In worst case that's only 35 tiles /frame.

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

JGO Ninja


Medals: 70


falling into the abyss of reality


« Reply #3 - Posted 2003-04-05 21:59:02 »

Quote
Your second idea isn't as bad as it sounds. You can make it faster if you scroll your offscreen image with copyArea() and then only draw the tiles at the edges. In worst case that's only 35 tiles /frame.




thats assuming you never scroll faster than cellWidth/celHeight in a single frame.
Otherwise, its gonna be more.

is the original poster using hardware accelerated images?
cos if he is, there is something wrong with his code.

on any decent pc, using hardware accelerated images and back buffer, you can draw atleast 10000 images @ 30fps.
Offline role

Junior Devvie




Java manmoth is coming!


« Reply #4 - Posted 2003-04-06 12:49:21 »

yup i have take a look at gage2d works
and i think mine is using similar technic like yours
but with different implementation  Tongue
i use only one map for the background
but i'll take a look closer, cos i haven't optimize my code

Quote

Your second idea isn't as bad as it sounds. You can make it faster if you scroll your offscreen image with copyArea() and then only draw the tiles at the edges. In worst case that's only 35 tiles /frame.  


umm how to use copyArea()? any simple code plz?

Quote

is the original poster using hardware accelerated images?
cos if he is, there is something wrong with his code.

on any decent pc, using hardware accelerated images and back buffer, you can draw atleast 10000 images @ 30fps.


i don't know is my images are accelerated or not
how to know that?
i use BufferedImage for all images and also my background back buffer
and use VolatileImage for offscreen image
what do you think should i use for back buffer? is it right using BufferedImage or should i change it to VolatileImage, what's the difference?
and one thing i can't use BufferStrategy, so i use offscreen buffer
my images is png files (24 bit color) and i create the image like this :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
      public static final Image getBufferedImage(Image image) {
            BufferedImage bufferedImage = gc.createCompatibleImage(
                  image.getWidth(null), image.getHeight(null), Transparency.OPAQUE);
            Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
            g.drawImage(image, 0, 0, null, null);
            g.dispose();

            image = null;

            return bufferedImage;
      }

Golden T Game Engine - Java2D/OpenGL Game Engine
Golden T Website | Golden T Forum
Offline Abuse

JGO Ninja


Medals: 70


falling into the abyss of reality


« Reply #5 - Posted 2003-04-06 14:44:38 »

your image creation looks fine, images created that way are elligable for acceleration.

Ideally you should use BufferStrategy for managing your back buffer, Why can't you use it?

The alternative to BufferStrategy is to use a VolatileImage as the back buffer.

There are however other complications.
If you are performing pixel operations that arn't hardware accelerated (alpha compositing, affine transforming etc etc) it is infact quicker to keep everything in system memory. (the images, and the back buffer!)
Offline role

Junior Devvie




Java manmoth is coming!


« Reply #6 - Posted 2003-04-08 14:40:30 »

ups i have solved my problem
i'm draw the map into back buffer and then
draw it to screen graphics
g.drawImage(backBuffer,0,0,null);
i forget that the screen graphics is back buffer too
then i directly draw the map into the screen
g.drawImage(tile[i+(j*horiz)], m, n, null);
and it's fast now Smiley

Golden T Game Engine - Java2D/OpenGL Game Engine
Golden T Website | Golden T Forum
Pages: [1]
  ignore  |  Print  
 
 

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

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

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

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

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

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

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

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

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

nelsongames (2312 views)
2018-04-24 18:14:32
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

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!