Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: how to add KeyListener to JPanel from another class on: 2013-04-15 14:44:13
if i understand correctly, you want to add an instance of Control as KeyListener to an instance of Screen?
that would be
1  
theScreenInstance.addKeyListener(theControlInstance);
2  Game Development / Newbie & Debugging Questions / Re: Best way to play audio in java on: 2013-04-09 14:35:14
for compressed audio http://code.google.com/p/jdogg/

create one thread for audio-playback and mix all audio streams into the SourceDataLine.
3  Game Development / Newbie & Debugging Questions / Re: Having trouble loading a brick level on: 2013-04-09 06:52:53
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
public class Level {
   int[][] board;
   
   public Level() {
      board = new int[][] {
            {1,1,1,1,1,1,1,1,1,1,1,1,},
            {1,1,1,1,1,1,1,1,1,1,1,1,},
            {1,1,1,1,1,1,1,1,1,1,1,1,},
            {1,1,1,1,1,1,1,1,1,1,1,1,},
            {1,1,1,1,1,1,1,1,1,1,1,1,},
            {1,1,1,1,1,1,1,1,1,1,1,1,},
            {1,1,1,1,1,1,1,1,1,1,1,1,},
            {1,1,1,1,1,1,1,1,1,1,1,1,},
            {1,1,1,1,1,1,1,1,1,1,1,1,},
            {1,1,1,1,1,1,1,1,1,1,1,1,},
            {1,1,1,1,1,1,1,1,1,1,1,1,},
            {1,1,1,1,1,1,1,1,1,1,1,1,}
      };
   }
}
4  Game Development / Newbie & Debugging Questions / Re: Having trouble loading a brick level on: 2013-04-06 03:02:14
you have 2 x int[][] board. one is a class member, the other one is a local variable in the constructor.
you only fill the local variable, but then you use the class member, which will only contain 0's.




5  Java Game APIs & Engines / Java Sound & OpenAL / Re: Need a really simple library for playing sounds and music? Try TinySound. on: 2013-04-05 23:43:29
the methods with the streamFromFile flag DO stream, you can see in in the source code Wink
the temp file (which is used for streaming) should be in your temp folder, it gets created with

1  
temp = File.createTempFile("tiny", "sound")

6  Java Game APIs & Engines / Java Sound & OpenAL / Re: Need a really simple library for playing sounds and music? Try TinySound. on: 2013-04-05 23:27:19
np philfrei Smiley

FYI https://github.com/finnkuusisto/TinySound
7  Java Game APIs & Engines / Java Sound & OpenAL / Re: Need a really simple library for playing sounds and music? Try TinySound. on: 2013-04-05 23:01:52
I'm starting to think that there is something in the rest of my program that is causing the memory to grow or something.

i think so. i tried it with a 500 KB wav file and after the music is loaded it does not grow more than ~1 KB per 20 seconds, and these are from my debug strings...
8  Java Game APIs & Engines / Java Sound & OpenAL / Re: Need a really simple library for playing sounds and music? Try TinySound. on: 2013-04-05 22:53:05
does the memory usage grow, or is it just as before?
that's what i was pointing out in the first post: TinySound loads the _whole_ audio data and stores it in a temp file, from which it then streams.

i tried the code now. you must call music.rewind() before music.play() to replay it.

the only memory it allocates when replaying is in setPosition() which gets called from rewind(), coz this closes the stream and reopens it. (i don't know why it is implemented this way, since it creates the temp file, which i thought gets created to have a resetable input stream...Huh)
9  Java Game APIs & Engines / Java Sound & OpenAL / Re: Need a really simple library for playing sounds and music? Try TinySound. on: 2013-04-05 22:31:38
when you call play(false) twice, does it play the sound twice?

10  Java Game APIs & Engines / Java Sound & OpenAL / Re: Need a really simple library for playing sounds and music? Try TinySound. on: 2013-04-05 21:31:18
1  
TinySound.loadMusic(URL url, boolean streamFromFile)


this first reads the _whole_ audio data from the stream into a temp buffer...
writes the temp buffer to a temp file...
streams from this file...

i'd rearrange the code to something like this
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public class AudioHandler
{
    Music music;
    public AudioHandler()
    {
        TinySound.init();
        music = TinySound.loadMusic(...);
    }
   
    public void play()
    {
        music.play(...);
    }
}



11  Java Game APIs & Engines / OpenGL Development / Re: Why is/are my VBO(s) so slow? on: 2013-03-27 10:51:57
have a look at gDEBugger http://www.gremedy.com/

1  
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, interleave, GL15.GL_STATIC_READ);

