cocos2d 2.0 と Xcode 4.5 を使用しています。線の引き方を勉強中です。線を引くことはできますが、いくつかの線を引いた後、シミュレーターで重大なパフォーマンスの問題が発生します。
シミュレーターがフリーズし始め、線の描画が非常に遅くなり、最悪の場合、-(void)draw
フレームごとに呼び出されるため、画面上のラベルが太字になると思います
行の前:
行の後;
次のコードを使用します:.m
-(id) init
{
if( (self=[super init])) {
CCLabelTTF *label = [CCLabelTTF labelWithString:@"Simple Line Demo" fontName:@"Marker Felt" fontSize:32];
label.position = ccp( 240, 300 );
[self addChild: label];
_naughtytoucharray =[[NSMutableArray alloc ] init];
self.isTouchEnabled = YES;
}
return self;
}
-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
BOOL isTouching;
// determine if it's a touch you want, then return the result
return isTouching;
}
-(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [ touches anyObject];
CGPoint new_location = [touch locationInView: [touch view]];
new_location = [[CCDirector sharedDirector] convertToGL:new_location];
CGPoint oldTouchLocation = [touch previousLocationInView:touch.view];
oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation];
oldTouchLocation = [self convertToNodeSpace:oldTouchLocation];
// add my touches to the naughty touch array
[_naughtytoucharray addObject:NSStringFromCGPoint(new_location)];
[_naughtytoucharray addObject:NSStringFromCGPoint(oldTouchLocation)];
}
-(void)draw
{
[super draw];
ccDrawColor4F(1.0f, 0.0f, 0.0f, 100.0f);
for(int i = 0; i < [_naughtytoucharray count]; i+=2)
{
CGPoint start = CGPointFromString([_naughtytoucharray objectAtIndex:i]);
CGPoint end = CGPointFromString([_naughtytoucharray objectAtIndex:i+1]);
ccDrawLine(start, end);
}
}
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
ManageTraffic *line = [ManageTraffic node];
[self addChild: line z:99 tag:999];
}
Flight Controlなどの Air Traffic Control ゲームはほとんど見たことがありませんが、ATC Maniaは非常にうまく機能します。
このパフォーマンスの問題CCDrawLine/UITouch *touch
は、一般的な問題が原因で発生しますか? ATC Maniaが線画に使用しているかもしれないFlight Control は何ですか?
前もって感謝します。
編集::::
OK問題はccDrawLineではないと思います。問題は、ManageTraffic *line = [ManageTraffic node];
タッチが終了するたびinit
にノードを呼び出すため、シーンをオーバーライドすることです
- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
ManageTraffic *line = [ManageTraffic node];
[self addChild: line z:99 tag:999];
}