Touch and scale actor

glyniusglynius Member Posts: 231
edited August 2012 in Working with GS (Mac)
Hi everybody.
I need some help on the following:
i want to drag and scale an actor, i managed to do it, but the problem is that when i touch
my actor, it scales sudden according to the area of the touch. I don't know if it is clear enough.

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited August 2012
    @glynius

    Hi, I'm guessing you've got both sets of Rules - for drag and scale - all working on touch, so they'll start working at the same time. So you need some sort of separation; your drag rules will work OK on the touch rule of course, but then you'll have to work in some kind of system to let the rules "know" the actor needs to be scaled.

    What this system is would depend on what kind of game or app you are making.... if it's some sort of utility for instance, one system would be to have a button at the side that when pressed, highlights the actor perhaps, and when touched scales the actor accordingly.

    It's difficult to be more precise without knowing what sort of thing you're creating...

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • glyniusglynius Member Posts: 231
    @glynius

    Hi, I'm guessing you've got both sets of Rules - for drag and scale - all working on touch, so they'll start working at the same time. So you need some sort of separation; your drag rules will work OK on the touch rule of course, but then you'll have to work in some kind of system to let the rules "know" the actor needs to be scaled.

    What this system is would depend on what kind of game or app you are making.... if it's some sort of utility for instance, one system would be to have a button at the side that when pressed, highlights the actor perhaps, and when touched scales the actor accordingly.

    It's difficult to be more precise without knowing what sort of thing you're creating...
    Sorry, i will try to make it more clear...

    I want to have an image on my scene, i will have 3 options, move, scale, rotation.
    I fixed the move and rotation issues, i also fixed the scaling. but (like rotation that fixed) when you touch the actor, for scaling, it takes the number of x,y of touch and converts it to scaling x,y, The problem is that this scaling does not start the scaling from the current actors scaling but it depends on the x,y of the touch.
    Imaging that i want to make an application like a photo studio or something. not a game. I don't know how to explain it better...i apologize...
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited August 2012
    @glynius -- you probably fixed the rotation issue by using an offsetX, offsetY (or perhaps an offsetAngle) to take care of the rotation snapping to the touch point.

    The same thing needs to happen with scaling. In this case you would determine the distance from the center of the actor to the touch point (use magnitude function). Then you add (or maybe subtract) that offset distance into the scaling equation you have.

    Here is a previous thread that might help:
    http://forums.gamesalad.com/discussion/44456/pinch-spread-rotate
  • glyniusglynius Member Posts: 231
    @glynius -- you probably fixed the rotation issue by using an offsetX, offsetY (or perhaps an offsetAngle) to take care of the rotation snapping to the touch point.

    The same thing needs to happen with scaling. In this case you would determine the distance from the center of the actor to the touch point (use magnitude function). Then you add (or maybe subtract) that offset distance into the scaling equation you have.

    Here is a previous thread that might help:
    http://forums.gamesalad.com/discussion/44456/pinch-spread-rotate
    I think i've done it this way, but still not working as i want.
    i created a self-distance attribute which is constrained to
    magnitude( game.Touches.Touch 1.X - self.Position.X , game.Touches.Touch 1.Y - self.Position.Y )

    then i constrain self.size.width TO self-distance
    same thing for Height.

    The problem is still there, if i press in the middle of the actor, the actor gets real small,
    then when i drag it gets bigger or smaller. So the problem is at my first touch. I don't need two finger scaling at this time, but the preset you linked me to, for sure it will be very useful for me in the near future...so thanks anyway.

    It must be something stupid, but since i am a begginer, i am really confused with this, it is one of the lasts things to fix before publishing my app.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Try something like:
    Constrain: self.size.Height To: (self.size.Width + (self.size.Width - self.distance))
  • glyniusglynius Member Posts: 231
    Try something like:
    Constrain: self.size.Height To: (self.size.Width + (self.size.Width - self.distance))
    thanks, but...not working either...
    any ideas?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited August 2012
    Oh -- OK try this. This is based upon the example demo in the other thread but modified because you don't need multitouch.

    Make three 'real' attributes in the actor: widthOffset, heightOffset, and distance.

    Add this rule to the actor:

    When touch is pressed
    --Change Attribute: self.widthOffset To: (magnitude( game.Mouse.Position.X - self.Position.X , game.Mouse.Position.Y - self.Position.Y )- self.Size.Width )
    --Change Attribute: self.heightOffset To: (magnitude( game.Mouse.Position.X - self.Position.X , game.Mouse.Position.Y - self.Position.Y )- self.Size.Height )
    --Constrain Attribute: distance To:magnitude( game.Mouse.Position.X - self.Position.X , game.Mouse.Position.Y - self.Position.Y )
    --Constrain Attribute: self.Size.Width To:self.distance - self.widthOffset
    --Constrain Attribute: self.Size.Height To:self.distance - self.heightOffset

    Notice that there are two Change Attribute behaviors and three Constrain Attribute behaviors

    Hope this helps!
  • glyniusglynius Member Posts: 231
    RThurman, thanks man.
    I just send my imac for screen replacement and i also leave for vacations, i will try what you suggest as long as i am back. I really appreciate your help.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    No Problem!

    Hope it works out for you.
  • glyniusglynius Member Posts: 231
    still not working, it seems that it must be very tricky. thanks RThurman anyway, if you have anything else to suggest, please tell me.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    I will probably need a little more information to figure out what's not working! Can you describe the issue in more detail?
  • glyniusglynius Member Posts: 231
    I will probably need a little more information to figure out what's not working! Can you describe the issue in more detail?
    yeap, the problem is that it stills starts the scaling according to the place that you touch (so, when you touch, lets say, 100pixels from the center of the actor, it scales sudden to big), and also the width and height are not constrained as it should be, i hope this helps.
Sign In or Register to comment.