libgdx working with sprite size - libgdx

I am new to libgdx and i was wondering if someone could help me with sprite size.
my screen is set to be 1280 x 720. for my desktop it looks great and the right size that i need it to be. but when i test it on my android, the sprite is way to small. How do you make screen size consistent?
to animate my sprite, i followed this. https://code.google.com/p/libgdx/wiki/SpriteAnimation
If anyone could help, that would be awesome. thanks in advance

If your app is not going to have zoom feature (which is mostly the case), you should not decide sprite sizes in terms of pixels.
Since you are going to tackle so many screen sizes and resolutions, I'd suggest a way to handle sizing of sprites in a screen size and pixel density independent way.
Assume some resolution (probably largest that you'd like to provide support for) with a suitable aspect ratio.
Size and place your sprites properly in that stage as you like.
While drawing, scale it to the actual screen resolution. (Keep in mind what to do if the aspect ratio is less or more than you had intended).
This way, you are essentially setting sizes of sprites in terms of fraction of screen size which is really convenient to understand and your sprites will look same relative sizes on all resolutions.
Hope this helps.

Related

Do 4k phone resolutions affect responsive CSS that relies on pixel width?

4k phones are still new in the market, but I suppose it's only a matter of time the tech becomes more widespread. Should I be concerned when it comes to designing responsive websites?
Is there any other unit of measure that I should use that's not px to avoid issues in the future or are my worries unfounded?
Short answer: Your worries are probably unfounded.
Longer answer: I don't know the exact specs of some 4k phones, but the interpreted CSS-resolution of smartphones these days is in most cases much lower than the physical resolution. (see this thread about device pixel ratio). 4k phones will just have a much higher device pixel ratio. So if your responsive websites work on devices like the iphone 5 or 6, they will probably also do well on 4k phones.
That said, to be at least somehow future proof, I advise to follow best practices. Some examples:
Use SVGs instead of pixel graphics where possible, so the graphics stay sharp on devices with high pixel ratio.
Work mobile first and set your breakpoints where they make logical sense, not targeting specific devices
You should use % instead of px and use em for font-size

How does a CSS width react to different screens?

When I use
.class { width: 800px; }
what does it actually mean?
When I view it on my laptop screen, it shows up exactly 800 pixels wide. When I view it on my tablet screen, it shows up as 1600 pixels wide. I am guessing because my tablet might have a higher pixel density. However, the physical (when compare side-by-side) width of the element if much smaller on the tablet than on my laptop
So, my question is: When I define a dimension in CSS to an HTML element, what is the reference? How is it computed or scaled on different displays?
The reference is a logical coordinate system that might be scaled in relation to the physical screen.
It's most common on a PC that the scale is 1:1. However as screens get larger it's becoming more common with computers that have scaled up display, which may also affect the browser.
The user can also zoom in the browser, which natually affects the scaling.
Devices like tablets and phones usually have a 2:1 scaling in the browser, sometimes even more. That means that the browser reports a smaller screen size, and everything is scaled up. This also affects the media queries, so even if the physical screen is larger, your CSS might not apply as the media query uses the screen size that the browser reports.
Also, if you don't lock the viewport using a meta tag, the mobile browser will scale the page to fit the screen, so whatever page width you specify will show up the same size.

Actual mobile resolution vs css resolution

I'm developing a mobile app using HTML5 and CSS3 using responsive design. Its quite difficult to find css resolution of mobile.
I'm using Samsugn galaxy Note2. my actual resolution is 1280 X 720. but css resolution is 640 X 360.
How can we calculate css resolution from actual resolution? and what is concept behind this?
Thanks in advance.
You can test for a certain aspect ratio using media queries, however you shouldn't be designing for specific devices or aspect ratios. Responsive design works best when you design for breakpoints as it relates to your content. This way, there's less to worry about, and your content almost always looks better on every device

AIR Project Dimensions for Retina Support

I am a bit confused with how the project dimensions I set up in Flash Develop will affect my AIR Application's appearance on Retina and non-Retina iPad displays, and how to work with Bitmaps under these circumstances.
When I run in Flash Player on PC to debug the 2048x1536 is off of my monitor it's so big. I've heard that the stage will scale with the size of the screen, and is just a reference coordinate system, but I don't understand how Bitmaps would work in these conditions... Are the Bitmaps scaled automatically all too? Does it matter whether I set my project dimensions to 2048x1546?
My hesitance to get started with this is that I will be using some spritesheets via Starling and I am confused with how to treat their dimensions in these circumstances.
Plz set me straight if you have knowledge and a minute. Appreciated.
You don't have to use 2048x1536. You can just use 1024x768 for your project dimensions. Make sure that stage.scaleMode = StageScaleMode.SHOW_ALL; but that's the default if I'm not mistaken.
Retina iPads will just show it doubled, so everything gets scaled up to 2048x1536. That means your bitmaps won't look as sharp as they can be, but vector graphics DO look sharp because Flash uses the extra resolution on a retina screen.
You could write some code to use higher-resolution bitmaps if you're on a retina display but I don't actually know of a good way of detecting retina resolution other than checking the screen dimensions. Or you could use high-resolution bitmaps that will be scaled down on non-retina screens (make sure to allow smoothing).
Also, I don't have experience with Starling myself so that may behave differently. Hope this helps a bit anyway.

Get device physical size using CSS3

I have an HTML5 page using CSS3 and SVG graphics in development. I tried using media queries to enlarge the SVG graphics when the device pixel ratio is 1.5 or 2. This works fine. Now I view my page on a small device like the Motorolla Xoom. The reported ratio is 1. This means the Xoom displays everything quite small as compared to a regular monitor. The most annoying part is that it looks great in landscape mode, but in portrait mode the full page is resized to fit in the same width. The ratio number does not change at this point.
I did try using something like 'width: 3in;' but again, it was only the correct size in landscape.
Ultimately, I'd like to use some ratio of device size vs pixel size, and scale everything this way. Is this possible?
My issue was that my graphics were never rendered again when orientation was changed. When I hit refresh again, all is coming up as expected. This was an issue that existed somewhere between my keyboard and my chair. The media queries are in fact working, I just need to rerender some stuff upon orientation change.