我试图创建一个的cocos2d销毁的世界,我做了一些关于这个问题的阅读,但我真的不能弄清楚如何得到它的正常工作。黑白色(像素),请与Cocos2D中
我目前所面对的一个非常简单的测试;屏幕为黑色和触摸将借鉴与CCRenderTexture触摸位置的白圈。
这是我的测试:
// Get the black background
- (CCSprite *)sprite
{
CGSize winSize = [CCDirector sharedDirector].winSize;
self.renderTexture = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height];
[self.renderTexture beginWithClear:0.0 g:0.0 b:0.0 a:1.0];
[self.renderTexture end];
return [CCSprite spriteWithTexture:self.renderTexture.sprite.texture];
}
- (void)generateBackground
{
background = [self sprite];
CGSize winSize = [CCDirector sharedDirector].winSize;
background.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:background z:-1];
}
// Draw the white circle
- (void)generateExplosionWithTouch:(UITouch *)touch
{
[self.renderTexture begin];
CGPoint location = [touch locationInView:touch.view];
location = [self convertToNodeSpace:location];
ccDrawCircle(location, 30.0, 5.0, 360, NO);
[self.renderTexture end];
}
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
[self generateExplosionWithTouch:touch];
}
我加入黑色背景后面添加一个精灵:
CGSize winSize = [CCDirector sharedDirector].winSize;
self.icon = [CCSprite spriteWithFile:@"Icon.png"];
self.icon.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:self.icon];
有一种简单的方法来检查精灵是一个黑色/白色区域与某种像素碰撞检查?
我以前见过这个问题,但答案始终是这样的:“只要用一个简单的黑/白图像检查它是否是在黑色或白色区域”,确定,但如何? :P
谢谢
里克
好的,我会做教程:)顺便说一下,我从CCRenderTexture atm创建一个精灵?哦,谢谢:) – 2012-08-11 10:18:28
你是正确的关于精灵,你是从质感创造它;不知何故,我错过了CCSprite初始化...... – sergio 2012-08-11 10:26:13