Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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] 2 3
1  Game Development / Newbie & Debugging Questions / Re: Starting a Java Game, Where to Start? Eventually want to be network multiplayer on: 2014-12-15 23:37:44
I still use the android folder etc. for resources. Maybe you just had something weird going on with your eclipse/gradle install.
Ah, ok. But if you don't know to use the Android/assets folder then it makes for some head scratching and research to figure out why things aren't working when it seemed like they should be.

The other problems I had were specifically related to Android and after trying several things to get Android to work, installing the Eclipse+Android bundle was the key to making it work finally. Then I had to update several things (Android libraries, maybe? Can't remember exactly, it's been a few months since my initial setup) and configure the build path inside of Eclipse to select an Android version.

It just seemed to take quite a while before I was finally all up and running.
2  Game Development / Newbie & Debugging Questions / Re: Starting a Java Game, Where to Start? Eventually want to be network multiplayer on: 2014-12-15 23:00:30
I haven't tried Android, but in my experience the libGDX project setup (including gradle, note I have no experience there either) was a painless 30 second procedure from opening the gui to having the libGDX default program running.
I believe you can use any asset folder you want for the desktop version, but if you're also building for Android then your entire project has to point to Android otherwise Android will not work. My purpose for using LibGDX was to develop for mobile devices, so that's probably why I had a more difficult setup since I was fighting with Android right from the start. LOL
3  Game Development / Newbie & Debugging Questions / Re: Starting a Java Game, Where to Start? Eventually want to be network multiplayer on: 2014-12-15 22:38:31

Yeah, I was referring to the stuff that comes after the Gradle setup. Such as not being able to get graphics to load on all platforms unless you put your graphics into the "Android/assets folder" (due to some kind of LibGDX backwards compatibility thing with Android) and then point your entire project to that folder. It's little things that you do get used to once you use LibGDX, but it takes some research to get working because it's not really intuitive. My first time setup took a while just to be able to get the stock default program that displays the LibGDX image to run. And then I ran into more problems when I tried to get Android working...but that may have just been an Eclipse issue as I ended up uninstalling Eclipse and the Android SDK I had downloaded separately and used the Eclipse+Android bundle instead.
4  Game Development / Newbie & Debugging Questions / Re: Libgdx TextField set size on: 2014-12-15 18:29:19
Hi hugotheman,

I know you got it to work, but to answer your question the UI components do not set their own sizes, the parent (in your case stage) sets the size.