the GL_STATIC_READ _might_ cause the memory manager to use AGP or system memory, try GL_STATIC_DRAW.
page 11, https://developer.nvidia.com/sites/default/files/akamai/gamedev/docs/Using-VBOs.pdf?download=1

12  Game Development / Newbie & Debugging Questions / Re: Texture coordinate problem with GLSL on: 2013-03-26 07:33:48
you are welcome  Smiley
yeah, i started to understand VAOs with this tutorial. really nice to work with VAOs...
13  Game Development / Newbie & Debugging Questions / Re: Texture coordinate problem with GLSL on: 2013-03-26 07:24:51
http://www.swiftless.com/tutorials/opengl4/4-opengl-4-vao.html
14  Game Development / Newbie & Debugging Questions / Re: Texture coordinate problem with GLSL on: 2013-03-26 03:49:00
hi,
i am working on the same stuff atm. i found the 2nd answer at http://gamedev.stackexchange.com/questions/42145/passing-multiple-vertex-attributes-in-glsl-130 to be quite helpfull.

i am far away from a GL guru, but here are some thoughts. please correct me if i am wrong...

the glGetAttribLocation() and glGetUniformLocation() calls could (or should) be done only once and stored after the program got linked.

if you use "location" in the shaders then the glGetAttribLocation() calls can be removed and instead hard-coded indexes could be used.

with VAOs the VBO bindings could be done only once when the VAO gets created.

i hope this makes sense...?
15  Game Development / Shared Code / Re: 2D Matrix Equivalent of ArrayList on: 2013-03-26 02:50:33
there is a bug in put()

should be:
1  
2  
3  
4  
5  
6  
7  
8  
   public void put(T object, int x, int y){
      if(x < 0 || y < 0)
         throw new IllegalArgumentException("X and Y must be positive");
      if(x >= data.length  || y >= data[0].length){
         expand(x + 1,y + 1);
      }
      data[x][y] = object;
   }



and isValidPosition

should be:
1  
2  
3  
   public boolean isValidPosition(int x, int y){
      return (x >= 0 && x < data.length && y >= 0 && y < data[0].length);
   }

or the method should be called isInValidPosition and the > should be >= then (like in put())

for optimization you could store in the outer loops a reference to
1  
array[x]
and use this in the inner loops, but of course it depends on your matrix size and usage frequency if that makes sense and since you are using getters and setters in the loops i think it's not very time critical code Wink

further, in the expand() method i would copy the area of Math.min(newWidth, getWidth()) and Math.min(newHeight, getHeight()) and remove the try catch. this way you can handle the case when newWidth > getWidth but newHeight < getHeight() for example.

in getSection() you could replace the inner loop with a System.arraycopy()

and so on Wink

EDIT: damn how can i use the array index operator in normal text without getting this list thing?
16  Game Development / Newbie & Debugging Questions / Re: Values of a float not updating in classes besides the one it is defined in :( on: 2013-03-24 18:58:15
only 2 possible reasons for that:

1) the values get reset between changing and getting

2) you are changing the values in one instance and getting them from another instance
print out the instance address in the key handler method and in the getters. i'm pretty sure they are not equal...
17  Game Development / Newbie & Debugging Questions / Re: NullPointer exception? on: 2013-03-23 07:18:10
Quote from: kutucuk
And by using "if", I basicly skipped these stuff and thus it had the chance to create the image and thus, offScreen object.

Right? Cheesy
right. in the first paint() the if statement protected you from the NPE, and in further paint() you had the offscreen already created.

