Between Sprites Distance + Zoom

Get help using Construct 2

Post » Fri May 11, 2012 10:24 am

Im figuring out how to make that on following these pics:





A red circle moves as player and the blue square is a enemy

It shouldn't lose red sprite on screen while it's out of window

Would you help me? Joannesalfa2012-05-11 10:28:17
B
96
S
25
G
20
Posts: 3,054
Reputation: 22,642

Post » Fri May 11, 2012 12:04 pm

I tried to do this some time ago, and let me just say that it was a pretty brutal piece of work to get going nicely. I couldn't find a good algorithm, so I simply had to make a series of conditions that would snap to a particular scale rate. Then I made it slowly fade from one to the other so it wasn't so jarring.

I hope someone's able to figure it out. For science.brockatkinson2012-05-11 12:05:23
B
14
S
1
G
2
Posts: 85
Reputation: 2,810

Post » Fri May 11, 2012 12:14 pm

I did this too in a game, and it worked quiet well, at least for my game.
I put a "Scroll To" behavior on the player and then I used the following calculation:

clamp(1 - Distance / (LayoutHeight + LayoutWidth), 0.10, 1.0)

Hope it helps!
B
38
S
13
G
9
Posts: 151
Reputation: 8,437

Post » Fri May 11, 2012 1:22 pm

autoFraming.capx
If you want unlimited zoom out you just have to toggle off the 2 first action (those with the clamp()) and set the unbounded scrolling to yes.
Oh and the two squares have a drag&drop behavior
And if you choose the limited zoom, it works better if the layout ratio is the same as the window ratio (although I could make it work for any ratio, by recalculating the clamping values using this ratio etc etc etc...)
Last edited by Yann on Sun Sep 14, 2014 12:05 pm, edited 2 times in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat May 12, 2012 7:14 am

@CodeMasterMike I made a test with your method, it did work as charm!

Thanks!


@Yann omfg, i didn't know there about "?" as conditional operator, but it was awesome example, thank you a lot!
B
96
S
25
G
20
Posts: 3,054
Reputation: 22,642

Post » Thu May 17, 2012 2:01 pm

[QUOTE=CodeMasterMike] I did this too in a game, and it worked quiet well, at least for my game.
I put a "Scroll To" behavior on the player and then I used the following calculation:

clamp(1 - Distance / (LayoutHeight + LayoutWidth), 0.10, 1.0)

Hope it helps![/QUOTE]


where do you put the calculation? and does it work with all kinds of games?
B
15
S
2
G
1
Posts: 15
Reputation: 1,282

Post » Thu May 24, 2012 6:41 pm

[QUOTE=MrLosAngeles213] [QUOTE=CodeMasterMike] I did this too in a game, and it worked quiet well, at least for my game.
I put a "Scroll To" behavior on the player and then I used the following calculation:

clamp(1 - Distance / (LayoutHeight + LayoutWidth), 0.10, 1.0)

Hope it helps![/QUOTE]


where do you put the calculation? and does it work with all kinds of games?[/QUOTE]

Same question here; where do you write the calculation?

bye!
B
9
S
3
G
3
Posts: 39
Reputation: 3,112

Post » Fri May 25, 2012 2:28 am

I consider yann project as more close to the behaviour explain in Joannesalfa pics ! ... these kind of effect in really useful in multiplayers on same screen game !.

CodeMasterMike magic formula works, considering P1 and P2, 2 sprites for player1 and player2 :

(Layout with unbounding scrolling set to "Yes")

On every ticks ->

set layout scale to clamp(1 - distance(p1.x, p1.y, p2.x, p2.y) / (layoutHeight + layoutWidth), 0.1, 1)

scroll to ( (p1.X+p2.X)/2, ((p1.Y+p2.Y)/2 )

<Yes i put the scroll between P1 and P2 here>

BUT ! ... P1 and P2 size not take in account ...
0.1 (10% size min zoom layout can be very small in some cases)
1 (100% size max zoom is not a powerful zoom !, just the standard one)

=> So always test and adapt for YOUR game and case ! ;-p

ENjoy !naelian2012-05-25 02:39:25
B
16
S
5
G
3
Posts: 298
Reputation: 5,240

Post » Fri May 25, 2012 5:37 am

Thanks man! I was getting crazy trying to figure this out.

It works better (in my case) with the onbounding scrolling set to No.
B
9
S
3
G
3
Posts: 39
Reputation: 3,112

Post » Fri Apr 05, 2013 8:13 pm

Hey all, I think I found a really nice and smooth way to do this. My code looks like this:

lerp(LayoutScale, min(WindowHeight, WindowWidth) / (distance(sprite1.ImagePointX(0), sprite1.ImagePointY(0), sprite2.ImagePointX(0), sprite2.ImagePointY(0)) + (max(sprite1.Width, sprite1.Height) + max(sprite2.Width, sprite2.Height)) / 2 ) * 0.70, 0.5 * dt)

The 0.7 is how much you want the "default zoom" to be, and the 0.5 controls the speed of the zoom.

I use the above formula with these scrolling values for System: Scroll to Position:

X: lerp(scrollx, (sprite1.ImagePointX(0) + sprite2.ImagePointX(0)) / 2, 0.7 * dt)

Y: lerp(scrolly, (sprite1.ImagePointY(0) + sprite2.ImagePointY(0)) / 2, 0.7 * dt)

Let me know how this works for you guys and if it's just overcomplicated.
B
6
S
3
Posts: 5
Reputation: 1,192

Next

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests