neztreh
neztreh

Reputation: 4241

Cocos2d image masking

I'm currently working on game where the main character rides on a ship and when an enemy is parallel to the ship, it drops a tube. My main problem is the tube is bigger than the ship so it is visible from behind while it is going down or up. Please note that the image (the ship) on top of the tube is a transparent image. Thanks! enter image description here enter image description here enter image description here

Upvotes: 1

Views: 228

Answers (2)

user2004159
user2004159

Reputation:

I think you have to manage two tube image ,one is big and other is small, which is fit to your ship. you have to change tube image when you drops this tube. to change tube image you use this code

CCTexture2D* tex = [[CCTextureCache sharedTextureCache] addImage:@"blast.png"];
            [player setTexture: tex];

here player is CCSprite.

CCSprite *player;

Upvotes: 0

aronspring
aronspring

Reputation: 276

You can clip draw regions in Cocos2d without too much effort. If you add this code to the tube object then you can define a suitable region to draw the object. Anything outside of this rectangle doesn't get drawn.

-(void) visit
{
if(!self.visible)
    return;

glEnable(GL_SCISSOR_TEST);

CGRect thisClipRegion = _clipRegion;
thisClipRegion = CC_RECT_POINTS_TO_PIXELS(thisClipRegion);

glScissor(thisClipRegion.origin.x, thisClipRegion.origin.y, thisClipRegion.size.width, thisClipRegion.size.height);

[super visit];

glDisable(GL_SCISSOR_TEST);
}

Upvotes: 1

Related Questions