How would you make 2048 style swiping?

FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

So lets say I have an actor in the scene. (this is all theoretical my real project is very different but uses this concept) Let's say I want to make it so that when a person swipes up, the actor moves up say 10 degrees, swipe right move right 10 degrees, left, down, you get the picture.

I saw GSHelper's video on swiping here:

But that seems to be dependent on the release of the swipe, which if you look at a game like 2048, the second it registers that you have placed your finger on the screen, and moved it at all to the right, whether you lifted your finger off the screen or not, the game shifts the blocks right, left, and so on. It's not dependent on the player removing their finger from the screen. Would this be possible, to make a swiping system that when it registers you have swiped right, it activates say a "right" boolean attribute to true, which in the actor would cause what you want to happen when the right attribute is true.

I also could see this maybe being a little sensitive, like if you swipe at all up or down when trying to go right maybe it would confuse the system and GS would pick the undesired one. So would there be away to set the specific amount of distance you want to be required in any direction before it registers?

This is kind of complicated, but I do hope this is the type of thing that has already been solved, if so, please link me. If not, I'd love to hear what you have to say.

Thanks
TJ

Comments

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    PS Built in Swipe functionality is a MUST for gamesalad.

  • zweg25zweg25 Member Posts: 738

    You can try doing when touch is pressed to see the start X and Y but instead of touch is released just put in a timer after .25s (or whatever) in the touch is pressed rule. Untested, but think it could work

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148
    edited March 2015

    Well, I figured out, like I said in the original post, my goal was to make the action that follows a swipe dependent on an attribute being true. So if I wanted an actor to move left when I swiped left, my goal was to make the swipe left cause a LEFT attribute to be true, and when the LEFT attribute is true the actor moves left a certain amount. I also did along with this work out how to make the swiping non dependent on the release of a touch.

    I have attributes touchX, touchY, releaseX, releaseY (I just left them release), differenceX, differenceY, absX, absY, DOWN, LEFT, RIGHT.

    (It should be noted that I have only the desire to make down, left, and right swipes work, I have no use for Up, a few things would have to be adjusted to make up work, but it would follow the same basic principle.)

    So heres the code,

    I have an actor called Swipe Button, expanded to be underlying the whole scene, in that actor we have:

    Rule (when touch is pressed)
    {
         do
         {
              set game.touchX to game.Mouse.position.x
              set game.touchY to game.Mouse.position.y
    
              After 0.2 seconds [Run to completion]
              {
                   set game.releaseX to game.Mouse.position.x
                   set game.releaseY to game.Mouse.position.y
              }
    
              After 0.25 seconds [Run to completion]
              {
                   set game.differenceX to (game.releaseX-game.touchX)
                   set game.differenceY to (game.releaseY-game.touchY)
                   set game.absX to abs(game.differenceX)
                   set game.absY to abs(game.differenceY)
              }
    
    Note: this next part right here is what you would have to modify to include up
                  After 0.3 seconds [Run to completion]
                  {
                       Rule
                       If game.absY > game.absX
                       If game.differenceY <= -25
                       {
    Note: <--- that -25 value, and all the other 25   values are what you would change to change the amount of distance someone would have to move their finger to register that it was that kind of swipe, so Im on an ipad prototype right now, and so on a smaller screen with less coordinates this would be a much smaller value.
                         do
                         { 
                              set game.DOWN to true
                              After 0.8 seconds [Run to completion]
                              {
                                   set game.DOWN to false
                              }
    
                         else
                         {
                              Rule
                              If game.differenceX <= -25
                              {
                                   do
                                   {
                                        set game.LEFT to true
                                        After 0.8 seconds [Run to completion]
                                        {
                                             set game.LEFT to false
                                        }
                                   }
    
                                   else
                                   {
                                        Rule
                                        If game.differenceX >= 25
                                        {
                                             do
                                             {
                                                  set game.RIGHT to true
                                                  After 0.8 seconds [Run to completion]
                                                  {
                                                       set game.RIGHT to false
                                                  }
                                             }
                                        }
                                   }
                              }
                         }                    
                    }
               }
          }
    }
    

    And there you have it. After this I placed a bunch of copies of actors with display texts in them, each displaying each of the attributes, so I could monitor them. Surprisingly, this is the first time I've just gone out on a whim and just made something on the way that I thought it could work, and it just simply worked the first time I opened it up in the prototyper. I was stoked. :) Anyway, I hope this helps someone, and I would love to hear if there is any redundancy I can remove to clean it up a little, and if theres anything else I could to do improve it.

    Thanks,
    TJ

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    PS, if anyone wants to thow this over to T shirt booth/GShelper, maybe he can make an updated video on this, maybe as an alternate method for swiping.

    Oh and Im gonna repeat myself in saying that this really should become a built in feature in gamesalad.

    Thanks again,
    TJ

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148
    edited April 2015

    Hate to bring this thread back from the dead but I have a problem where when I start the test screen the actors just wont accept any swiping input for like 4-5 seconds or so. Im swiping in all directions and nothing happens and then after a few seconds it starts working. Is this just the tester being slow?? How can I prevent this?

    Also, I have it set up so that when a swipe is happening, it activates a self attribute in the actor that the swipe is currently affecting, and that self attribute stays on forever. Once that attribute is activated the actor is supposed to move to some coordinates at a speed of 500 (run to completion) and then after 0.5 seconds it is supposed to move to another set of coordinates at a speed of 2000. But the problem is sometimes the actor will just go off the screen to the left or the right (which ever direction it of the coordinates it was supposed to go to), and then either comes back to the coordinates it was supposed to go to in the first place really quickly then performs going to the second set of coordinates at the 2000 speed (this is more common), or it goes off screen to the left or the right again in the direction of the coordinates its moving to and a full second later comes back moving in the opposite direction and goes off screen on the other side and never comes back.

    Now because this happens on occasion under different circumstances every time, this leads me to believe that its not an actual error in the code but rather Gamesalad just running weirdly sometimes. But I'd really like to figure this out.

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    Anyone have any solutions to this or have similar oddities happen in their games?

Sign In or Register to comment.