0 Favourites

Drag and drop tile puzzle

  • Hey guys, I've created a drag-and-drop sliding tile puzzle minigame that I'm setting within a larger RPG level. It is mostly functional, however, I have run into a behaviour that seems to occur somewhat randomly that breaks it. I'll explain my workflow:

    -----------------------------

    I first created an invisible grid on Layer 0 with placeholders 1 through 9 ("Place1" to "Place9"):

    [attachment=0:17s4v5m0][/attachment:17s4v5m0]

    I then inserted my image as a sliced sprite animation set (speed set to 0) and scrambled it on the grid on Layer 1:

    [attachment=2:17s4v5m0][/attachment:17s4v5m0]

    I put together code which does the following:

    -Assigns each piece of the image a number (as an instance variable) according to which tile it is currently on (every tick).

    -Checks each piece (on DragDrop > Drop) firstly which piece it is (according to the variable), and secondly where it can be placed.

    -This is done by checking firstly whether that piece is overlapping a particular "Place#" on the grid, and also if that particular "Place#" is empty (with a variable 1 or 0), and then setting its position to the x and y coordinates of that grid place. In the same event I include actions to set the destination place to "Full", and the source to "Empty".

    -An else statement underneath the possible locations sends the tile piece back to its origin (in the case it is dropped in an invalid space).

    -I also have code regarding winning conditions, but they don't concern me right now.

    -----------------------------

    Here's my problem:

    When I move two or three tiles, everything seems to be working fine. Then I will try to drop another tile on an empty space, and it springs back to it's origin. This might be fine (assuming it just hadn't overlapped properly or something), but it also seems to set the "Full" variable of the destination to 1 (on), even though it has sprung back to the origin. With the empty space "Full", no tiles are allowed to move there, and the game is broken.

    My code is attached, if anyone can help me reorganise it to solve this issue, I would be stoked.

  • Seriously guys, if I could get some feedback on this soon I might be able to move on with the rest of my level. Any help would be hugely appreciated.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Well in case anyone else has the same problem, I have solved this.

    There needs to be an 'else' statement attached to each of the sub-sub-event branches of the "on-drag drop" event.

    e.g.

    - 14 - Circuits | Is overlapping Place2

    Place2 | Full = 0

    - 15 - [System] | [ Else]

    Circuits | Is overlapping Place5

    ....

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