Also if you're using a lot of UI components you may want to try using tables instead of adding components directly to the stage because tables give you a lot more flexibility for arranging components. Here is a great tutorial on using table layouts:
https://github.com/EsotericSoftware/tablelayout
5  Game Development / Newbie & Debugging Questions / Re: Starting a Java Game, Where to Start? Eventually want to be network multiplayer on: 2014-12-12 17:26:30
Another vote for LibGDX. If your goal is to eventually be cross platform, LibGDX handles all of that for you. From one code base you can compile to Java SE for desktop (which covers Windows, Linux, and Mac), HTML5, Android, Blackberry, and iOS (but you need a Mac for that unfortunately and I believe you may even need to be an "iOS developer" but I'm not positive on that).

LibGDX was recommended to me when I ran into some animation problems with Java SE and it was the best move I ever made.

Advanced warning...the initial setup is kind of a nightmare, but it's definitely worth it! Smiley
6  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Creating a copy of a Texture on: 2014-12-07 01:09:51
UPDATE: I was told on the LibGDX forum that textures are heavy weight objects and you can't copy them.

I was advised to work with Pixmaps, and I spent some time converting my graphics from ShapeRenderer over to Pixmap and it works great. It is so much easier to work without the FrameBuffer and the Pixmap can be disposed without affecting the Image. So this is the route I'm going now. Smiley
7  Game Development / Newbie & Debugging Questions / [SOLVED] [LibGDX] Creating a copy of a Texture on: 2014-12-05 18:46:12
Hi all,

I’m drawing graphics to an Image using ShapeRenderer and FrameBuffer and after I create the Image I dispose the ShapeRenderer and the FrameBuffer, but when I dispose the FrameBuffer the Image doesn't display. It seems like the Image is referencing the Texture located inside the FrameBuffer, so is a way to make a copy of the FrameBuffer’s Texture? Then I should be able to dispose the FrameBuffer without affecting the Image.

The Texture constructor doesn’t take another Texture, but it does take a TextureData object, so I thought I could use the getTextureData() method to create new Texture, but I just got an error (see code below). I also tried making a copy of the TextureRegion, but that did nothing as I think the new TextureRegion is also referencing the same Texture.

Here is a short example code that draws a filled rectangle. I also left in my code trying to generate a new Texture with the getTextureData() method and the error I got from it.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
package com.tekker.test;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Table;

public class Test extends ApplicationAdapter {
   Stage stage;  
   Table tableMain;
   TestBackground background;  
   
   @Override
   public void create () {
      stage = new Stage();
      Gdx.input.setInputProcessor(stage);
           
      tableMain = new Table();
      tableMain.setFillParent(true);
      stage.addActor(tableMain);
     
      background = new TestBackground(Gdx.graphics.getWidth(), 200);
      tableMain.add(background).size(background.getWidth(), background.getHeight());
   }
         
   @Override
   public void render () {
      Gdx.gl.glClearColor(0, 0, 0, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      stage.draw();
   }
   
   @Override
   public void dispose(){
      stage.dispose();
   }
}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
package com.tekker.test;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Table;

public class TestBackground extends Table {  
   Color backgroundColor = new Color(0.5f, 0.5f, 0.5f, 1.0f);
   Image backgroundImage;
   
   public TestBackground(float width, float height){
      setSize(width, height);
      createBackground();
   }
   
   private void createBackground(){
      FrameBuffer buffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
      ShapeRenderer shapeRenderer = new ShapeRenderer();
     
      buffer.begin();
      Gdx.gl.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
      Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND);
     
      shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
      shapeRenderer.rect(0f, 0f, getWidth(), getHeight(), backgroundColor, backgroundColor, backgroundColor, backgroundColor);
      shapeRenderer.end();
     
      buffer.end();
     
      Texture bufferTexture = buffer.getColorBufferTexture();
      Texture newTexture = new Texture(bufferTexture.getTextureData()); // <<< ERROR >>>
      TextureRegion region = new TextureRegion(newTexture);
      region.flip(false, true);
      backgroundImage = new Image(region);
     
      shapeRenderer.dispose();
      buffer.dispose();
   }
   
   @Override
   public void draw (Batch batch, float parentAlpha) {
      applyTransform(batch, computeTransform());
      backgroundImage.draw(batch, parentAlpha);
      resetTransform(batch);
     
      super.draw(batch, parentAlpha);
   }
}


ERROR MESSAGE:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: Pixmap already disposed
   at com.badlogic.gdx.graphics.Pixmap.getPixels(Pixmap.java:356)
   at com.badlogic.gdx.graphics.GLTexture.uploadImageData(GLTexture.java:248)
   at com.badlogic.gdx.graphics.GLTexture.uploadImageData(GLTexture.java:212)
   at com.badlogic.gdx.graphics.Texture.load(Texture.java:133)
   at com.badlogic.gdx.graphics.Texture.<init>(Texture.java:121)
   at com.tekker.test.TestBackground.createBackground(TestBackground.java:39)
   at com.tekker.test.TestBackground.<init>(TestBackground.java:21)
   at com.tekker.test.Test.create(Test.java:34)
   at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:136)
   at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
8  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Combining Images on: 2014-12-03 05:13:23
Well, never mind...I figured it out. I spent days on this problem and just within a few hours of posting on the forum I got it working. LOL

My problem was a size issue. Turns out the FrameBuffer was working but it wasn't the right size so it didn't seem like it was doing anything. But setting the size with Gdx.graphics.getWidth() and Gdx.graphics.getHeight() did the trick.

I didn't post my code before because I just just screwing around and didn't think I was even in the ballpark of getting it working. But I'll post it now in case this is useful to anyone else. Smiley

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
public class Background extends Table {
   public final float width;
   public final float height;
   
