Java-Gaming.org Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (565)
Games in Android Showcase (151)
games submitted by our members
Games in WIP (606)
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 4
1  Game Development / Newbie & Debugging Questions / Re: Best tutorials on the basics? on: 2015-03-24 16:51:21
^^^ THIS! Smiley Tutorials Point is awesome and the topics are organized very well, which makes it easy to refresh on the parts you need.
2  Game Development / Newbie & Debugging Questions / Re: Libgdx font blurring on: 2015-03-24 16:39:21
FreeTypeFonts can be any size, they don't have to be 10px or multiples of it. The comment you posted might be regarding the use of the default BitmapFont provided by LibGDX in their uiskin...which doesn't apply to what you're doing.

It appears you're generating two fonts, "textFont" and "font". Are you trying to create two different fonts with two different sizes or just one font? (As a side note, the default font size for the parameter is 16, so you are actually generating two fonts of size 16.)

Are you resizing the font(s) elsewhere? With FreeTypeFonts you don't want to resize these later, you can create the font at the specific size that you need and it will look perfect.

You also want to make sure that you set all the parameters BEFORE you generate the BitmapFont. Generating the font is the last step because it creates an actual bitmap image of all the characters in your font using whatever parameters you have set at the time. As long as you get the size right and don't try to change it later, the font should come out perfect (and the filter types don't matter as these only apply when scaling).

1  
2  
3  
4  
5  
FreeTypeFontGenerator gen = new FreeTypeFontGenerator(Gdx.files.internal("font.ttf"));
FreeTypeFontParameter params = new FreeTypeFontParameter();
params.size = 16;
BitmapFont font = gen.generateFont(params);
gen.dispose();
3  Game Development / Newbie & Debugging Questions / Re: LibGDX: Memory management concerning Textures on: 2015-03-17 15:59:00
From my understanding of LibGDX anything that has a dispose method will not be garbage collected automatically and it is necessary to use the dispose method otherwise you will have memory leaks.
4  Discussions / General Discussions / Re: where can i get better at java? on: 2015-03-09 04:40:30
Here are a few tutorial sites that might be helpful.

The beginner Java course here is free.
http://courses.caveofprogramming.com/courses/java-for-complete-beginners

Mind blowing amount of tutorials! Shocked For certain languages (such as Java) they have an IDE built in so you can type code directly into the webpage and run it to see what it does. Pretty ingenious.
http://www.tutorialspoint.com/tutorialslibrary.htm

And for tutorial videos, TheNewBoston youtube channel is really good and entertaining too.
https://www.youtube.com/user/thenewboston/playlists
5  Game Development / Newbie & Debugging Questions / Re: LibGDX Displaying Textures on: 2015-02-24 00:48:32
Stage contains a SpriteBatch and does all of the rendering through it, so it's essentially a helper class that allows things to be handled in a much simpler way. As an example, this is the render method in my Game class.

1  
2  
3  
4  
5  
6  
7  
@Override
public void render () {
   stage.act();
   Gdx.gl.glClearColor(0.10f, 0.10f, 0.08f, 1.0f);
   Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
   stage.draw();
}


That updates and renders absolutely everything in my entire app. I'm fairly new to LibGDX myself, and I started with SpriteBatch and Sprites...but after making this change I haven't looked back. It's definitely worth it and not nearly as difficult to use as it might appear at first glance.
6  Game Development / Newbie & Debugging Questions / Re: LibGDX Displaying Textures on: 2015-02-24 00:30:28
As another option, look into the LibGDX Actor and Stage classes. If you make all of your entities extend Actor, you can add them to the Stage and then updating and rendering is super simple using only stage.act() and stage.draw(). The stage goes through every actor that has been added to it and performs the action (either updating or rendering) so you can update and/or draw everything with only one line just as you want. Smiley
7  Discussions / Miscellaneous Topics / Re: Super Serious Selfie Thread. on: 2015-02-08 08:18:12
DRUMS! DRUMS! DRUMS! DRUMS! DRUMS! DRUMS! DRUMS! DRUMS! DRUMS!

8  Game Development / Newbie & Debugging Questions / Re: [LibGDX] FreeTypeFont Outline and Drop Shadow? on: 2015-02-01 05:42:35
UPDATE: rinold started a new pull and finished the outline and drop shadow feature. It has now been merged into LibGDX, I just tested it out and it works perfectly!
Here is the link: https://github.com/libgdx/libgdx/pull/2774
9  Game Development / Newbie & Debugging Questions / Re: java.awt.Point class in Android on: 2015-01-25 21:20:54
Here is the source for awt.Point, which you can copy and paste to create a new class which performs all of the same functions.
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/awt/Point.java
10  Game Development / Newbie & Debugging Questions / [SOLVED] [LibGDX] FreeTypeFont Outline and Drop Shadow? on: 2015-01-25 20:55:02
Hi all,

Does anyone happen to know if there is currently a way to add an outline and a drop shadow to a FreeTypeFont in LibGDX? I've done quite a bit of searching but there's not much information on this topic. I did find this on github which looks like it would do exactly what I want, but it doesn’t appear that it was finished.
https://github.com/libgdx/libgdx/pull/2191

