How do I most efficiently move a sprite on a grid/tile with swipe?

0 favourites
  • 4 posts
From the Asset Store
This is a code so you can see the same skin on all screens (peers). Each peer gets a skin, in addition to 4 directions t
  • First off, I do already have this working, but starting to think I did it the long way. I'm currently tracking the start and end coordinates of a swipe, compare it to the coordinates of my grid rows and determine what direction the swipe is.

    After some looking around at behaviors, I noticed tile movement and was wondering if I should have been using that all along or if there is even another easier way to do this.

    In my project, I have a four by four tile grid and when I touch a tile piece, and swipe (up, down, left, right only, not 8 direction) I want the touched tile to move onto the next tile in that direction.

    What is the cleanest, least amount of conditions, easiest way to do this?

    Thanks!

  • When a tile is touched (and not already moving), set an instance variable on this tile, for example "isReadyToMove=true".

    Then when the screen Is In Touch and there is a tile which is ready to move, compare Touch.speedAt(0) and Touch.angleAt(0). For example, if Touch.speedAt(0)>100, then start moving the tile in Touch.angleAt(0) direction, rounded to 90 degrees.

    When the tile starts moving or has arrived, and when any touch has ended, clear the isReadyToMove flag.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, will try this out shortly.

    For the movement, should I use bullet behavior?

  • If you need the sprite to move precisely to another tile, use MoveTo or TileMovement behaviors.

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