Using TileMap in cocos2dx - cocos2d-x

I am creating a CrossPlatform ( iOS & android ) using Cocos2dX.I have a single TileMap
Details:
Rows & column : 8 X 11
TileSize Each : 192
TileMapSize : 1728 X 2304
TileSheet : tileMap.jpg ( 964 X 1736)
I scale down the TileMap accordingly for iOS devices(e.g.:iPad - 0.44) to fit in the window and used Resolution Policy:kResolutionFixedHeight. It works as i expected the height stretches according to device height.But as expected their is a loss in width.
So My question is am i going in right direct using single TileMap for all devices or should i use three or more TileMaps.
If then please tell me the Tile Map size used for
iPad,iPhone,iPhone 5,retina or anything else to move Forward
Thanks in Advance

That's a Massive TileMap, as the comment under your question :)
When I ported a game to Android, I used 3 TileMaps. All maps 15 x 10 tiles, with 32, 64 and 128 pixel tiles.
On App start up, I have:
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CGameManager::Instance()->SetSuffixAndScaleFactor(visibleSize);
Where SetSuffixAndScaleFactor() is in my CGameManager class. This looks at the screen size,and depending on the resolution sets
The tileMaps to be used
the ScaleFactor required
Beware of different X and Y scalings - otherwise your tiles will appear stretched.
For the iPad / iPhone....
iPhone is the same as the android tilemaps - 960 x 640 or 480 x 320.
For the iPhone 5 I add a small frame, as with all android devices that don't have a 960 x 640 aspect ratio.
I made a special set for the iPad with 15 x 12 tiles, again one for each resolution.

Related

Preffered viewPort to dealing with textButton libgdx

