How to pan the camera like COC

K

krugen

Guest
In clash of clan, you can

1) drag past the village for a finite distance. And the further you go into that finite distance, the harder it seems to pull further.
2) once you reach the limit, the view will bounce slightly back into the village but not all the way back to the limit.

village size is 640 x 360
extra area for the effect result in total: 660 x 380
when u reach 660 or 380 or both, the screen will bounce back in the opposite direction for 10 px once you release the finger

How to achieve that kind of panning for programming mobile? Assume there is no zooming available.
 

NightFrost

Member
Off the top of my head:

When you drag the view, if any view edge is closer to corresponding room edge than a set amount (in your case, 10 pixels), and movement is towards that room edge, the actual amount moved is made a function of the difference between view edge position and room edge position. In other words, when they are the same, the amount moved will be zero.

When dragging is not happening, if any view edge is closer to corresponding room edge than a set amount (again, 10 pixels), the view edge is moved away from that room edge by an amount that is a function of the difference between view edge position and room edge position, subtracted from one. In other words, if the difference is 10 pixels or over, the necessary movement evaluates to zero.
 
Top