Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  LibGDX error : Camera setup  (Read 927 times)
0 Members and 1 Guest are viewing this topic.
Offline SHC
« Posted 2013-08-02 01:21:09 »

I'm trying to write a simple app which demonstrates how my packed fonts can be rendered in LibGDX. I asked it to render at (0, 0) and it starts rendering at bottom-down corner. I've wanted it at up-left corner so from the wiki, I used the following in the
create()
method.

1  
2  
cam = new OrthographicCamera();
cam.setToOrtho(true, 800, 600);

But it still renders in the bottom-left corner. What should I do?

Offline SHC
« Reply #1 - Posted 2013-08-02 02:02:17 »

I'm rendering the texture like this. Does it matter?

1  
2  
3  
4  
5  
batch.begin();
{
    batch.draw(tex, x, y);
}
batch.end();

Offline ReBirth
« Reply #2 - Posted 2013-08-02 02:12:35 »

I never use setToOrtho method, just pass those value to constructor.

Btw I don't really clear the problem. So you want to move the origin back to Java2D (up-left)?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SHC
« Reply #3 - Posted 2013-08-02 02:13:48 »

@Rebirth

Yes. I just want to go to Java2D origin.

Offline ReBirth
« Reply #4 - Posted 2013-08-02 02:19:17 »

I never do this. I just recalculate the Y with height subtraction since it's safer to do that.

My idea:
1. translate camera x,y
2. use negative value for height (Huh)

Offline SHC
« Reply #5 - Posted 2013-08-02 02:30:26 »

Could you give me some clarity? An example? I don't understand.

I just want to draw a texture on top of the screen. And leave others at the default position.

Offline drabla

Junior Duke


Medals: 5



« Reply #6 - Posted 2013-08-02 02:54:57 »

Have you added:
1  
2  
3  
batch.setProjectionMatrix(cam.combined);
batch.begin();
...
?
Offline SHC
« Reply #7 - Posted 2013-08-02 04:29:40 »

@drabla

Adding that made the characters upside down.

Offline ReBirth
« Reply #8 - Posted 2013-08-02 11:38:05 »

I am not on Eclipse right now,
1  
cam = new OrthographicCamera(800, -600, true);

Dunno what will happen though Roll Eyes

Offline SHC
« Reply #9 - Posted 2013-08-02 11:54:12 »

@Rebirth,

The same. No change at all. I've also tried calling the update and apply methods. But no use.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #10 - Posted 2013-08-02 12:05:02 »

After changing your camera, like this:
http://stackoverflow.com/a/7751183

You need to change your batch's projection matrix:
batch.setProjectionMatrix(camera.combined);
... render sprites ...


Offline Cero
« Reply #11 - Posted 2013-08-02 13:17:38 »

and yes the characters will be upside down.
if you use ydown you have to flip your textures as well

Offline SHC
« Reply #12 - Posted 2013-08-02 13:20:17 »

@Cero

Can you say how to flip them?

Offline drabla

Junior Duke


Medals: 5



« Reply #13 - Posted 2013-08-02 13:22:01 »

1  
sprite.flip(false, true);


or do it in your graphical program.
Offline SHC
« Reply #14 - Posted 2013-08-02 13:23:15 »

I can't create a new sprite for each texture. Can we directly flip the texture?

Offline davedes
« Reply #15 - Posted 2013-08-02 13:25:08 »

Don't flip texture; that would involve re-arranging byte data. Instead, flip the texture region that encapsulates your texture. You should learn about textures and texture regions here:
https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Textures

Generally speaking you shouldn't be using Texture except for low-level purposes, or to hold a single texture atlas. Instead it is better to use Sprite (which caches vertex data) or TextureRegion.

Offline drabla

Junior Duke


Medals: 5



« Reply #16 - Posted 2013-08-02 13:27:04 »

If you are loading your Sprites through a TextureAtlas:    //  (this is good practice right? Wink )

TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/pack.pack"), true);

The last boolean will flip the y in your whole textureatlas. C.f.: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/TextureAtlas.html#TextureAtlas(com.badlogic.gdx.files.FileHandle, boolean)
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.

Longarmx (35 views)
2014-10-17 03:59:02

Norakomi (27 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (27 views)
2014-10-15 16:18:58

TehJavaDev (52 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (42 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (76 views)
2014-10-11 22:30:10
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!