Is there a "Touch moves outside of actor" condition for rules?

frankwashburnfrankwashburn Member Posts: 32
edited March 2012 in Working with GS (Mac)
For rules for touch-based stuff on Actors, there is:

"Pressed" - touch does not exist, and then suddenly exists on the actor
"Released" - touch exists on the actor, and then does not exist at all
"inside" - any touch anywhere inside the actor
"Outside" - any touch anywhere outside the actor

I need a variant on 'released'... I need my actor to change its behavior if you are touching it, and your touch moves off of it.

I.e. "Touch exists on the actor, and then still exists, but has moved off of the actor"

The problem is, is there are multiple actors at once like this, meaning that "Outside" does not work. If I touch one of my actors, and then simultaneously touch another actor, that secondary touch reads as an "outside" touch and changes the behavior of my first actor.

I want my actor, from being touched to
1) Change behavior if touch is lifted (i.e. "released")
2) Change behavior if the touch that has begun on the actor moves off of the actor's position.

This is proving to be extraordinarily difficult. Any help appreciated.

Best Answer

  • JohnPapiomitisJohnPapiomitis Posts: 6,256
    Accepted Answer
    Youll have to make another attribute thats true when the mouse position is inside the actors, and false when its not. Then add when that attribute is false to the conditions of the rule for the touch outside. That way touching another actor doesnt trigger it. I made you a quick demo real quick, let me know if its what your after.

    http://www.mediafire.com/?lrdrxvakxf296yj

    cheers

Answers

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    Try this.

    Make a self attribute called touched(boolean)

    Have a rule when touch is pressed
    -change attribute touched to true

    Then have another rule when touch is outside and attribute touched=true
    -do whatever
  • frankwashburnfrankwashburn Member Posts: 32
    Aren't those mutually exclusive?

    How can:
    Rule: Actor receives event Touched is outside && Actor receives event Touched pressed

    ever return true? Isn't by definition the touch input being outside of the actor mean that the actor itself is NOT touch-pressed?


    Is there a way to give touch events variable names and keep track of them? The challenge is doing this with multiple of these Actors - a touch event outside one of these actors sets off the rules for all of them.
  • AsymptoteellAsymptoteell Member Posts: 1,362
    I'm pretty sure his point was that it would make the attribute true when it was inside, and it would stay on once it moved outside, but with the added event of an outside touch, the computer would know it's been on the inside and is now on the outside. Name the rule "Things on the outside just ain't what they used to be," and you'll do fine.

    I'd also add a timer and rule to after 1 second of being outside, change the attribute back to false, and another to make it false if you unpress the button just by letting go.

    I don't know if that makes any sense. If not, just say so, and I'll try to clear it up.

    Asymptoteell
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    The challenge is doing this with multiple of these Actors - a touch event outside one of these actors sets off the rules for all of them.
    Yes thats how it works. Touch is outside checks for anytouch not on the actor. So they will all go off if you have that rule and the touch on any of them.

    What i said will correct that, because youll have to touch it first then move the touch off of it for it to trigger, and it wont effect every actor. Only the one the action was applied to. Try it out.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2012
    @JohnPapiommitis That works. What about a way to simulate Touch is Released the instant that an actor is released and only for that instant, so that it isn't true if I've released the touch and, say, a second has gone by?

    Nevermind, I think I figured it out:

    image

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • frankwashburnfrankwashburn Member Posts: 32
    @John @Asymptotell Thanks, I think I understand John's explanation now.

    @tatiang - Shouldn't the second rule be "Actor receives event touch is OUTSIDE" rather than Released?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2012
    @tatiang - Shouldn't the second rule be "Actor receives event touch is OUTSIDE" rather than Released?
    No, because I'm not trying to solve your initial question. For my purposes, I don't care about inside/outside, I just want to know the precise moment that the touch is released from the actor. I guess I could add Touch is Outside if I need it, but for now I'm happy to have a set of rules that give me the ability to run a rule/behavior when an actor is released. I'm thinking specifically of a tower defense game where you click and drag an actor from a "store" area and then release it where you want to place it. I can then run a rule when the tower is released, such as to enable it to shoot, etc.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • MotherHooseMotherHoose Member Posts: 2,456
    any actor responds to touch is outside
    when they have that rule

    try this:
    add an actor and the
    Rule: when
    Event: touch is outside
    --changeAttribute: self.Color.Alpha To: 0.2
    Otherwise:
    --changeAttribute: self.Color.Alpha To: 1

    drag a few of these actors to the scene
    Preview and touch (and hold down the mouseButton) outside the actors
    they all change their Alpha
    release and they all change

    the whole displayArea of the device is touch sensitive and tracks the position of a touch

    actors receive the events:
    touch: pressed; inside; outside;
    however, an actor receives the event 'released' only when touch is inside that actor

    we do not have to track the the touch pressed or released position … the computer does that!

    small demo: http://www.mediafire.com/?cxuidbj5jn5no1i

    image MH
  • frankwashburnfrankwashburn Member Posts: 32
    @John John, I'm having some trouble with your suggested implementation.

    I have two identical Actors with your suggested implementation in the scene.

    I touch one - so it changes state, and Actor1.istouched turns to TRUE.

    Then I touch the second Actor - Actor1 immediately receives a "touch received OUTSIDE" and changes again!!


    Simply trying to touch multiple of these Actors at once counts as a "touch received OUTSIDE actor" and thus disables all of the other actors. :(
  • frankwashburnfrankwashburn Member Posts: 32
    @Johnpapiomitis Thank you John, that makes sense and is super helpful.

    One last thing though - I think there's one more rule that I need. A rouge touch that doesn't land on any of the Actors at all should disable all of them - by changing game.onAnotherActor to false.

    Because there needs to be a rule to SET game.onAnotherActor to FALSE, otherwise once it gets changed to TRUE it will never be set back to FALSE.

    How does one implement a rule like that?

    Is it possible to layer Actors? Maybe I could make the background art of the scene an Actor, and if any touch touches it and not the Actor in front of it, then it sets game.onAnotherActor to FALSE.
  • frankwashburnfrankwashburn Member Posts: 32
    @John Actually John I'm going to open this up specifically in a new discussion. Thank you very much for that demo and for all of your help.
  • frankwashburnfrankwashburn Member Posts: 32
    @John Ok I think I have a solution, but I am not sure how to implement it.

    I am keeping a counter on all Actors that are being touched.

    If I do:

    Rule:
    If Actor receives touch that is outside
    &&
    Counter does NOT change

    Then deactivate.

    Is checking to see whether a counter changes upon the device receiving a touch is as simple as
    "Attribute counter =/= counter"?
Sign In or Register to comment.