Changing window size in code.

Anything libgdx related goes here!

Re: Changing window size in code.

Postby mmtbb » Thu Dec 23, 2010 10:32 pm

Thanks Nates.
mmtbb
 
Posts: 135
Joined: Thu Nov 11, 2010 6:56 pm

Re: Changing window size in code.

Postby mmtbb » Fri Dec 24, 2010 7:39 pm

I have hard coded all the textures and it seemed to be working good. However, it seems to be scaling each texture individually. Thus, if a texture has a width of 110, and the scaled size is 70.123, it will make the texture 70 and cut a pixel off.

Example: I have two textures, a purple rectangle and a black rectangle. I draw them on top of each other. At 100% it looks like this:

Untitled-3.png
Untitled-3.png (329 Bytes) Viewed 3811 times


Now if I scale the image for a smaller screen, it draws it like this (notice the purple texture lost a pixel and you can see the green backround under it):

Untitled-4.png
Untitled-4.png (276 Bytes) Viewed 3811 times



I know I can add a line of pixels on the original image to account for this, but Is there a way to have the entire screen scaled, instead of each texture individually?
mmtbb
 
Posts: 135
Joined: Thu Nov 11, 2010 6:56 pm

Re: Changing window size in code.

Postby mzechner » Fri Dec 24, 2010 10:11 pm

How do you scale your rectangles?
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: Changing window size in code.

Postby mmtbb » Fri Dec 24, 2010 10:52 pm

In the code that puts coordinates in the upper left, I just modified it:

Code: Select all
Matrix4 transform = new Matrix4();
transform.setToTranslation(0, Gdx.graphics.getHeight(), 0);
transform.mul(new Matrix4().setToScaling(Gdx.graphics.getWidth()/(float)g_Width, Gdx.graphics.getHeight()/(float)(-1*g_Height), 1f));
spriteBatch.setTransformMatrix(transform);


where g_Width = 480 and g_Height = 800 (the original size of my game). This scales everything to the resolution of the android device.

I have also tried:

Code: Select all
spriteBatch.getProjectionMatrix().setToOrtho(0, (float)g_Width, (float)g_Height, 0, 0, 1);


Which gives the same results.
mmtbb
 
Posts: 135
Joined: Thu Nov 11, 2010 6:56 pm

Re: Changing window size in code.

Postby mmtbb » Thu Dec 30, 2010 4:23 am

On a similar note. Does performance take a hit if I hard code the size, then scale down the size with either of the scaling codes posted above? In otherwords, is the cpu working a lot harder frame by frame to reduce scale the size of everything?
mmtbb
 
Posts: 135
Joined: Thu Nov 11, 2010 6:56 pm

Previous

Return to Libgdx

Who is online

Users browsing this forum: diazndc, MSN [Bot] and 1 guest