How do I simulate a finger swipe?

0 favourites
  • 14 posts
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • Please keep in mind that I'm an absolute beginner with game development, and so thoroughly "right-brained" that I lean to one side when walking. I'm struggling to figure out how to simulate a finger swipe on a square sprite in the center of my layout. After two hours of tutorials and forum posts, here's what I thought would work, but no luck. any help would be appreciated.

    Tagged:

  • So how do you want it to work? You touch the sprite, swipe right and the sprite should fly to the right?

    You need to tell more about your game, because there are many ways to do this.

  • Usually i do this by checking the angle.

    You need to create a couple of variables.

    TouchStartX

    TouchStartY

    TouchEndX

    TouchEndY

    TouchAngle

    or something similar. When touch starts you save the XY position, when Touch Ends, you save the Touch end coordinates. Then you check the save that angle from start to finish position.

    When you have the angle from start to finish, you can check if the angle is between certain values, it would count as either up, down, left or right swipe.

    At least that's the basic idea, i don't have any clean project with only that, but hopefully it's enough to get you going.

  • I put together a quick little project for you.

    https://www.dropbox.com/s/lwoo2tu9v8ide5l/touchSwipe.c3p?dl=1

    Hope that helps :)

    Added some comments as well to help you understand how it works.

  • So how do you want it to work? You touch the sprite, swipe right and the sprite should fly to the right?

    You need to tell more about your game, because there are many ways to do this.

    This concept animation will explain the game much more concisely than I can. I'm trying to figure out the very basics of what I need to do, and then "baby-step" my way through the project.

    dropbox.com/s/ld932vawlrfe4zd/GameConcept.key

  • I don't have a Mac and can't open your presentation.

  • Sorry about that. Here's a .mp4 file that's a bit choppy but it should give you the idea.

    dropbox.com/s/cpluh0iupc9k2dl/GameConcept.mp4

  • This is not an easy task..

    Firstly, you probably need Drag&Drop behavior here, not swipe gestures. On the video the hand grabs the letter and then drags it several rows/columns. With gestures you will only be able to slide letters one cell at a time. For example, to move the letter 3 cells up, you will need to swipe it 3 times.

    So when dragging starts, you need to detect its direction (horizontal or vertical), lock this direction, and then move the entire row or column. On drop you need to snap letters to the nearest cell.

    Another tricky part is wrapping the letters. As a letter disappears on one side of the board, the same letter should reappear at the other side. You need to create a copy of this letter sprite, or maybe a copy of the entire row/column.

    Anyway, this is a pretty complex mechanics, not something that can be done in 20 minutes.

  • I was hoping it would be simple. In your opinion, is Construct 3 going to be the least difficult of the game engines to work in? My plan is to build a test model with a 3 x 3 grid of letter tiles. I'll use your suggestions and see if I can figure it out.

    Do you know of a tutorial that might demonstrate similar tile movement or wrap function?

  • When you use construct you think dont need any code , but its not ! a simple touch gestures needs to code maybe later scirra make a behaviour for that !

    When you use simulate control if you touch on scren outside of the istance the instance move and that is bad

    I did a Swipe menu that move the Menu Up and Down , there are 3 methods and the first works better , you can studie it and implement in your game if you want to move in other directions

    dropbox.com/s/kshhlrzfkjzdzsx/SwipeMenuWorking.c3p

    I

  • I was hoping it would be simple. In your opinion, is Construct 3 going to be the least difficult of the game engines to work in?

    It's not a terribly difficult task, but it will definitely be time consuming. I don't think it will be any easier in other game engines.

    Here is a quick and basic demo with swipes:

    dropbox.com/s/ne9lw2f112ahk31/SwipeLettersGame.c3p

    Dragging and proper wrapping will require more work.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Your demo got me very excited! I've been studying the demo and trying to apply it to a 3x3 grid of my alphabet tiles.

    I have a few questions: are the columns and rows in your demo moving in unison because they are all basically duplications of a single sprite? And also, If I'm using nine unique sprites for my 3x3 grid, is there a way to establish collision behavior to "push" the rows and columns of alphabet tiles?

    I'm very appreciative of your help. I'm determined to figure this out, regardless of how much time will be consumed. I've already spent a laughable amount of time getting to this point!

  • And also, If I'm using nine unique sprites for my 3x3 grid..

    This is a very wrong approach, don't do it! Use a single sprite with 26 animation frames (or animations) for letters. Copy this sprite 9 times to make 9 instances of this sprite, and place them in a grid. Again, all 9 instances should belong to the same one Sprite object!

    Also, the only behavior that can push multiple objects like this is Physics, and I really don't recommend using Physics here.

    Do what I did in my demo:

  • Maybe my video on how to make a 2048 type of game might help here?

    youtu.be/Fr52zATpvok

    cheers!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)