scale globals and locals

Get help using Construct 2

Post » Sat Oct 29, 2011 12:19 pm

When setting scale mode on everything gets scaled to fit the browser window. Very nice! But what happens to nummeric variables?

Suppose I have an action which adds 80 pixels to the Y coordinate of a sprite. In scale mode I will have to use a variable to calculate the amount (80 * layoutscale). Can this be done on start of layout or should it be done on every tick?

Would it be possible to introduce a scaling nummeric variable to avoid the event sheet getting cluttered with recalculations?

Regards,

Jeroen
B
5
G
2
Posts: 10
Reputation: 1,145

Post » Sat Oct 29, 2011 12:21 pm

You don't need to use layoutscale in your movement calculations! The scaling only affects the display - how existing movements are shown. You do not need to change how you move objects!
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Sat Oct 29, 2011 1:56 pm

Sorry, but I do not understand this. When I move an object 100 pixels on a screen which is 1000 pixels heigh, the amount of movement is 10 percent. When screen height is 500 then 100 pixels movement is 20 percent. I never was any good at math, but it seems to me the result would look different on the screen even when the sprite itself has been scaled to half its original size.
Suppose the original sprite is 100 X 100 pixels at y 800 (80%). Moving it 100 pixels, it is still visible at y 900. Scaling the layout by half would result in a sprite 50 x 50 at 400 (still 80%) Moving this 100 pixels the sprite would go off screen. Or do I make a logical mistake?Jeroen2011-10-29 14:23:41
B
5
G
2
Posts: 10
Reputation: 1,145

Post » Sat Oct 29, 2011 3:05 pm

You're just not quite thinking about this right. There's a big difference between game co-ordinates and screen co-ordinates. When you change an object's position you change its position in game co-ordinates. These are not the same as pixels on the monitor! All the scaling feature does is stretch what's in the game.

So for example: moving an object by 100 moves it in the game by 100 pixels. On a monitor 1000 pixels tall, this is 10% of the screen. On a monitor 500 pixels tall, the scale would be 50% due to the scaling feature, so it moves 50 pixels on-screen, which is still 10% of the screen.

The game happens independently of how it is drawn. Imagine you have no monitor at all! The game is still happening invisibly, and objects moving around in the computer's memory. Attaching monitors which display different parts of the game at different sizes does not affect those objects moving around in memory. So you don't need to worry about the scale at all when moving objects, or in fact in any of the game logic.Ashley2011-10-29 15:06:26
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Sat Oct 29, 2011 3:24 pm

Thank you Ashley for explaining this. Indeed I assumed game coordinates to be screen coordinates using pixels as unit. Well, this makes it a lot easier to develop games for different screen resolutions.
B
5
G
2
Posts: 10
Reputation: 1,145


Return to How do I....?

Who is online

Users browsing this forum: Scofano and 18 guests