Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Hello World - libGDX Batch Questions  (Read 3675 times)
0 Members and 1 Guest are viewing this topic.
Offline ReBirth
« Posted 2012-01-02 02:07:50 »

I just learn about libGdx and find it's good. However I have several questions regarding their example of Hello World,

1. To change OpenGL between LWJGL and JOGL, is it really simple enough by just do this
1  
new LwjglApplication(new HelloWorld(), "Hello World", 480, 320, false);

without change anything in backend (HelloWorld class)?

2. When I did above, it works. However the window with LwjglApplication didn't allow you to resize. How to fix it?

3. When I have a class implementing ApplicationListener with custom constructor, which one called first, the constructor or create()?

4. In moving the text, why need to multiply 60 instead declare "new Vector2(60, 60)"? does it to create smooth move?
1  
textPosition.x += textDirection.x * Gdx.graphics.getDeltaTime() * 60;


5. How the "Gdx.Graphics.getDeltaTime()" calculated? If it's calculated from SpriteBatch.begin() to SpriteBatch.end() then the time taken for update game logic isn't counted right?

6. There is a commented line. I uncommented it but only see the text moved faster. What exactly it did?
1  
textPosition.add(textDirection.tmp().mul(Gdx.graphics.getDeltaTime()).mul(60));


7. Is there advantage to use Vector2 instead Point, and awt.Color instead gdx.graphics.Color?

8. Is it right to reuse BitmapFont to draw multiply Strings?

9. When I cropping texture with SpriteBatch.draw, the 0,0 position of texture relative to screen is left bottom, while cropping area (x, y, width, height or constructing TextureRegion) using left up as 0,0. Is it true? just to be sure.

11. Whatever game it is, I should implement ApplicationListener and declare SpriteBatch right? Is Gdx.graphics static?

Thanks.  Grin

Offline ra4king

JGO Kernel


Medals: 337
Projects: 2
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-01-02 09:27:36 »

1. Yup

2. You can't resize yet.

3. If you don't know the answer to this one, I don't think you are ready to start OpenGL. You need read up a bit more on Java and objects. The constructor is always called first before anything in every single class that ever exists.

4. Who says you have to?

5. getDeltaTime() returns the amount of time since the last frame, it has nothing to do with SpriteBatch.

6. That does the same thing as line 4 except it also applies it to the Y variable.

7. You cannot use java.awt.Color in libGDX. In fact, it is best to completely avoid AWT.

8. Of course! BitmapFont describes a font and you use it draw all your Strings of that specific font. You only create new BitmapFonts when creating a different font.

9. According to the JavaDocs, the (x,y) position is always the bottom left for everything.

10. O_o What happened to #10? Tongue

11. You will need SpriteBatch to render textures, fonts, etc.. so yes. All the public instance variables in Gdx are static.

Offline ReBirth
« Reply #2 - Posted 2012-01-02 13:56:51 »

I should now it'll be you who answer first. thanks Grin

3, 7 and 11 are just to be sure, how do you think I can come to this "far" anyway Cool Honestly I want to argue about number 9, but need time first to prove it one more time. I took that bottom left in mind cropping an image and it resulted wrong.

And number 10 is still on vacation.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-01-07 14:45:18 »

This is what I mean from no.9

I wan to get left up clip of an image (1)
| 1 | 2 |
| 3 | 4 |

yet the code become into
1  
2  
3  
4  
5  
6  
spriteBatch.draw(texture, 
            centerX - texture.getWidth() / 4, centerY - texture.getHeight() / 4,
            texture.getWidth()/2, texture.getHeight()/2,
            0,0,
            texture.getWidth()/2, texture.getHeight()/2,
            false, false);

Offline ra4king

JGO Kernel


Medals: 337
Projects: 2
Exp: 5 years


I'm the King!


« Reply #4 - Posted 2012-01-07 20:34:48 »

The coordinates and sizes are in texels so that might be why.

Offline ReBirth
« Reply #5 - Posted 2012-01-08 03:52:22 »

texels? actually it's not really problem, just odd when I have to have different point of view when imagining crop area LoL.

Offline pitbuller
« Reply #6 - Posted 2012-01-08 16:54:55 »

The coordinates and sizes are in texels so that might be why.

Coorndinate and sizes are just in arbitary units. Sprite batch projection matrix will tell how those map to screen. By default it's pixel perfect so then those size are 1:1 pixels but never they are texels.
Offline Nate

JGO Kernel


Medals: 145
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #7 - Posted 2012-01-08 17:36:17 »

3. If you don't know the answer to this one, I don't think you are ready to start OpenGL. You need read up a bit more on Java and objects. The constructor is always called first before anything in every single class that ever exists.

9. According to the JavaDocs, the (x,y) position is always the bottom left for everything.