Quote from: kutucuk
And, I could escape this problem by simply drawing everything on a JPanel and then adding it to the JFrame, right?
almost right Wink
you would first create a subclass of JPanel and override the paint(Graphics g) method.
(in this method you use the param "g" to draw onto the JPanel.)
then add an instance of your JPanel subclass to the JFrame and then call the JFrame's setVisible(true).
18  Game Development / Newbie & Debugging Questions / Re: NullPointer exception? on: 2013-03-23 03:24:04
no, because then you would have had the NullPointerException in the line

1  
offScreen = buffer.getGraphics();

because buffer would have been null.

the problem in the original code was, like Sparky83 said, that you called setVisible(true) before
1  
2  
buffer = createImage(aWidth, aHeight); // Creating an image in the same size as JFrame
offScreen = buffer.getGraphics(); // It is initialized man...


in the original code the order was:
setVisible()
repaint() < this was called from the AWT thread "in the background" because you called setVisible()
buffer = createImage()
...

btw, you create an offscreen that has the size of the frame including the frame border. so if you paint to the offscreen with
1  
2  
offScreen.setColor(Color.red);
offScreen.fillRect(buffer.getWidth() - 1, buffer.getHeight() - 1, 1, 1);

you will not see the red pixel.
you could call setUndecorated(true) before setVisible(true), which will give you a frame without border.

or, even better, add an other Component to the Frame's ContentPane (or replace the ContentPane) and create your offscreen in the doLayout() method of that Component.
this way you can handle when the Frame gets resized and create an offscreen that always has the same size as the ContentPane.

19  Java Game APIs & Engines / OpenGL Development / Re: [LWJGL] isKeyReleased() method? on: 2013-03-14 23:42:26
Really, are you really going to do this? The brushSize variable does not increase to 5, I have tested it. Seeing as LESS THAN OR EQUAL TO means that you can only increase the number up to 4. Second, you don't know what the rest of my code looks like, don't say I don't know how to code. Third, my else statement does work. I use it for other things to besides the brushSize.

ok, relax,  i try again...

your code says: if brushSize is less than or equal to 4 then add 1.
so what happens if it is equal to 4? it will be increased to 5!

and you did not see it because you print it before it is increased to 5.

20  Java Game APIs & Engines / OpenGL Development / Re: [LWJGL] isKeyReleased() method? on: 2013-03-14 21:10:05
Quote
First, I do need less than or equal to four

thats why you have to change the '<=' to '<' otherwise you increment brushSize to 5!

Quote
Second, there can be an else

sure, there can be an else but it makes no sense here.

Quote
I do not need to print after the change as honestly, it was for debugging purposes and it will only print out the incorrect thing once.

well, i just thought that if you print before the change, you could -and obviously you did- not see that brushSize is 5.

Quote
I think I know how to use classes and objects by now.

the code you posted does not look as if you know, sorry.

Quote
Please, don't just post without thinking...

Please, don't just post without thinking...  Wink
21  Java Game APIs & Engines / OpenGL Development / Re: [LWJGL] isKeyReleased() method? on: 2013-03-14 02:23:30
without more code it's hard to say, but i guess what you want is:

1  
2  
3  
4  
if (brushSize < 4) { // < 4 (not <= 4)                          
   brushSize += 1;
    System.out.println(brushSize); // print after the change
} // no else

either you are accessing the wrong instance or you do not set the new instance's brushSize member coz of something like
1  
2  
3  
4  
5  
brushSize = brushSize;
// instead of
this.brushSize = brushSize;
// or
brushSize = other.brushSize;
in a copy constructor or clone method.
22  Game Development / Newbie & Debugging Questions / Re: Stop frozen method on: 2013-03-13 03:27:49
hi,

try this...

1  
2  
3  
URLConnection urlconnection = file.openConnection();
urlconnection.setReadTimeout(5000);
long size = urlconnection.getContentLength();


URLConnection's read-timeout is set to 0 by default, which means 'wait forever'.
23  Games Center / WIP games, tools & toy projects / Re: Isotröma (Tesseract 2) on: 2013-02-26 18:43:11
looks really nice!
terrain4 runs smooth at 62 fps  Smiley
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (46 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (36 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (52 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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!