2

私はcocos2d/OpenGLESを初めて使用しますが、解決策が見つからない問題が発生しています。基本的に、CCRenderTextureでアンチエイリアス処理された円を描画し、そのテクスチャを複数のスプライトで使用します。アンチエイリアスの部分以外はすべて単純ですが、行き詰まっていて、次にどこに行くべきかわかりません。

私が今持っているコードは次のとおりです。

int textureSize = 64;
CCRenderTexture *rt = [CCRenderTexture renderTextureWithWidth:textureSize height:textureSize];
[rt beginWithClear:spriteColor.r g:spriteColor.g b:spriteColor.b a:0.0f];

ccDrawColor4F(spriteColor.r, spriteColor.g, spriteColor.b, spriteColor.a);
ccDrawCircle(CGPointMake(textureSize / 2.0f, textureSize / 2.0f), textureSize / 2.0f, 0.0f, 360, false);

[rt end];

しかし、それはギザギザの混乱を招き、私はここからどこへ行くべきか理解できません。ポイントを使用して滑らかな円を描く例をオンラインで見ましたが、OpenGLES2.0では機能しないようです。

一度テクスチャに描画し、テクスチャを何度も再利用しているので、パフォーマンスはそれほど問題ではありません。

4

1 に答える 1

9

Core Graphics で円のテクスチャを作成し、CGImage としてテクスチャ キャッシュに追加します。Core Graphics は自動的にアンチエイリアシングを使用します。円はこのようになります。

サークル

サンプルコード:

//Setup Core Graphics
CGSize circleSize = CGSizeMake(100, 100);
CGPoint circlePosition = ccp(50, 50);
UIGraphicsBeginImageContextWithOptions(size, NO, [[UIScreen mainScreen] scale]);
CGContextRef context = UIGraphicsGetCurrentContext();

//Add the circle to the context and draw it.
CGContextAddArc(context, circlePosition.x, circlePosition.y , circleSize.width/2, 0,2*M_PI,1);
CGContextDrawPath(context,kCGPathStroke);

//Get an image so we can store it in the Texture Cache
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//Add the image to the texture cache
[[CCTextureCache sharedTextureCache] addCGImage:[img CGImage] forKey:@"circleKey"];

次に、を使用してスプライトを作成できます

CCSprite *circle = [CCSprite spriteWithTexture:[[CCTextureCache sharedTextureCache] textureForKey:@"circleKey"]];
于 2012-09-17T22:19:50.747 に答える