Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

ct.js

Create cool 2D games with a free game editor! · By Cosmo Myzrail Gorynych

What does ct.camera.realign(room); actually do ?

A topic by HardWomen created 21 days ago Views: 28 Replies: 3
Viewing posts 1 to 3

The manual says "To align basic interfaces automagically".

Since ct.js already do a good job of rescaling everything to fitscreen proportionately, what is this ct.camera.realign(room); doing and under what condition would we ever call it then ?


What does it actually do ?

Developer

It is useful on different screen proportions. Say, you have 16:10 monitor, I have a 16:9 one, and my sister has a 21:9 ratio, and a game runs with ct.fittoscreen’s “Scaling without letterboxing” mode. Your game will cover any screen, fully, but without ct.camera.realign(room) elements that were supposed to be placed in corners will be in the wrong places if the screen is of different aspect ratio you were designing for.

Here is how it works with the catformer demo and its UI layer — by stretching the window, I can “simulate” screens of different width:

And here is how it works without ct.camera.realign(this);:

Though ct.camera.realign is not perfect, it is better than nothing :D If ct.camera.realign is not enough, one can always align their UI manually relative to ct.camera.width and ct.camera.height.

(6 edits)

Oh I see it now, ct.camera.realign is AMAZING !!!

Thank you for taking the time to show the screenshot, this should be in the documentation, this is SO AMAZING !!!!!!

Now...what do you do to tell ct.camera.realign which element should be pulled towards the left or the right (or top or bottom for that matter).

How does ct.camera.realign "know" which element are to go towards the left or right ?

How do you inform it ?

PS: Wait I just saw that this magic is required only for Scaling without letterboxing, since all my game will be played with cropping on because things can get real complicated real fast catering to all the resolutions, it looks like ct.camera.realign would not be ultilized by me at all.   

Thanks for the explanation !

Developer

How does ct.camera.realign “know” which element are to go towards the left or right ?

It works based on copies’ xstart and ystart coordinates, and interpolates them based on initial and new camera size.