gpt4 book ai didi

ios - Cocos 2d画线不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:20:27 28 4
gpt4 key购买 nike

我想在 cocos 2d 中用手指触摸画线。

-(void) ccTouchesMoved:(NSSet *)inappropriateTouches withEvent:(UIEvent *)event
{
UITouch *touch = [inappropriateTouches anyObject];

CGPoint currentTouchArea = [touch locationInView:[touch view] ];
CGPoint lastTouchArea = [touch previousLocationInView:[touch view]];

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);

glColor4f(0.8, 1.0, 0.76, 1.0);
glLineWidth(6.0f);
ccDrawLine(currentTouchArea, lastTouchArea);
}

我使用此代码,但屏幕上没有绘制任何内容。我的代码有什么问题?

最佳答案

所有你想在draw方法中做的OpenGL绘图。像这样:

-(void)draw
{
if(lastTouchArea != 0)
{
glColor4f(0.8, 1.0, 0.76, 1.0);
glLineWidth(6.0f);
ccDrawLine(currentTouchArea, lastTouchArea);
lastTouchArea = 0;
}
}

关于ios - Cocos 2d画线不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8076503/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com