i work with a new game , i have create 2 camera one camera for real world and another (GUI) camera for a static resolution (800 x 480)
private void init () {
camera = new OrthographicCamera(16,9);
camera.position.set(0, 0, 0);
camera.update();
cameraGUI = new OrthographicCamera(800,480);
cameraGUI.position.set(0, 0, 0);
cameraGUI.update();
And i want to use a textButton in my game , so i've create a new stage using a new fitViewPort
fitViewPort=new FitViewport(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
gameController.stage=new Stage(fitViewPort);
then i create my textButtons using my bitmap font and i try it on the Desktop , and it's great
desktop
but when i try another device , the position is not the same
Tablet
then i think for using the cameraGui Width and height for my view port , the font is very bad stretched
any help please :(
Don't create a special camera for GUI, because viewport already has a camera.
Make your viewport width and height fixed, in your case:
fitViewPort = new FitViewport(800, 480);
gameController.stage = new Stage(fitViewPort);
And then just add actors to stage and draw it just by calling method
gameController.stage.draw();
Note: Remember to add gameController.stage.getViewport().update(width, height); in your resize method.
Edit: Using small fixed viewport (800x480 is small) will cause scaling, that is why the font is stretched. For example if you run a 800x480 layout on 1920x1080 display it will be scaled by 225%.
What you can do is generate a font with big size and the set scale to its data fe. bitmapFont20.getData().setScale(0.5F); (in this case font is generated by FreeTypeFontGenerator with size 40). Using this trick you will be able to get a great results. The proof is below. It is viewport of 640x360F * (float) Gdx.graphics.getHeight() / (float) Gdx.graphics.getWidth() scaled to 1920x1080. Font is generated with size 72 and then data scale is set to 0.5F
Here is the same text, but without modified data scale.

How to draw a 1cm wide square in html5 canvas?

Drawing a black square on white background is easy using canvas API.
Nevertheless, a lot of devices have different window.devicePixelRatio values, but even if they do, the physical size of a pixel might differ.
Can the needed scaling factor be retrieved using HTML5 APIs?
If not, how it can be determined using more low level host OS APIs (lets say, linux, windows, android, ios, osx ...
There is really no way to know how large 1 cm would be on the screen. The browser has just a generic concept of the DPI for the screen which is typically 96 DPI. However, you could be sitting by a 19" or a 32" monitor - the browser wouldn't know and 1 cm would be very different in size between them assuming they are defined by the same number of pixels.
You will have to manually calibrate for each monitor by physically measuring the size and then convert this to number of pixels per cm or inch when it comes to browsers.
Old-tech method
I made this simple tool (see below) to do basic calibration - it won't give you a scientifically exact result, but a close enough result. And yes, you would have to put a physical ruler onto the screen to measure and adjust the slider so that the lines matches up with the ruler. This is of course not so practical to ask users to do, which is a drawback... (it can be modified to take a known object of a known size instead). Separate X/Y as needed.
When you then have the DPI (or PPI) for your screen, you can use that as a scale factor for anything that goes onto the screen, as well as its inverse (1/ppi) for the other direction, from screen to path etc.
The scale factor is calculated dividing the result on 96.
var c = document.querySelector("canvas"),
ctx = c.getContext("2d"),
rng = document.querySelector("input");
ctx.translate(0.5, 0.5);
ctx.font = "16px sans-serif";
ctx.fillStyle = "#c00";
(rng.oninput = render)();
function render() {
var v = +rng.value, sepDist = 4; // 4"
ctx.clearRect(-0.5, -0.5, c.width, c.height);
ctx.strokeRect(0, 0, v, v); // draw 1:1 pixels:ppi
ctx.fillText(v + " PPI", 10, 20);
// draw marks which should be 4 inches apart
ctx.fillRect(0, 0, 3, 140);
ctx.fillRect(96 * sepDist * (v / 96), 0, 3, 140); // assuming 96 DPI base resolution
ctx.fillText("------ Should be 4 inches apart ------", 50, 140);
ctx.fillText((v / 96).toFixed(2) + "x (96 DPI)", 10, 40);
}
<label>Adjust so square below equals 1x1 inch:
<input type=range value=96 min=72 max=150></label>
<canvas width=630 height=300></canvas>

How to use dp to calculate shadows - web development HTML CSS

I have question about using dp in web development. Im currently reading google material design guidelines and they are talking about elevation and shadows based on dp. How can I use this in web development? Is there any way to calculate this how to create shadow based on dp with HTML CSS?
Example from the web page:
Raised button
Resting state: 2dp
Pressed state: 8dp
For desktop only, raised buttons can have an elevation of:
Resting state: 0dp
Pressed state: 2dp
As mentioned in the Google Material design documents:
A dp is equal to one physical pixel on a screen with a density of 160.
To calculate dp:
dp = (width in pixels * 160) / screen density
When writing CSS, use px wherever dp or sp is stated. Dp only needs to
be used in developing for Android.
and screen density is
Screen resolution refers to the total number pixels in a display.
screen density = screen width (or height) in pixels / screen width (or
height) in inches
So it depends on the screen width and height. There are some converters on the web to calculate for each density. But as most screens are still 72dpi (not mentioned the HDPI screens), I think that is a proper starting point.
There are no CSS units that are truly device-independent. See http://www.w3.org/TR/css3-values/#absolute-lengths. In particular, the absolute units might not match their physical measurements.
If physical units were true to their purpose, you could use something like points; points are close enough to dps:
1 in = 72 pt
1 in = 160 dp
=> 1 dp = 72 / 160 pt
If you use SCSS, you can write a function to return in pts:
#function dp($_dp) {
#return (72 / 160) * $_dp + pt;
}
And use it:
.shadow-2 {
height: dp(2);
}
For Material's shadows they only really use the concept of dp to attempt to relay how elements should be layered.
i.e.
2dp < 8dp // 2 is layered under 8
// or
2dp (resting) => 8dp (focused)
What they are referring to is z-depth (or on the z-axis). This cannot be converted straight to CSS. When they talk about elevation levels they are not referring to x & y or width & height dimension.
See design guide page on elevation.
If you are simply looking for the values for CSS shadows check here.
https://github.com/mrmlnc/material-shadows/blob/master/material-shadows.scss
That is as close to converting z-depth dp to CSS values. The CSS values do match Google's Polymer elements though so it's most likely spot on.
Good Luck!

What device sizes/resolutions does Chrome's `srcset` attribute correspond to?

Is there a map defining what device sizes/resolutions the Google Chrome IMG srcset attribute sizes correspond to?
For example, in the case of
<img src="pic1x.png" srcset="pic1x.png 1x, pic2x.png 2x, pic4x.png 4x">
What size/resolution screens would receive each of those image sizes? And/or are there other sizes?
The srcset multiplier represents dots per pixel unit. It maps to a ratio of pixels to physical dimensions, rather than a particular resolution. Here is a simple mapping:
Multiplier(dppx) Dots Per Inch(dpi)
1 96dpi
1.3 124.8dpi
1.5 144dpi
2 192dpi
1 dppx = 96 dpi
1 dpi = 2.54 dpcm
1 dpcm ≈ 0.39dpi
dpi: dots per inch; 1dpi ≈ 2.54dpcm
dpcm: dots per centimeter; 1dpcm ≈ 0.39dpi
dppx: dots per px unit; 1dppx ≈ 96dpi
References
retina.js
Resolution Units
What Media Queries Can My Device See
CSS Media Queries Implementation Report
The real conflict behind <picture> and #srcset

Simulate A4 page in HTML [duplicate]

This question already has answers here:
How to make a HTML Page in A4 paper size page(s)?
(15 answers)
Closed 7 years ago.
I need to create an HTML page with A4 paper size.
I know that A4 paper size in pixels is: 595px x 842px (string No. 10-11). But while I put those sizes and try to print the page (I print to PDF file, due to the temporary lack of inks), I do not get my HTML fully fits the page: it is much smaller.
When I tried to add some pixels (with the coefficient, of course), I got 794px x 1122px (string No. 12-13) and the second printing attempt (saving to PDF file) gave me the result that this variant is a bit bigger, then needed.
So, what is the solution and why may 595px x 842px not be compatible with real A4 saved to PDF?
This is the example
P.S. I use Chromium for Ubuntu 13.10 and did not checked it on Windows.
I am doing this to be able to simply change the values via PHP and then convert HTML page to PDF, like described here.
HTML assumes that the screen is 96 DPI, or that 1 pixel is 1/96 of an inch.
On hardware with a very high resolution, it uses the concept of logical pixels, which are units that are close to 1/96 of an inch, and each of which consists of multiple device pixels. This is true for printers, but also for phones and other devices with high res screens.
So, if you want a rectangle the same size an an A4 (21 × 29.7 cm), you should use 794 × 1122 pixels, or in CSS, width:794px; height:1122px. But you can also use physical units, width:21cm; height:29.7cm if you don't want to worry about these logical pixels.
If you're planning on printing this, remember you should print at 300dpi, so 8.5"x11"* 300 = height: 3300px; width: 2550px.
Also, I would buffer .25" for a margin as well, so just do 8" x 10.5" before converting to pixels.