Touch input question

micahmicah Member Posts: 85
edited November -1 in Working with GS (Mac)
I'm trying to make a d-pad, but it needs to behave a lot differently than the ones in the wiki. The d-pad is a circle and it's split into 8 sections: left, top-left, top, top-right, right, bottom-right, bottom, and bottom-left.

The d-pad is a single actor, and depending on where you press the image of it updates accordingly. I've done all the math correctly, and depending on which part of the d-pad you press that part lights up.

I have a rule, if actor receives event touch inside, and if it's true it calculates the angle of the touch. So it's like:

if ( actor receives event touch inside ) {
figure out the angle
based on the angle, figure out which of the 8 directions is being pressed
}

The problem is when you move your finger to a different part of the d-pad, it doesn't run this code over again, so it doesn't update the angle that's being pressed. So if you start pushing the right side of the d-pad and it says right is being pushed, then you slide your finger to the left, if still thinks right is being pushed.

I even tried:

timer, every .05 seconds {
if ( actor receives event touch inside ) {
figure out the angle
based on the angle, figure out which of the 8 directions is being pressed
}
}

And it didn't help. The problem here it looks like is iPhone touch events get sent to the app when they're touching down, getting released, or moving, but GameSalad doesn't have an event for when a touch moves. How can I solve this?

Thanks!

Comments

  • BeyondtheTechBeyondtheTech Member Posts: 809
    I have a different idea of coming up with a virtual D-Pad.

    Create 4 rectangular Actors. Two horizontal, two vertical.
    Have the ends of the Actors overlap such that you end up with a tic-tac-toe design or looking like the title screen of the Brady Bunch.

    All you need to do is register one Rule for each of the Actors.

    If he touches the UP bar, go up.
    If he touches the DOWN bar, go down.
    If he touches the LEFT bar, go left.
    If he touches the RIGHT bar, go right.

    Using GS' current limitation (or feature?), it will detect two Actors being touched if you tap on the corner.

    If he touches the upper-right corner, both Actors for UP and RIGHT will register, and so on.

    Does that work for you?
  • micahmicah Member Posts: 85
    Hey, I'm trying this out and it looks like it's working great! Thanks, that's a lot simpler than using angleFromVector() and all that... :)
  • BeyondtheTechBeyondtheTech Member Posts: 809
    Glad I could help.

    Now, you can either hide your directional Actors and place a huge graphic D-pad Actor on top of it with a 0.5 Alpha Color for transparency (easier), or you can turn cut up a design and stick it into the four separate directional Actors (slightly more difficult, but less resources).

    Keep at it, hope to see a game from you soon.
  • NestorAcevedoNestorAcevedo Member Posts: 1
    for me, this didn't work. maybe i'm doing bad rules or validations.
  • ORBZORBZ Member Posts: 1,304
    micah, are you using mouse.position to figure out the current touch location or touch 1? I think touch 1 only updates where you first touched, whereas mouse.position (even on iPhone) updates constantly.

    That's from my 0.7.0 experience though... it may have changed in 0.8.2
Sign In or Register to comment.