Scaling an actor with touch

Hi!
I have a square box (actor) that I want to scale depending on how far away I drag my finger from the touch start point.
The direction I'm dragging my finger should not matter, it's how far away it's being draged. The X & Y proportions have to be the same, so that it stays a box and does not become a rectangle.

Please help me if you've got the answer!

Comments

  • ArmellineArmelline Member, PRO Posts: 5,369
    edited March 2015

    Achieving this effect for a square that only grows in size is pretty simple. Would you want the square to be able to be shrunk using this drag method too?

    Attached is an example project that achieves the effect for growing only. If you want to be able to shrink using the same drag method, things get a lot more complicated. Not so much with the logic, but with the interface. Does the shrink depend on the drag direction? etc.

  • dekisimkedekisimke Member Posts: 24

    Yes it needs to shrink as well.
    Let me explain more...

    In my game I have a "Touchscreen" actor. It stretches across the entire screen.
    Right now, when i touch anywhere, a "Box Mask" will spawn. This mask is rotating to the angle of the touch. When released, a new actor "Box" will be spawned with the same angle as the mask had. Just like this:

    This works great but the problem is that the player can tap once to place the box. I don't want that to be possible. So i have to make a "Box Mask 2" (same img as the box) that will spawn together with the "Box Mask 1". It is this actor (2nd Box Mask) that i want to scale! It starts with size 0 and scales up when the finger is dragged away from the mask and scales down when the finger is dragged towards the mask. The box will be placed only if the "Box Mask 2" is the same size or larger then "Box Mask 1". Meaning that the player can not tap to place anymore and is forced to drag their finger in order to place the box.

    So what I need to know is only the scaling part of "Box Mask 2".

  • ArmellineArmelline Member, PRO Posts: 5,369

    There shouldn't be any need to spawn Box Mask 2 at all. You can prevent a tap being enough in a few ways, perhaps the simplest would be to only accept the "swipe" if the magnitude from the touch start position to the touch end position is greater than, perhaps, 10px.

    i.e. magnitude(game.TouchXStart-game.Touch 1 X,game.TouchYStart-game.Touch 1 Y) > 10

  • dekisimkedekisimke Member Posts: 24
    edited March 2015

    @Armelline said:
    There shouldn't be any need to spawn Box Mask 2 at all. You can prevent a tap being enough in a few ways, perhaps the simplest would be to only accept the "swipe" if the magnitude from the touch start position to the touch end position is greater than, perhaps, 10px.

    i.e. magnitude(game.TouchXStart-game.Touch 1 X,game.TouchYStart-game.Touch 1 Y) > 10

    Indeed, but I want that visual effect to be there so that the player understands why the box isn't spawning when he/she's tapping the screen. They need to understand that they need to match the "Box Mask 2" size with the "Box Mask 1" in order to place the box.
    Also, I need "Box Mask 2" to stop scaling once reaching the same size as "Box Mask 1".

  • ArmellineArmelline Member, PRO Posts: 5,369

    Sorry I'm lost :D I thought box mask 2 was invisible? I'm afraid I really can't get a good enough idea of what you're after to be able to help. Does box mask 2 start off smaller than box mask 1?

  • dekisimkedekisimke Member Posts: 24
    edited March 2015

    @Armelline said:
    Sorry I'm lost :D I thought box mask 2 was invisible? I'm afraid I really can't get a good enough idea of what you're after to be able to help. Does box mask 2 start off smaller than box mask 1?

    Yes the box mask 2 starts off with size 0. it is placed inside the box mask 1. when the player drags their finger outwards the box mask 2 will scale up until reaching the same size as box mask 1. And then by your magnitude rule the box will be placed.

  • ArmellineArmelline Member, PRO Posts: 5,369

    Okay, that shouldn't be too hard then. My original example should work for that. You still have some tricky UI considerations to consider, though.

  • dekisimkedekisimke Member Posts: 24
    edited March 2015

    This is how it looks now:

    I want the box mask 2 to scale up and down instead of just making the alpha go on/off.
    Remember that it needs to have a scaling limit so that it doesn't scale over the box mask 1.

  • ArmellineArmelline Member, PRO Posts: 5,369

    Did you look at the project I posted?

  • dekisimkedekisimke Member Posts: 24

    @Armelline said:
    Did you look at the project I posted?

    Yes, I did take a look. But the box wont scale down to 0 size and if i scale it up a bit and then try to scale it down, it wont go down to scale 0 but to the previous scale when i released touch.

  • ArmellineArmelline Member, PRO Posts: 5,369
    edited March 2015

    Start the box at size 0. If you want to be able to release touch and then press again, that complicates things a bit though.

  • dekisimkedekisimke Member Posts: 24

    I have reached my result i was looking for! Thanks for all your help Armelline!!!!!!!! You are someones hero today! =D

  • ArmellineArmelline Member, PRO Posts: 5,369

    Glad to hear it helped! Good luck with your game!

Sign In or Register to comment.