框架在Cocos2D中的renderTexture上设置

时间:2012-05-30 06:36:43

标签: ipad cocos2d-iphone

我是cocos2D的新手,我想在其中绘制线条,我试图从here

实现

我的框架设置有问题。我通过以下代码设置背景图片

CCSprite * background = [CCSprite spriteWithFile:imgPath rect:frame];

其中imgPath是设置为CCSprite的图像文件的路径,frame是视图边界。 CCSprite的框架没问题,现在我添加了

  [background addChild: [LineDrawingClass node]];

然后我使用以下代码剪辑向LineDrawingClass添加了一个CCRenderTexture实例

renderTexture.anchorPoint = ccp(0,0);
renderTexture.position = ccp(self.width * 0.5f,self.height * 0.5f);

然后我将renderTexture添加到LineDrawingClass

我得到的是CCSprite的背景设置为正确的框架,没有问题,但renderTexture的框架设置在CCSprite下方约5个像素。

我还将锚点设置为

renderTexture.anchorPoint = ccp(0.5f,0.5f);

但renderTexture的origin.y滞后。

请参阅附图以供参考。有人可以指出错误,并纠正我renderTexture的框架正好在CCSprite的框架上(现在是5px滞后的origin.y)??

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试将纹理的高度设置得稍微大一点,如果480是你的身高,请将其设置为580或更高,以符合您的要求。

renderTexture.position = ccp(self.width * 0.5f, (self.height + 100) * 0.5f);

它有一些方向性问题。