   TextureAtlas atlas;
   NinePatch ninePatch;
   Sprite color;
   Image bevel;
   Image border;
   Image combinedBackground;
   
   private final float rgbMax = 255;
   Color backgroundColor = new Color(86/rgbMax, 86/rgbMax, 86/rgbMax, 1);
   
   public Background(float width, float height){      
      this.width = width;
      this.height = height;
     
      initBackground();
   }
   
   private void initBackground(){
      // BACKGROUND COLOR
      Texture texture = new Texture("white.png");
      TextureRegion whitePixel = new TextureRegion(texture);
      color = new Sprite(whitePixel);
      color.setSize(width, height);
      color.setColor(backgroundColor);
     
      // BEVEL
      atlas = new TextureAtlas(Gdx.files.internal("background.atlas"));
      ninePatch = atlas.createPatch("background");
      bevel = new Image(ninePatch);
      bevel.setSize(width-2, height-2);
      bevel.setPosition(getX()+1, getY()+1);
     
      // BORDER
      atlas = new TextureAtlas(Gdx.files.internal("border.atlas"));
      ninePatch = atlas.createPatch("border");
      border = new Image(ninePatch);
      border.setSize(width, height);
     
      // MERGE
      mergeBackground();
   }
   
   public void mergeBackground(){
      FrameBuffer buffer = new FrameBuffer(Format.RGBA8888, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), false);
      Batch batch = new SpriteBatch();
     
      buffer.begin();
      batch.enableBlending();
      Gdx.gl.glBlendFuncSeparate(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);
      Gdx.gl.glClearColor(1, 0, 1, 0);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
     
      batch.begin();
     
      color.draw(batch);
      bevel.draw(batch, 0.3f);
      border.draw(batch, 1f);
     
      batch.end();
      buffer.end();
     
      TextureRegion combinedTexture = new TextureRegion(buffer.getColorBufferTexture());
      combinedTexture.flip(false, true);
     
      combinedBackground = new Image(combinedTexture);
   }
   
   @Override
   public void draw (Batch batch, float parentAlpha) {
      applyTransform(batch, computeTransform());
     
      combinedBackground.draw(batch, parentAlpha);
     
      resetTransform(batch);
     
      super.draw(batch, parentAlpha);
   }
9  Game Development / Newbie & Debugging Questions / [SOLVED] [LibGDX] Combining Images on: 2014-12-03 02:06:32
Hi all,

I’m working on creating scalable GUI components programmatically by drawing layers on top of each other. For example, I’m using Sprites for gradients and drawing on top of that with 9patch Images for borders and bevel effects (although I might be able to use Pixmaps to draw the images instead of using 9patch Images, but haven’t had a chance to try this out yet).

So essentially for each individual component like a button, I’m going to end up with several layers of drawing for each button...but I was wondering if there was a way to do all of the creation on startup and then merge the layers together and end up with just a single image that I can then load into all of the buttons in my program. It seems like it would be far more efficient for each button to only have to draw a single image instead of multiple images.

I think FrameBuffer might do what I need, as from what I understand it writes the output of SpriteBatch to a Texture, but I’m not totally clear on how it works and how to use it. The few examples I have been able to find used the FrameBuffer inside the render method in connection with the SpriteBatch. However, I don’t want to use it on every frame in the render method. I would like to be able to combine all of the image layers in the constructor of my GUI class after they have been created based on the device’s resolution, and then use a single image in the rest of the program.

It seems to be a difficult task getting Sprites, Images, and Pixmaps all to combine or be able to draw them to a format that I can use to create a Texture, or an Image, etc.

Is what I want to do possible? Thanks! Smiley
10  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Custom GUI Component Not Moving on: 2014-11-30 06:53:10
WOOHOO! Finally figured it out! Smiley

I was looking at the wrong source code for information on the draw() method. I thought I needed to look at Actor source since Group extends Actor...turns out Group was the one that held the valuable information:

Draw Method for Group.java:
1  
2  
3  
4  
5  
public void draw (Batch batch, float parentAlpha) {
   if (transform) applyTransform(batch, computeTransform());
   drawChildren(batch, parentAlpha);
   if (transform) resetTransform(batch);
}


