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  
  Tile/LargeImage speed?  (Read 2703 times)
0 Members and 1 Guest are viewing this topic.
Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



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


Medals: 2


Hi


« 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
Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



« 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

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

Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



« 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.
Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



« Reply #5 - Posted 2011-04-17 03:10:38 »

I'm following some tutorials, and this confused me.
1  
2  
3  
4  
5  
6  
7  
8  
        constructor()
        {
        JFrame container = new JFrame("name");
        JPanel panel = (JPanel) container.getContentPane();
        setSize(800,600);
        panel.add(this);
        setIgnoreRepaint(true);
        container.pack();


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" (http://download.oracle.com/javase/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.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
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));
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
  }
}


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: 345
Projects: 2
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().

Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



« 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.
Offline JESTERRRRRR

Senior Member


Medals: 7
Exp: 1 year



« 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  
 
 
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 (25 views)
2014-08-19 09:29:53

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

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

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

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

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

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

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

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

BurntPizza (67 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!