Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (780)
Games in Android Showcase (233)
games submitted by our members
Games in WIP (857)
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  
  Tile/LargeImage speed?  (Read 5184 times)
0 Members and 1 Guest are viewing this topic.
« Posted 2011-04-13 02:49:36 »

I'm using one large map image, (think 4000x4000) and am creating a scrolling background. Should I just cut the appropriate segment for then screen out each frame and display that, or should I cut the image up into an array of tiles upon loading of the map, and display only the appropriate tiles?

I have actually done both of these, a friend assuring me a tiled system is better, but I found that the tiles slow the program way too much. I'm getting 34 fps, when drawing 15x7 (105) tiles at 128x128 pixels. Now typing this that sounds like a hell of a lot of tiles. What sort of road should I go down here? (I'm drawing onto a JPanel, contained in a JFrame, each tile is a BufferedImage)

((I found some really good threads in search, but they where old and the links (some really useful) where broken, I have no problems with the whole scrolling/fixed camera concept))
Offline Captain Awesome

Junior Devvie

Medals: 2


« Reply #1 - Posted 2011-04-13 05:00:52 »

First of all, you should take a look at active rendering on a Canvas instead of passive rendering on a JPanel
« Reply #2 - Posted 2011-04-13 13:13:58 »

I will do this now and see how it helps. Thanks
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DzzD
« Reply #3 - Posted 2011-04-13 16:31:48 »

you should not need tiles for 4000*4000 image size

...a friend assuring me a tiled system is better...
I realy depend on what you're trying to do, use tiles if you want to use multiple times the same tile, to reduce memory for example or build level based on a collection of tiles, if you just want to scroll a 4000*4000 image this is not requiered

« Reply #4 - Posted 2011-04-13 23:10:10 »

Think my stupid buffered images are getting blitted onto screen again, I've obviously cocked something up. Yeah all tiles are different, so I guess you're right.
« Reply #5 - Posted 2011-04-17 03:10:38 »

I'm following some tutorials, and this confused me.
        JFrame container = new JFrame("name");
        JPanel panel = (JPanel) container.getContentPane();

This is the constructor method for a class which extends Canvas. The JFrame and JPanel where not established before this constructor.. How can they work? I was under the impression they would no longer exist outside the method.

Also whats going on with the Panel? After googling I still dont understand the getContentPane() method. I've seen people using 'getContentPane().add(something);' - from all the books I've read, they just added things without that extra method. And finally, why is this tutorial putting a Canvas into a JPanel into a JFrame.. I find this all very confusing.

One of the problems this is causing me now is that I can no longer use getSize() to find the width or height. It always returns the initial values, and the JFrame or Panel can't be found outside this constructor.

If anyone could clear this up this up for me I'd be really thankful
Offline CaptainJester

JGO Knight

Medals: 12
Projects: 2
Exp: 14 years

Make it work; make it better.

« Reply #6 - Posted 2011-04-17 15:10:13 »

First, this is all covered in "The Java Tutorial" ( under Creating Graphical User Interfaces.

Second, you do not add components directly to a JFrame. It is built of sub containers, one of which is the content pane. The content pane is where you add your components. So if you want to draw to the entire space inside your JFrame you get the content pane and then set the layout to BorderLayout then add Canvas to the center. You can then either getContentPane().getSize() or Canvas getSize() to find out what your drawing area is.

Alternatively you can make your drawing area the size you want with the code below.
public class DrawingPanel extends JPanel {
  private Dimension size;

  public DrawingPanel(int width, int height) {
    size = new Dimension(width, height);

  public Dimension getPreferredSize() {
    return size;

  public static void main(String args[]) {
    JFrame f = new JFrame("My Game");
    f.setContentPane(new DrawingPanel(700, 700));

Since you are only drawing to the panel you could subclass any component like JComponent or Canvas to use as a drawing area.

Offline ra4king

JGO Kernel

Medals: 508
Projects: 3
Exp: 5 years

I'm the King!

« Reply #7 - Posted 2011-04-18 04:19:37 »

frame.add() is a convenience method to frame.getContentPane().add().
You can call canvas.getSize() and it will return the same values as frame.getContentPane().getSize().

« Reply #8 - Posted 2011-04-19 16:01:30 »

Aaah! I'm with you now. Thank you both. The book I had followed dedicated many chapters to Swing, I thought I understood, but had never seen mention of a content pane. I've got my Window working beautifully now. I see now the Panel is the container, and also removes the problem of the JFrame's insets.
« Reply #9 - Posted 2011-04-20 17:53:12 »

Active rendering on a canvas with volatile images, at full screen window size, 1200fps Cheesy. Finally. Thanks everyone who helped.
Pages: [1]
  ignore  |  Print  

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

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

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

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

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

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

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

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

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

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

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