Pinned sprites after wrap have an unwanted offset

0 favourites
  • 7 posts
From the Asset Store
Build your map with these isometric objects and terrains
  • I have an 8x8 grid full of sprites. When the user swipes the screen, the sprites in the row or column the user swiped get pinned to a clear sprite that uses drag drop. As this sprite is moved on the appropriate axis, the sprites below move with it. Once one of the pinned sprites reaches the edge of the board, it is unpinned and wraps to the other side and is re-pinned to the clear sprite and begins moving with the rest of them again.

    The problem is, when the swipe is somewhat fast, the sprites get pinned further down on the clear sprite, so there are random sized spaces between the sprites and sometimes they overlap each other.

    Does anyone know how to fix this?

  • How are you doing the wrapping?


    I'm guessing you may be doing something like this for the wrapping:

    Sprite x > 640
    --- Sprite: set x to 0 [/code:2rkaazyg]
    So if moving slow sprite.x will be just past 640, but if fast then sprite.x may be way over 640.  The point is anything over 640 is discarded.
    So to keep the extra don't set x to 0, rather subtract 640 from it.
    [code:2rkaazyg]Sprite x > 640
    --- Sprite: set x to self.x-640 [/code:2rkaazyg]
  • R0J0hound - It's actually a masking system. I didn't like how the sprites couldn't be in 2 opposing sides of the grid at the same time. This way it looks like the sprite is in 2 places at once.

    I've tried including an offset, like you suggested, but it still shows uneven gaps between the spawned sprites. I thought it had something to do with the amount of time it takes for the function to end and the pin action to trigger, but even when I tried putting a pin action in this function and it still did the same thing.

    Is there any way to set the max speed of a Touch gesture? Maybe to allow a swipe to move the sprites up to a certain speed, but if there's a swipe that's faster, it still only moves the sprites at the speed defined?

    I tried using lerp and, which slows it down, but if you giggle the swipe back and forth fast, it screws the entire selection up.

  • The issue is when the pin behavior is run. The basic loop is:

    pre tick behaviors -> events -> post tick behaviors -> draw -> repeat

    "drag n drop" is "pre tick" and "pin" is "post tick" so the pinned object's positions won't be updated from the dragging object until after the event sheet.

    One solution is to keep track of the change of position of the dragging object and adding that to the position when you wrap. ... g_pin.capx

    Another is to not use the pin behavior and do it in events. If anything it gives more control. ... _drag.capx


    The for eaches and events 4,5,7 & 8 are for the visual wrapping of tiles.

  • R0J0hound - Omg, that's amazing!!!! It works perfectly and it cut out 8 events. Thank you so much!!!

  • R0J0hound your capx examples are very useful!

    if instead of drag n drop we put two buttons, one to move the row a step to the right at each touch and one to move the row a step to the left at each touch, how the capx will be? please can you change both the previous examples with this new condition of moving? thanks in advance!!


    Resolved by me! Thanks anyway

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • iwontnamemyself our Rogohound is not just pretty face he has big heart too

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