Careful with absolutes. Smiley If a super class constructor calls a method that has been overridden by a subclass, the subclass' method will be called before the subclass' constructor.

The javadocs specify the origin for things. Sometimes it is lower left, sometimes it is upper left. This is part of the fun! Wink Kidding, lower left origin is typically used for coordinates, since y up makes mathematical sense. If you don't like it (I hate it personally), you can change the SpriteBatch projection matrix. the easy way to do this is to use OrthographicCamera. See the examples for this. Texture coordinates use upper left origin and y down, since that is typical for bitmaps.

Offline ReBirth
« Reply #8 - Posted 2012-01-09 03:54:55 »

Thanks for replies (and for not let me alone with ra4king Tongue)

@Nate: When I read ra4king's post, I go back to code and see it's implementing (not extending) so I can know the answer Wink I'm still on first step so changing projection matrix is a bit too much for me now. I'm just curious with people shouting this lib over threads so I want to test out.

Offline badlogicgames
« Reply #9 - Posted 2012-01-14 12:05:33 »

This is part of the fun! Wink Kidding, lower left origin is typically used for coordinates, since y up makes mathematical sense. If you don't like it (I hate it personally), you can change the SpriteBatch projection matrix. the easy way to do this is to use OrthographicCamera. See the examples for this. Texture coordinates use upper left origin and y down, since that is typical for bitmaps.

You like it and you know it!

http://www.badlogicgames.com - musings on Android and Java game development
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #10 - Posted 2012-01-16 12:01:16 »

12. Utils package has many class, what is the best choice to replace ArrayList and HashMap?
13. FPS, without any line code, is it true that lib set it to 60fps?
14. To turn an app with lwjgl backend into applet, what should I do? change LwjglApplication with LwjglApplet?
1  
2  
3  
public static void main (String[] argv) {
      new LwjglApplication(new Game(), "blah", 750, 500, false);
}

Offline ra4king

JGO Kernel


Medals: 337
Projects: 2
Exp: 5 years


I'm the King!


« Reply #11 - Posted 2012-01-16 21:04:42 »

12. Why would you want to replace those? They each do their own respective jobs quite fast already.

13. Yes.

14. Extend LwjglApplet and in the constructor call "super(new Game(),false);" as per the javadocs. Wink

Offline ReBirth
« Reply #12 - Posted 2012-01-17 05:29:56 »

Thanks! time to rock! (and come again with more questions)

Offline ReBirth
« Reply #13 - Posted 2012-01-18 01:12:17 »

Hehe question again

15. because I still have java2d concept in mind, is it bad to treat libgdx's TextureRegion as j2d's Image/BufferedImage? currently I store sprite using TextureRegion

16. Apart from above question, why I got
with this code
1  
2  
3  
Texture sprites = new Texture(Gdx.files.internal("res/sprites.png"));
textures.put("ship", new TextureRegion(sprites, 0, 0, 80, 42)); //ship correct
textures.put("missile", new TextureRegion(sprites, 0, 50, 32, 16)); //missile draw ship's part?!
looks like on second TextureRegion's constructor, the params X and Y don't work Huh the sprites were drawn correctly in place and rechecked using image editor.

17. Do you think it's killing a fly with RPG by using this lib to just create simple 2D game, just because I want nice particle effect?

Offline ra4king

JGO Kernel


Medals: 337
Projects: 2
Exp: 5 years


I'm the King!


« Reply #14 - Posted 2012-01-18 01:19:51 »

15. I don't know, I've never used TextureRegion. I always just use Texture Smiley

16. What's "textures"? A HashMap? Double check the original image to make sure you're not doing anything wrong.

17. No, libGDX is good enough for anything, even the simplest projects Smiley

For more detailed questions, you should join the #badlogic channel on APIStudios.

Offline ReBirth
« Reply #15 - Posted 2012-01-18 01:32:19 »

IRC not allowed here Cool
I did want to just use texture but I create sprite by cropping around from one large file so I use TextureRegion. And textureRegion.getTexture() give weird result.

18. Really, does libgdx only support fnt font, not ttf? many cool free fonts on ttf format. I converted one but it said "invalid font".

Offline badlogicgames
« Reply #16 - Posted 2012-01-20 16:34:55 »

12. Array and ObjectMap
15. TextureRegions work as expect. What you ran into is called texture filtering. This happens if you don't render your image at pixel perfect positions, with pixel perfect sizes.
18. ttf support is in soon via stb-truetype, it has some limitations though (chinese/arabic might be problematic, very large font sizes, e.g. 130pt, might be to large).


http://www.badlogicgames.com - musings on Android and Java game development
Offline ReBirth
« Reply #17 - Posted 2012-01-21 05:41:52 »

Thanks for replying! how about number 16? can't solve it until now...

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00

Cero (60 views)
2014-07-16 00:42:17

Riven (57 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

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

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

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

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

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

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

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!