How to calculate ...

For questions about using Classic.

Post » Wed Jun 01, 2011 12:30 am

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?
B
43
S
8
G
5
Posts: 110
Reputation: 3,605

Post » Wed Jun 01, 2011 12:55 am

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...
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Wed Jun 01, 2011 1:20 am

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
B
43
S
8
G
5
Posts: 110
Reputation: 3,605

Post » Wed Jun 01, 2011 6:02 pm

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
[code:3hqapjqi]PlayerSprite.X - 100 + (DisplayWidth / 2) * (100 / ZoomX)[/code:3hqapjqi]

Without being able to validate it, I don't have Construct at the moment
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Jun 03, 2011 3:46 pm

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. :oops:

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% ? :roll:
B
43
S
8
G
5
Posts: 110
Reputation: 3,605

Post » Fri Jun 03, 2011 7:33 pm

Damn, you're killing me :mrgreen:
But I'll do my best to make a third attempt.

Distance from edge in pixel:
[list:342r2nwn]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[/list:u:342r2nwn]

To get the "real" value:
[list:342r2nwn]d = d * (100 / ZoomX)[/list:u:342r2nwn]

Applying left aligned:
[list:342r2nwn]-> Scroll to x
PlayerSprite.X - d + (DisplayWidth / 2)[/list:u:342r2nwn]

Or applying right aligned:
[list:342r2nwn]-> Scroll to x
PlayerSprite.X + d - (DisplayWidth / 2)[/list:u:342r2nwn]

I sincerely hope it works :mrgreen:
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sun Jun 05, 2011 7:48 pm

1000 times thanks Tulamide, this is exact what I need and it works awesome! :D :D :D
B
43
S
8
G
5
Posts: 110
Reputation: 3,605


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests