Between Sprites Distance + Zoom

Get help using Construct 2

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

Post » Fri Sep 27, 2013 2:17 am

First post here; I've been using construct for a few months, though.
How do i modify this to leave space on the outside of the 'framed' sprites? And could someone post how to modify this to more entities? all this math makes my brain hurt!

EDIT: I'm going for a Super Smash Bros. type effect.
EDIT2: solved my first question. for anyone wondering, it's the number before (X*dt); which is .7 in the example. would still like help with 4-player, though.TalorA2013-09-27 02:59:04
B
3
Posts: 5
Reputation: 215

Post » Sat Jun 13, 2015 5:52 am

Yann wrote: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...)



Did anyone try this? I'm surprised no one seemed to respond. If it's a plugin that can adjust the zoom then that's perfect isn't it?
Life is what you make it!
B
9
S
2
G
5
Posts: 44
Reputation: 3,286

Post » Sat Jun 13, 2015 5:58 am

I tried the plugin, but when I boot up C2 it says it's unable to load the plugin/behavior.

Tried both the plugin and behavior folder.
Life is what you make it!
B
9
S
2
G
5
Posts: 44
Reputation: 3,286

Post » Sat Jun 13, 2015 8:54 am

ozboybrian wrote:I tried the plugin, but when I boot up C2 it says it's unable to load the plugin/behavior.

Tried both the plugin and behavior folder.


What do you mean by plugin?
It's just a capx, a layout with events..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
53
S
16
G
8
Posts: 6,157
Reputation: 19,744

Post » Sat Jun 13, 2015 4:30 pm

LittleStain wrote:
ozboybrian wrote:I tried the plugin, but when I boot up C2 it says it's unable to load the plugin/behavior.

Tried both the plugin and behavior folder.


What do you mean by plugin?
It's just a capx, a layout with events..


LOL my bad. Sorry all.
Life is what you make it!
B
9
S
2
G
5
Posts: 44
Reputation: 3,286

Post » Thu Dec 31, 2015 5:59 pm

Any ideas on how I can accomplish this with 4 players running around on a screen? Right now it's only taking the distance of 2 players. Would you have to compare the X and Y distance of every player, then choose the max ones?
B
32
S
4
Posts: 406
Reputation: 3,221

Post » Wed Feb 17, 2016 11:39 pm

Hello Im super new but would be so thankful for a tip on how to accomplish Naelian's code.


I tried "Naelian's" way and ended up having this: (sorry I can't upload my dropboxed screenshot)

On every ticks ->
set layout scale to clamp(1 - distance(p1.x, p1.y, p2.x, p2.y) / (layoutHeight + layoutWidth), 0.5, 1)
scroll to ( (p1.X+p2.X)/2, ((p1.Y+p2.Y)/2 ) JUST FOUND OUT THAT MY SCROLL TO ACTION DOESNT WORK AT ALL

I set the Naelian's "0.1 and 1) to "0.5 and 1" but Im not quiet sure what they really do. Now I ended up with having the superb opposite of what i want. If the two player are close my window/levelbackground is like fullscreen and when the two player go as far as they can its about 50% zoomed out.

But I want it to be "full" when the player are far away and just a little zoomed in when they get closer. Inverting the "0.5,1" to a "1,0.5" didn't solve it. All just stayed "full" without zooming. This must be funny for you :P I guess those setting obviously dont do what i thought they might be for :D

Please help :)
Thank you!
B
7
Posts: 23
Reputation: 336

Previous

Return to How do I....?

Who is online

Users browsing this forum: DemantDigitalArt, Unconnected and 32 guests