So I put my drawing code in between these two lines...

1  
2  
3  
applyTransform(batch, computeTransform());
//...DRAW ACTORS AND SPRITES HERE...
resetTransform(batch);


...and now it works perfectly! This is why nothing moved when I overwrote the draw method, I needed that applyTransform method.

This information might be useful to anyone making custom LibGDX Groups. Smiley
11  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Custom GUI Component Not Moving on: 2014-11-30 03:58:20
It seems my problem is related to overriding the draw method in ButtonGradient.java. I tried commenting out the entire draw method and the bevel and black border now show up in the correct position since they are children of the Group. However, the gradient (which is a Sprite and not a child of the Group) does not get drawn at all.

Here is a screenshot after commenting out the draw method in ButtonGradient.java:


Is there a way to make the gradient as an Image instead of a Sprite?...or can I somehow draw the Sprite's gradient to an Image?...then I could simply add it to the Group as an Actor and it would be placed in the correct location like the other Images.

Also, I've seen that ShapeRenderer can be used to draw gradients, but I'm trying to avoid that as I'd have to switch between SpriteBatch and ShapeRenderer, which apparently is a costly operation.

Thanks!
12  Game Development / Newbie & Debugging Questions / [SOLVED] [LibGDX] Custom GUI Component Not Moving on: 2014-11-30 02:14:24
Hi all,

I’m trying to create some scalable GUI components programmatically instead of using png files in order to avoid pixilation when scaling or having to create different sized images for different resolutions.

I found this thread which shows how to create a gradient programmatically using a Sprite:
http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=9361

So I’m using that code to generate the gradient and then I am adding a couple additional layers on top of the gradient to create a bevel effect and a black border from 9patch images.

The only problem I’m having is that my component doesn’t move off the bottom of the screen when I add it to a Table. I have debug lines enabled on the Table and the debug lines are centered where my component is supposed to be placed. Here is a screenshot:


My component class extends Group and I have added the 9patch images to be children of the Group. Unfortunately I cannot do that with the Sprite (since it is not an Actor), but I have created an additional method that sets the position of the Sprite relative to the Group, which I call after my custom component has been added to the Table. However, putting print statements into the "setSpritePosition" method shows that the X and Y position of the Group is "0.0" even after being added to the Table.

It seems like this should work, so I’m not sure why it’s not positioning correctly. Any ideas on how to fix it would be greatly appreciated. Smiley

Here is my code:

Test.java - Main
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
package com.tekker.test;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Table;

public class Test extends ApplicationAdapter {
   Stage stage;
   SpriteBatch batch;
   static final float rgbMax = 255;
   
   Table tableMain;
   Table table;
   ButtonGradient button;
   
   @Override
   public void create () {
      stage = new Stage();
      Gdx.input.setInputProcessor(stage);
      batch = new SpriteBatch();
     
      tableMain = new Table();
      tableMain.setFillParent(true);
      tableMain.center();
      stage.addActor(tableMain);
     
      table = new Table();
      table.center();
      tableMain.add(table);
           
      button = new ButtonGradient();
      button.setSize(640, 58);
     
      table.add(button);
      table.getCell(button).size(button.getWidth(), button.getHeight());
      button.setSpritePosition();
     
      tableMain.debug();
      table.debug();
   }
   
   @Override
   public void render () {
      Gdx.gl.glClearColor(86/rgbMax, 86/rgbMax, 86/rgbMax, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      stage.draw();
   }
}


ButtonGradient.java - Custom Component
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
package com.tekker.test;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.ui.Image;

public class ButtonGradient extends Group {
   SpriteGradient gradient;
   Image bevel;
   Image border;
   NinePatch patch9;
   TextureAtlas atlas;
   
   static final float rgbMax = 255;
   static final float bevelTransparency = 0.2f;
   Color top = new Color((134/rgbMax), (134/rgbMax), (135/rgbMax), 1);
   Color bottom = new Color((0/rgbMax), (0/rgbMax), (0/rgbMax), 1);
   
   public ButtonGradient(){      
      Texture texture = new Texture("white.png");
      TextureRegion whitePixel = new TextureRegion(texture);
     
      // GRADIENT
      gradient = new SpriteGradient(whitePixel);
      gradient.setGradientColor(top, bottom, false);
     
      // BEVEL
      atlas = new TextureAtlas(Gdx.files.internal("border.atlas"));
      patch9 = atlas.createPatch("bevel");
      bevel = new Image(patch9);
     
      // BORDER
      atlas = new TextureAtlas(Gdx.files.internal("border.atlas"));
      patch9 = atlas.createPatch("border");
      border = new Image(patch9);
     
      // ADD
      addActor(bevel);
      addActor(border);
   }
   
   @Override
   public void setSize(float width, float height){
      super.setSize(width, height);
      gradient.setSize(width-2, height-2);
      bevel.setSize(width-2, height-2);
      border.setSize(width, height);
   }
   
   public void setSpritePosition(){
      gradient.setPosition(getX()+1, getY()+1);
      bevel.setPosition(getX()+1, getY()+1);
   }
   
   @Override
   public void draw(Batch batch, float parentAlpha){
      gradient.draw(batch);
      bevel.draw(batch, bevelTransparency);
      border.draw(batch, 1);
   }
}


SpriteGradient.java - Generates Gradient
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
package com.tekker.test;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;

public class SpriteGradient extends Sprite {
   public SpriteGradient(TextureRegion white) {
      setRegion(white);
   }
   
