# How to calculate ...

This forum is currently in read-only mode.
0 favourites
• 7 posts
• I'm strugeling to make a right calculation for the following:

In my platformer I have made that if you walk right and press Ctrl that the player/camera moves to 100 pixels to the left of the screen, now I have added that you also can zoom in and out, and I can't figure out how to make the right calculation that the player/camera is still 100 pixels at left of the screen.

Anyone can help me with this?

• You mean 100 "unzoomed" pixels, while zoomed?

When zoomed to 200% every pixel uses 2x2 "unzoomed" pixel, so you would need to move the cam 50 pixels to the left instead of 100. So I would say it is

currentX - 100 * (100 / zoom)

EDIT: Ups, to the left, sorry. Corrected to minus...

• Thanks for the reply Tulamide,

At 100% zoom, the player is 100 pixels from left of the screen and my zoom level is between the 100% and 50% so you can see more from the level and it zooms in steps of 5.

But I want that it stay 100 pixels from left of screen when the player hold Ctrl key, nomater what the zoom level is.

this is what I do now at 100% zoom: 0-(DisplayWidth/2)+100

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Ok, so you need to calculate the scroll center based on the player sprite. When the player sprite is at x = 300, then the left edge of the visible screen should always be 200, no matter the zoom. And when it is at x = 960, then the left edge should be 860, etc?

Scroll to x

``````PlayerSprite.X - 100 + (DisplayWidth / 2) * (100 / ZoomX)[/code:3hqapjqi]

[i]Without being able to validate it, I don't have Construct at the moment[/i]``````
• Thanks Tulamide,

I did not realize that the amount of pixels from the screen stay the same whatever the zoom is, so my explanation was wrong.

What I want is that the player is around 10% at the left and/or right of the screen, but how to calculate this when zoom can be between 50-100% ?

• Damn, you're killing me

But I'll do my best to make a third attempt.

Distance from edge in pixel:

d = DisplayWidth / 100 * desiredPercentage, e.g. d = DisplayWidth / 100 * 10 or just use a fixed value based on the display size, e.g. d = 100

To get the "real" value:

d = d * (100 / ZoomX)

Applying left aligned:

-> Scroll to x PlayerSprite.X - d + (DisplayWidth / 2)

Or applying right aligned:

-> Scroll to x PlayerSprite.X + d - (DisplayWidth / 2)

I sincerely hope it works

• 1000 times thanks Tulamide, this is exact what I need and it works awesome!