I also tried posting on the LibGDX forum a few days ago but didn't get any responses.

Thanks. Smiley
11  Discussions / General Discussions / Re: Game Sound effects? on: 2015-01-03 23:02:57
Could also get the demo of your DAW of choice and use that, for instance FL Studio demo is free and the only limitation is not being able to open previously saved projects, which wouldn't be a big deal if you're just processing some one-off sound files. I believe the situation is similar for other DAWs.
Reaper is a little different as it works on the honor system, the demo version is fully functional and never expires. Definitely worth checking out, it is an awesome DAW!
http://www.reaper.fm/
12  Discussions / General Discussions / Re: Programmer jokes on: 2015-01-03 21:06:08
... and those that never get first base.
LOL Grin Grin Grin
13  Discussions / General Discussions / Re: Would it be worth porting to c++? on: 2015-01-03 20:59:37
What about using LibGDX? From what I've read, LibGDX does the performance critical stuff in C/C++. And you get the added benefits of automatically handling ports to mobile devices (Android, iOS, and Blackberry).
14  Discussions / General Discussions / Re: 2015 Game Development Goals on: 2015-01-02 23:51:14
What I did in 2014:

Exactly one year ago today, I decided to dust off my idea of creating a polyrhythmic (two or more different rhythms played simultaneously) metronome application and start working on it again. I've had the idea for about 4 years but kept running into problems that I couldn't get past, thus never made any kind of serious progress with it. After picking it up again, I had hit another wall with it...but then....I found this forum!!! Smiley And thanks to the help of the amazing members here I was able to not just move forward on my project, but get the core functionality working better than I could have ever dreamed possible. It's still a work in progress, but it is coming along extremely well. I also made the switch over from Java SE to using LibGDX (based on the recommendation of several forum members here) which has been a challenge all on its own.

Finding this forum was the best part of 2014 as I probably would have stopped working on my project yet again and put it back on the shelf. I have learned so much in just the 6 months or so that I've been here, it's crazy.

What I plan to do in 2015

Release my metronome! I'm not going to say "finish" as I think I will keep adding more features to it for as long as I can. And of course, I plan to spend lots more time here! Cheesy
15  Game Development / Newbie & Debugging Questions / Re: [LibGDX] Scene 2d Buttons click detection offcentered. on: 2014-12-31 15:47:08
Hi MrPork,

The problem might be that the ui components do not actually set their own size or position, these are set by the parent container that they are added to (in your case by the stage). To see if that is the problem, try removing the set position (and maybe the set size too) which you are doing directly on the buttons and see if the click detection works correctly.

If that fixes the problem, then you should try using Tables to layout your ui components instead of adding them directly to the stage. Here is a great tutorial from the LibGDX wiki that goes into great detail on how to do this:
https://github.com/libgdx/libgdx/wiki/Table

One more thing you may also need to do is set the viewport when resizing the window as this can also mess up the click detection. I recently had this problem and I found a thread on stackoverflow which helped me get it working:
http://stackoverflow.com/questions/23091823/incorrect-click-event-when-resize-on-libgdx
16  Game Development / Newbie & Debugging Questions / Re: LibGDX resizing window on: 2014-12-27 09:57:17
Using a specific number of pixels to set the position will not scale very well.

To illustrate the problem of "Gdx.graphics.getWidth() - 100":
- If the width was 400, then subtracting 100 would move it 1/4th of the screen width.
- If the width was 800, then subtracting 100 would move it 1/8th of the screen width.

This is why your UI gets messed up because the button's relative position on the screen changes. To fix that, try setting the position based on a percentage of the screen size. Something like:

1  
2  
3  
4  
button1X = Gdx.graphics.getWidth() * 0.1; // 10% of screen width
button2X = Gdx.graphics.getWidth() * 0.5; // 50% of screen width
button3X = Gdx.graphics.getWidth() * 0.9; // 90% of screen width
etc...


These three buttons will always be positioned at 10%, 50%, and 90% of the screen width, so no mater what the screen size is they will stay in their relative positions.

Also, I did not take into account width of the button, so depending on how you want to position your buttons you may need to take that into account also.
17  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.
18  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
19  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.
20  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
21  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
22  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
23  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)
24  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);
   }
25  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
26  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
27  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!
28  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
   }
}
29  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.
30  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
Pages: [1] 2 3 4
 
ags1 (11 views)
2015-03-31 10:55:12

theagentd (13 views)
2015-03-27 23:08:20

wxwsk8er (54 views)
2015-03-20 15:39:46

Fairy Tailz (47 views)
2015-03-15 21:52:20

Olo (29 views)
2015-03-13 17:51:59

Olo (32 views)
2015-03-13 17:50:51

Olo (39 views)
2015-03-13 17:50:16

Olo (44 views)
2015-03-13 17:47:07

ClaasJG (58 views)
2015-03-10 11:36:42

ClaasJG (42 views)
2015-03-10 11:33:01
How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

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