   public void setGradientColor(Color a, Color b, boolean horizontal) {
      float[] vertices = getVertices();
      float ca = a.toFloatBits();
      float cb = b.toFloatBits();
      vertices[SpriteBatch.C1] = horizontal ? ca : cb;   //bottom left
      vertices[SpriteBatch.C2] = ca;                  //top left
      vertices[SpriteBatch.C3] = horizontal ? cb : ca;   //top right
      vertices[SpriteBatch.C4] = cb;                  //bottom right
   }
}
13  Game Development / Newbie & Debugging Questions / Re: Iterating through children actors - libgdx on: 2014-11-19 22:19:57
It appears you are only sending the gameOver actor to your disableTouch method, and if that's the case then it wouldn't have access to your other actors to be able to disable touch on them.

Actors are not added to other actors, so your gameOver actor would actually not have child actors. All actors are added to the stage, so you'd want to iterate through the actors that have been added to the stage. Stage has a getActors method that returns an array of all its actors, which you could iterate through.

To detect the gameOver actor you can name all of your actors with the setName method and then in your iterator loop get the name of each actor and compare it to the name of your gameOver actor.
14  Game Development / Newbie & Debugging Questions / Re: Java rendering to android on: 2014-11-17 15:55:43
From looking at your other thread, it appears you want to draw shapes, such as lines, circles, etc, is that correct? If so, there is a ShapeRenderer class in LibGDX:
libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/glutils/ShapeRenderer.html
15  Game Development / Newbie & Debugging Questions / Re: Well i have tried but cant get it to work "Prevented Collision Detection" on: 2014-11-17 15:49:08
How about stopping right next to the wall? Were you able to get that working also?
16  Game Development / Newbie & Debugging Questions / Re: Simple alignment problem with buttons - Libgdx on: 2014-11-17 15:45:19
Awesome! Glad you got it working. Smiley

Also, if you edit your original post and put [SOLVED] (exactly like this including the brackets) at the beginning of your thread title it will put a nifty "solved" icon into the title to let others know that your question was solved and you no longer need help on the problem.
17  Game Development / Newbie & Debugging Questions / Re: Well i have tried but cant get it to work "Prevented Collision Detection" on: 2014-11-16 17:38:52
It's kind of hard to give an example that works specifically in your code since you are doing other things outside of your short snippet.

Elsewhere in your code, you determine whether you are moving left and set the "left" flag, correct? If so, then instead of setting a flag that you are moving left, put the check loop there to see if you can move left and move left if you can.

There maybe a better way to do this but just a quick idea:

Also, I’m not sure what the PlayingState.offset does exactly, so I’m removing it for now just to illustrate the idea. Wink

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
if (***LEFT key press***){
   for (int i = 0; i < speed; i++){
      // CHECK
      if(PlayingState.checkCollision(xpos - 1, ypos + height) || PlayingState.checkCollision(xpos - 1, ypos)){
         break;
      }
      // MOVE
      xpos -= 1;
   }
}
if (***RIGHT key press***){
   for (int i = 0; i < speed; i++){
      // CHECK
      if(PlayingState.checkCollision(xpos + 1, ypos + height) || PlayingState.checkCollision(xpos + 1, ypos)){
         break;
      }
      // MOVE
      xpos += 1;
   }
}


That performs your collision check and if there is no collision it updates the position by one and keeps going until it moves the position by "speed". When there is a collision it breaks out of the loop and doesn't update the position. You would do the same thing for vertical movement.
18  Game Development / Newbie & Debugging Questions / Re: Well i have tried but cant get it to work "Prevented Collision Detection" on: 2014-11-16 16:48:42
The method trollwarrior1 mentioned is too move the player inside the for loop by "1" if that spot is open. So if your speed is 10, and there is a wall "8" away, your player will be able to move by 7 (given that 8 will prevent the player from moving forward) within the loop and when it exits the loop you will be right next to the wall.

From what I gather of your code, it doesn't appear that you update the player's position by "1" each time through the loop. This would explain why you end up at different positions from the wall. So using the previous example, if your speed is 10 and there is a wall 8 away, when you check each position up to 10 and then only set motion to "false" if there there is a wall at any point in that range (which 8 would be) then you will immediately stop moving and remain 8 away from the wall.

I assume you check the "left" flag somewhere else and then update the position according to the flag? If so, then you could remove the flag and update the position right there inside of the loop. Then you could update the position by "1" instead of only being able to update position by the value of speed.
19  Game Development / Newbie & Debugging Questions / Re: Simple alignment problem with buttons - Libgdx on: 2014-11-16 16:05:30
That's interesting. By default tables should be "centered" already, but as I said, I've never worked with windows so there may be something else going on.

Are you creating table rows or anything elsewhere in your code? It kind of looks like there is an empty row above it.

As a wild guess, you could try forcing it to the top:

1  
settingsWindow.getButtonTable().center().top();


Another option maybe bypass the buttonTable and try working directly with the Window table.

1  
2  
3  
4  
settingsWindow.align(Align.center);
settingsWindow.add(toggleMusic).size(100, 100).row();
settingsWindow.add(toggleSound).size(100, 100).row();
settingsWindow.add(quitSettingsButton).size(100, 100).row();


Or another option, try ditching the window option all together and use nested tables for your layout. I'm fairly new to LibGDX myself, but nesting tables seem to be fairly easy to work with.
20  Game Development / Newbie & Debugging Questions / Re: Simple alignment problem with buttons - Libgdx on: 2014-11-15 18:51:34
Hi DavidLasry,

The window class extends table, but it also contains another table inside of it called buttonTable. So there are essentially two different tables.

Here is the source for Window.java:
https://github.com/libgdx/libgdx/blob/19e0a888394eed8b4097a264186a1c8da600ed6b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/Window.java

By using settingsWindow.add() you add buttons directly to the settingsWindow table and by using settingsWindow.getButtonTable().align() you set the alignment of the buttonTable table.

I have never worked with windows as I simply use basic tables and nest them as needed, but you should be able to add your buttons to the buttonTable like this:

1  
2  
3  
4  
settingsWindow.getButtonTable().align(Align.center);
settingsWindow.getButtonTable().add(toggleMusic).size(100, 100).row();
settingsWindow.getButtonTable().add(toggleSound).size(100, 100).row();
settingsWindow.getButtonTable().add(quitSettingsButton).size(100, 100).row();


Now you will be aligning the same table that you add your buttons too.
21  Game Development / Newbie & Debugging Questions / Re: I'm desperate on: 2014-10-10 16:53:02
Since you are already familiar with Java, then try finding some simple game video tutorials (like pacman) that walk you through the entire process from start to finish and follow along line by line. This will get you familiar with the concepts that go into a game.

From there, start making very small tests where you implement just one aspect of a game at a time.

Some possible examples:
- Create a simple game loop that simply paints a circle.
- Next make the circle move across the screen from one end to the other.
- Next make the circle detect the edge of the screen and send it back the other direction when it hits an edge.
- Then get input from the user and make the circle move with the arrow keys instead of moving on its own.
Etc.

In just that little bit you've covered a game loop, updating, painting, basic collision detection, user input, etc all key components to creating games.

So instead of focusing on the exhausting task of "making a game" (OMG!!! Shocked) you can think about creating smaller individual puzzles for yourself that you have to solve. Focusing on these simpler tasks will also allow you to search for specific topics and find better explanations and tutorials related to what you want to know. For example, searching for "how to move an object with arrow keys in java" will likely provide much more useful results than "how to make a game in java", which is an extremely broad topic.

Finally, once you start working on more complex games, it's a very good idea to keep creating "side-projects" regularly where you work out a particular task in isolation without trying to figure it out inside of your more complex game. Once you know exactly how it works in isolation, then incorporating it into your actual game will be a whole lot easier.
22  Game Development / Newbie & Debugging Questions / Re: LibGDX Loading Audio File on: 2014-10-10 16:04:13
Just a quick update: I was able to read in all the bytes from the wav file with the LibGDX FileHandle and then maneuver through the header bytes to extract just the audio bytes (using the document from standford I posted before). It works perfectly on both desktop and android, so I can now officially mark this problem solved!

Thanks again for all the help everyone! Smiley
23  Game Development / Newbie & Debugging Questions / Re: I'm desperate on: 2014-10-09 08:05:11
First off, as a semi-noobie to this forum myself, let me just say that you can expect to be treated with utmost respect here on this forum! Smiley So you need not worry about hate mail or having people treat you in an uncivilized manner for asking beginner questions. This place is beyond awesome!

Second, as has been mentioned before, you might be better served getting familiar with Java before diving head first into a game. You say you have a hard time following tutorial videos, but maybe you just need to find the right ones?

TheNewBoston on youtube is awesome for beginners because he assumes you know absolutely nothing and then builds from the ground up. Bucky is a little on the goofy side which makes the videos fun. He does have a tendency to mess up typing/spelling (something he constantly jokes about himself), so be weary of that. lol He has lots of videos on Java and some on game dev.
http://www.youtube.com/user/thenewboston/playlists

This is another series of Java videos that is highly recommended here on this forum. He sells courses on his site, but the intro to Java course is totally free:
http://courses.caveofprogramming.com/course/java-for-complete-beginners/

Once you have a good grasp of the core language, then expanding into more complex gaming topics and graphics will be a lot easier.

And finally, when you do get into developing games, it helped me a lot to simply follow along with tutorials showing how to make simple games like pacman. Even though the app I'm working on has absolutely nothing to do with pacman this really helped in understanding gaming concepts like game loops, painting, sprite animation, etc. then you can just keep getting more and more in depth and complex from there.

Hope that helps.
24  Game Development / Newbie & Debugging Questions / Re: LibGDX Loading Audio File on: 2014-10-09 07:33:24
Thanks BurntPizza!

I'm also hoping to support iOS devices (assuming the LibGDX conversion process works well), so am I safe in assuming that a 3rd party library like musicg wouldn't be able to be converted to iOS via LibGDX?

If so, then would it be a good idea to just read the bytes straight from the wav file (since wav files aren't compressed) using a byte reader for files that android also supports (have to look more into this as apparently android doesn't support java.nio.Files either....go figure! Roll Eyes)? This gives a good description of the layout inside the wav file:
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
25  Game Development / Newbie & Debugging Questions / Re: [SOLVED] LibGDX Loading Audio File on: 2014-10-07 07:22:55
Well....after having it work so fantastically on my desktop I tried running it on my Android phone and it crashed and burned!

After some debugging and then some googling I found that Android does not support Java's AudioInputStream! Grrrrrr! That sucks! Huh

I didn't see any kind of LibGDX equivalent to AudioInputStream, so am I going to have to code this separately for each device (android, iOS, blackberry, ect) using native code or is there something else I can do? Thanks!
26  Game Development / Newbie & Debugging Questions / Re: [SOLVED] LibGDX Loading Audio File on: 2014-10-07 02:04:48
Oh wow...that's interesting. Thanks for the heads up BurntPizza, I definitely won't be using asDoubleBuffer() then. Wink
27  Game Development / Newbie & Debugging Questions / Re: [SOLVED] LibGDX Loading Audio File on: 2014-10-07 01:14:50
Niiiiice that is slick! Smiley Thanks BurntPizza, I will give that a go.

Also, it looks like ByteBuffer also has asDoubleBuffer(), so I may even be able to go directly from the byte buffer to the double buffer and bypass the shorts all together:

ByteBuffer.wrap(data).asDoubleBuffer();
28  Game Development / Newbie & Debugging Questions / Re: LibGDX Loading Audio File on: 2014-10-07 00:59:15
Thanks BurntPizza, that was it! Smiley Divided by Short.MAX_VALUE and it is working perfectly now!

Problem officially solved! Thanks everyone, you all are beyond amazing!! Smiley
29  Game Development / Newbie & Debugging Questions / Re: LibGDX Loading Audio File on: 2014-10-07 00:29:09
Thanks philfrei, bypassing the InputStream and getting a File from the LibGDX FileHandle did the trick. Smiley

One last problem I'm having now is when the file plays it just plays a blast of white noise, so I think I'm converting the data from the wav file incorrectly.

The AudioInputStream reads bytes from file and I'm trying to store that into an array of doubles. To do the conversion, I'm storing two bytes into a ByteBuffer and then getting a short back out since a short is 2 bytes, and then I'm casting that to a double to put into the array...it seems like this should work, but maybe this is the wrong way to convert it?

I've also tried reversing the order of putting the bytes into the ByteBuffer (in case I had them backwards), but no change.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
   private void readAudioFile(){
      FileHandle fileHandle = Gdx.files.internal("click.wav");        
      File file = fileHandle.file();
      int byteLength = (int)fileHandle.length();
     
      byte[] audioFileBytes = new byte[byteLength];
      audioFile = new double[(byteLength/2)];
     
      try {
         audioInputStream = AudioSystem.getAudioInputStream(file);
         audioInputStream.read(audioFileBytes);
      } catch (UnsupportedAudioFileException e) { e.printStackTrace(); }
        catch (IOException e) { e.printStackTrace(); }
     
      int j=0;
      for (int i=0; i<audioFileBytes.length;){
         audioFile[j++] = bytesToDouble(audioFileBytes[i++], audioFileBytes[i++]);
      }
   }
   
