I'm trying to create a destroyable world with Cocos2D and I did some reading on the subject, but I can't really figure out how to get it working properly.
I have a very simple test at the moment; the screen is black and a touch will draw a white circle on the touched location with CCRenderTexture.
This is my test:
// 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];
}
I add a sprite after adding the black background:
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];
Is there an easy method to check if the sprite is on a black/white area with some kind of pixel collision check?
I've seen this question before, but the answer always was something like: "Just check with a simple black/white image if it's on the black or white area", ok, but how? :P
Thank you,
Rick