Pinned sprites after wrap have an unwanted offset

Get help using Construct 2

Post » Tue Oct 14, 2014 1:26 am

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?
You do not have the required permissions to view the files attached to this post.
B
10
S
1
Posts: 67
Reputation: 909

Post » Tue Oct 14, 2014 4:03 am

How are you doing the wrapping?

Edit:
I'm guessing you may be doing something like this for the wrapping:
Code: Select all
Sprite x > 640
--- Sprite: set x to 0

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: Select all
Sprite x > 640
--- Sprite: set x to self.x-640
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Tue Oct 14, 2014 5:17 am

@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.
You do not have the required permissions to view the files attached to this post.
B
10
S
1
Posts: 67
Reputation: 909

Post » Tue Oct 14, 2014 6:32 am

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.
https://dl.dropboxusercontent.com/u/542 ... g_pin.capx

Another is to not use the pin behavior and do it in events. If anything it gives more control.
https://dl.dropboxusercontent.com/u/542 ... _drag.capx

Edit:
The for eaches and events 4,5,7 & 8 are for the visual wrapping of tiles.
B
92
S
32
G
106
Posts: 5,273
Reputation: 69,457

Post » Tue Oct 14, 2014 6:02 pm

@R0J0hound - Omg, that's amazing!!!! It works perfectly and it cut out 8 events. Thank you so much!!! :D
B
10
S
1
Posts: 67
Reputation: 909

Post » Wed Nov 19, 2014 1:32 am

@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!!

Edit:
Resolved by me! Thanks anyway ;)
Last edited by Aelfraed on Thu Nov 20, 2014 7:52 pm, edited 2 times in total.
B
22
S
2
G
4
Posts: 30
Reputation: 3,602

Post » Wed Nov 19, 2014 10:14 am

iwontnamemyself our Rogohound is not just pretty face he has big heart too
B
249
S
39
G
15
Posts: 1,953
Reputation: 40,598


Return to How do I....?

Who is online

Users browsing this forum: Exabot [Bot], Lancifer, nahima and 13 guests