2014년 12월 2일 화요일

Stop your Dragged sprites from sticking together!

When dragging a Ball or ImageSprite on a canvas, it may 'grab' another sprite or become hidden behind another sprite.
Then both sprites will be dragged together and cannot be separated.
This is due to each sprite's Dragged block executing it's blocks as though it is the only sprite being dragged.
So the problem is that one sprite does not 'know' if another sprite is already being dragged.
This workaround solution enables your app to keep track of the first sprite that is dragged and it ignores any other sprites that the 'control' sprite may pass over.
See the YouTube video explanation of how this works here.




An alternate solution popped into my head while I watched your Vid.  No testing is required if you use a third sprite to capture the drag event. You don't even have to move the 3rd sprite. It should be a simple ball sprite with the PaintColor set to 'None'.
 If the app has no other purpose for the Canvas.drag event, the ball sprite might be eliminated. However, you may have to handle dragging the canvas when a not a sprite is not touched. 



Very clever :)



Scott, I know it's been a while since this you posted this, but I wanted to thank you for the tip. This helped me with a problem that caused me countless headaches months previous, lol. You guys are really awesome :)


댓글 없음:

댓글 쓰기