Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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  
  double buffering fail...  (Read 891 times)
0 Members and 1 Guest are viewing this topic.
Offline PRW56

Senior Newbie





« Posted 2012-07-20 18:08:05 »

Ok... I was attempting to make a 2D game, but for some odd reason double buffering isn't working. I have used it in several other programs and set it up the same way here, but here it doesn't work. In the other programs the code was shorter and only one or two Images were being loaded. This program loads all the images at launch, adds all componets, sets up double buffering, but right after this I tell it to change the canvas background color to blue, screen stays white. I tell it to run the game loop (which at this point only paints parts of the background) and it does nothing. I checked with a println() to see if the Images finished loading (they did), so i just don't know why it wont work. the code is here: http://pastebin.com/h1T4beYW

If your unwilling to look through the whole code (understandable its long), pls just tell me any Ideas you have on what might cause double buffering to not work. pls feel free to correct me if I'm doing anything horridly ineffecient or unneccesary (because I'm sure I have), Ty for any help.
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #1 - Posted 2012-07-24 22:44:24 »

lines 48 and 49.

        uniXScale = base.getWidth()/800.0;
        uniYScale = base.getHeight()/600.0;

base.getWidth() returns 0.  Your scale is f****d up

Offline PRW56

Senior Newbie





« Reply #2 - Posted 2012-07-25 00:28:29 »

THANK YOU FOR FINDING THAT!?!!!!!!  Grin Grin Grin Grin It actually paints now, THANK U SOOO MUCH!

holy crap 0_0 it does, why does base.getWidth() return 0... I have another class called GPanel that uses that method (it extends panel) and while inside GPanel (this.getWidth()) the method returns correctly, but then when its used in another class (and base.getWidth() is called) it returns 0. Why the heck does it do that?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline UprightPath
« Reply #3 - Posted 2012-07-25 16:59:35 »

It's really a simple answer as to why it does that.

Due to the way that swing and the like works, most objects either are assigned a size by what's inside of them or by the layout manager of the object that they're added to (Typically more the latter than the former, but there are objects where the former is important). You're adding the base object to a Container (JFrame in the form of DescendedRupture) that doesn't have a layout manager, and since you do not manually adjust the size of the object, it has nowhere to get its size from (So it has dimensions of 0.) Check if your other panel is being added to a container that has a layout manager assigned to it.

To fix this issue, you can replace
1  
2  
3  
4  
5  
6  
7  
DescendedRupture()
    {
        super("Descended Rupture");
        addWindowListener(this);
        setSize(806,624);
        setResizable(false);
        add(base);

with
1  
2  
3  
4  
5  
6  
7  
8  
DescendedRupture()
    {
        super("Descended Rupture");
        addWindowListener(this);
        setSize(806,624);
        setResizable(false);
        setLayoutManager(new BorderLayout());
        add(base, BorderLayout.CENTER);

Offline PRW56

Senior Newbie





« Reply #4 - Posted 2012-07-27 06:02:49 »

Descended Rupture actually extended regular frame (no swing at all) I was paranoid about the EDT so I didn't use swing at all... Also I tried adding a (1,1) grid layout to the frame (DescendedRupture) then added the base panel, base.getWidth() still returned 0, I tried setting its layout to null (just in case, even though I think it is null by default) then adding the base panel, and using base.setBounds(), no matter what I set its width and height to in setBounds, base.getWidth() still returned 0. I don't know what to make of it, but thankfully I could get around it because a canvas was on top of base, and its getWidth() and getHeight() methods worked.
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.

CogWheelz (13 views)
2014-07-30 21:08:39

Riven (21 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (29 views)
2014-07-23 21:07:15

Riven (30 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!