0

I am following this great Smooth line drawing tutorial for my game, http://www.merowing.info/2012/04/drawing-smooth-lines-with-cocos2d-ios-inspired-by-paper/#.U1kiCJG6_Ez

My problem is that I can't get collision of line.

user3564985
  • 3
  • 1
  • 2

2 Answers2

1

If your line is a list/array of multiple line segments (which is the case for the tutorial link), As new line objects are added, check against all previous segments in your array for intersection.

This can be done rather easily, as there are multiple solutions on stackoverflow on how to detect line intersection.

Community
  • 1
  • 1
Reza Shirazian
  • 2,303
  • 1
  • 22
  • 30
  • thanks for reply ok i think i need to learn it first how to put all objects in array and update it to check intersection against first object .thanks – user3564985 Apr 26 '14 at 10:18
0

In the example code, everything is just rendered on the screen. No part of a collision detection system is implemented.

For implementing one of those, one of the simplest ways is to put all the points that make up the line in an NSMutableArray, and every time you want to draw a new point, you can check it against all the points contained in the array. If the new point is already contained in the array, then you have a collision between the line and the new point you are trying to draw.

From there on, you can research standard collision systems, and implement one of those. Cocos2D also supports 2 physics engines: Box2D and Chipmunk, both of which have collision detection of their own. For efficiency, you might want to use one of those instead of implementing your own system.

iajheyst
  • 214
  • 3
  • 6