起亚奥拉。无聊迫使我就这个话题提供一个答案。
图层部分(即 @interface GetMyTouches : CCLayer):
-(void) ccTouchesMoved:(NSSet *)inappropriateTouches withEvent:(UIEvent *)event
{
UITouch *touchMyMinge = [inappropriateTouches anyObject];
CGPoint currentTouchArea = [touchMyMinge locationInView:[touchMyminge view] ];
CGPoint lastTouchArea = [touchMyMinge previousLocationInView:[touchMyMinge view]];
// flip belly up. no one likes being entered from behind.
currentTouchArea = [[CCDirector sharedDirector] convertToGL:currentTouchArea];
lastTouchArea = [[CCDirector sharedDirector] convertToGL:lastTouchArea];
// throw to console my inappropriate touches
NSLog(@"current x=%2f,y=%2f",currentTouchArea.x, currentTouchArea.y);
NSLog(@"last x=%2f,y=%2f",lastTouchArea.x, lastTouchArea.y);
// add my touches to the naughty touch array
naughtyTouchArray addObject:NSStringFromCGPoint(currentTouchArea)];
naughtyTouchArray addObject:NSStringFromCGPoint(lastTouchArea)];
}
节点部分(即@interface DrawMyTouch:CCNode):
@implementation DrawMyTouch
-(id) init
{
if( (self=[super init]))
{ }
return self;
}
-(void)draw
{
glEnable(GL_LINE_SMOOTH);
for(int i = 0; i < [naughtyTouchArray count]; i+=2)
{
start = CGPointFromString([naughtyTouchArray objectAtIndex:i]);
end = CGPointFromString([naughtyTouchArray objectAtIndex:i+1]);
ccDrawLine(start, end);
}
}
@end
层第二部分(即 @interface GetMyTouches : CCLayer):
-(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
DrawMyTouch *line = [DrawMyTouch node];
[self addChild: line];
}
请记住,触摸很容易。了解触摸时自己在做什么并不是什么复杂的事情。
最后,如果你不明白我发布的任何内容……开始烘焙吧。世界需要更多的巧克力蛋糕生产商。
澄清:
- 没有人吸取教训剪切和粘贴 ~ this code从来不打算在没有爱抚的情况下工作
- 如果你看不出其中的幽默感,那你就入错行了
值得注意的是,我喜欢美味的巧克力蛋糕。这个世界确实需要更多出色的面包师。这不是侮辱,而是鼓励。
“看看方形外面,找到充满知识的圆圈,让生活变得有价值”〜埃内西德姆斯。