   public double bytesToDouble(byte firstByte, byte secondByte){
      ByteBuffer bb = ByteBuffer.allocate(2);
      bb.order(ByteOrder.LITTLE_ENDIAN);
      bb.put(firstByte);
      bb.put(secondByte);
      return (double)bb.getShort(0);
   }
30  Game Development / Newbie & Debugging Questions / Re: LibGDX Loading Audio File on: 2014-10-06 00:19:06
Hi kingroka123, thanks for the response.

That method works and it plays the sound file, so the Gdx.files.internal("click.wav") method is indeed working. I thought maybe that was the problem since the handle's status was "null" when I debugged and stepped through the program.

For my program I do need to be able to access the audio data from the wav/mp3 file and store the data in an array. I've looked at the LibGDX audio API but didn't see a way to load an audio file from disk and access the data directly. Currently my program generates its own sounds internally (just simple sine wave tones for testing) and stores them in double[]'s, so now I'm trying to load a file from disk and get it in the same format.

I know I can do that with Java's AudioInputStream, but it doesn't seem to work using the LibGDX file handle. Any ideas?

Thanks again!
Pages: [1] 2 3
 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (29 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (98 views)
2014-12-08 04:46:31

JscottyBieshaar (58 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (76 views)
2014-11-29 21:32:03

toopeicgaming1999 (137 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (37 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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