Need help with game code...

crazyfishdevcrazyfishdev Member Posts: 283
edited April 2012 in Working with GS (Mac)
I want to have it so that when the actor is touched and you drag your finger in a direction and let go another actor spawns from the actor you touched in that direction. I have all the spawning down and am happy with it but I am unable to get the drag to work properly... any ideas? the main problem I'm having is that i don't want it to spawn if not a real drag but rather a tap.

Best Answer

  • PhoticsPhotics Posts: 4,172
    Accepted Answer
    The trick is to record the starting X&Y points of the touch. Then, upon release, calculate if the release location is far away enough.

    Game Attributes...

    • game.startX
    • game.startY
    • game.releaseX
    • game.releaseY

    If touch is pressed...
    change game.startX to mouse.X
    change game.startY to mouse.Y

    if touch is release
    change game.releaseX to mouse.X
    change game.releaseY to mouse.Y
    ...if game.releaseX is greater than game.startX + 25
    or... if game.releaseX is less than game.startX - 25
    or... if game.releaseY is greater than than game.startY + 25
    or... if game.releaseY is less than game.startY - 25
    ... run behaviors
    otherwise... play error sound

    This is just a rough outline. I didn't test it, but I think that could be the solution you're looking.

Answers

  • crazyfishdevcrazyfishdev Member Posts: 283
    Thanks @photics glad to know thats the direction i will need to go...
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    If you open GameSalad and click on the "New" plus button and then search for "swipe" or "drag," you'll see some good demos.

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

  • crazyfishdevcrazyfishdev Member Posts: 283
    kk thanks... maybe there will be some new ones but when i looked before they all used 2 actors and i want to use only one to do it
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2012
    @crazyfishdev I just modified the "simple swipe direction finder" demo and it worked great. It uses a single actor (instance) to detect the direction of the swipe.

    There's also this @tshirtbooth video:


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

  • crazyfishdevcrazyfishdev Member Posts: 283
    thanks :) I knew he did a video and went to look and i couldn't find it! thanks a ton!
  • crazyfishdevcrazyfishdev Member Posts: 283
    alright... after watching the video I have run into a few potential problems... can it still recieve touch if another actor is above it? I have an actor on top that i would need to works well as as having the touch work...
  • crazyfishdevcrazyfishdev Member Posts: 283
    i solved it nvm...
Sign In or Register to comment.