Between Sprites Distance + Zoom

0 favourites
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • Im figuring out how to make that on following these pics:

    <img src="http://i.imgur.com/mOlmr.png" border="0" />

    <img src="http://i.imgur.com/zFVYz.png" border="0" />

    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?

  • 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.

  • 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!

  • 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...)

  • 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!

  • 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!

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

  • > 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!

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

    Same question here; where do you write the calculation?

    bye!

  • 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), <font color=red>0.1</font>, <font color=red>1</font>)

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

    <font color=red>0.1</font> (10% size min zoom layout can be very small in some cases)

    <font color=red>1</font> (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 !

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks man! I was getting crazy trying to figure this out.

    It works better (in my case) with the onbounding scrolling set to No.

  • 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.

  • 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.

  • 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?

  • 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.

  • 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 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)