您可以讓我知道什麼是使用Cocos2d ios4 iphone在場景圖層上繪製線條或矩形的最佳方式。在cocos2d上畫線或矩形圖層
到目前爲止,已經嘗試過Texture2d,但它更像是一把油漆刷,並不是很好。嘗試使用繪製方法繪製線條,但上一行在繪製另一條線時消失。
基本上想繪製多個水平,垂直,斜梁。請建議。任何代碼都會有很大幫助。
使用紋理繪製的代碼如下:
CGPoint start = edge.start;
CGPoint end = edge.end;
// begin drawing to the render texture
[target begin];
// for extra points, we'll draw this smoothly from the last position and vary the sprite's
// scale/rotation/offset
float distance = ccpDistance(start, end);
if (distance > 1)
{
int d = (int)distance;
for (int i = 0; i < d; i++)
{
float difx = end.x - start.x;
float dify = end.y - start.y;
float delta = (float)i/distance;
[brush setPosition:ccp(start.x + (difx * delta), start.y + (dify * delta))];
[brush setScale:0.3];
// Call visit to draw the brush, don't call draw..
[brush visit];
}
}
// finish drawing and return context back to the screen
[target end];
渲染不好ESP。斜線會影響質量。
乾杯
你看了繪圖原型的例子嗎? – xuanweng 2011-03-17 03:36:39
是的,但只能畫一條線。畫另一個使它鬆動了前一行。整個繪圖是否應該在繪製方法中一次重做? – MountainRock 2011-03-17 10:23:13
是的..你需要一個數組來存儲所有的位置的線..所以在繪製方法,它通過數組循環,並獲得所有的位置繪製.. – xuanweng 2011-03-18 03:44:51