I want to set blink on my CCSprite in Cocos2D.
How to set blink in Cocos2d ??
Try this...
CCSprite * m_Sprite = [CCSprite spriteWithFile:#"sprite.png"];
[m_Sprite runAction:[CCBlink actionWithDuration:1 blinks:5]];
Related
I can clip using native coding within iOS however, as I wish to port across to Android using SpriteBuilder I want to clip 2 CCSprites using Cocos2D.
I am looking to do the following :
I have seen libraries which support only Cocos2D 2 however I am using the latest version and these no longer seem to work.
How would I achieve this affect?
For anyone looking for a similar fix the following is native to Cocos2D.
//Get Screen size
CGSize winSize = [[CCDirector sharedDirector] viewSize];
//Set Clipping Sprite
CCSprite *heroClip = [CCSprite spriteWithImageNamed:#"stamina/MenuHappinessWhite.png"];
heroClip.position = ccp(winSize.width/2, winSize.height/2); // Middle of screen
//Set Sprite below Clipping
CCSprite *heroUnder = [CCSprite spriteWithImageNamed:#"stamina/MenuLevel.png"];
heroUnder.position = ccp(winSize.width/2, winSize.height/2);
heroUnder.scaleY = 0.5f;
// Create Clipping Node
CCClippingNode *scissor = [CCClippingNode clippingNodeWithStencil:heroClip];
[scissor setContentSize:self.contentSize];
[scissor setPositionType:CCPositionTypeNormalized];
[scissor setAlphaThreshold:0.0];
//[scissor setInverted:YES];
[self addChild:scissor];
// Add nodes to Clipping Node
[scissor addChild:heroUnder];
and add this to app delegate
//Load Clipping Mask
[cocos2dSetup setObject:#GL_DEPTH24_STENCIL8_OES forKey:CCSetupDepthFormat];
Im a bit confused. I am trying to move one CCSprite onto the position of another CCSprite. I figured it would be simple, but the CCSprite isn't positioning correctly. I have 2 CCSprites:
//Get Position of EMPTY SPRITE
CCSprite *sprite = (CCSprite*)[self getChildByName:[NSString stringWithFormat:#"%d", kEMPTY] recursively:NO];
//GET DRAGGED SQUARE
CCSprite *spriteMove = (CCSprite*)[self getChildByName:[NSString stringWithFormat:#"%d", DragStartSquare] recursively:NO];
I am then trying to get the position of the EMPTY SPRITE (Its not actually empty) by doing
CGPoint worldCoord = [sprite convertToWorldSpace: sprite.position];
I am then animating it with:
id action1 = [CCActionMoveTo actionWithDuration:duration position:worldCoord];
This sends the sprite off the screen. What am I doing wrong?
You need to convert back into the target sprite's node space:
CGPoint targetNodeCoord = [spriteMove convertToNodeSpace: [sprite convertToWorldSpace: sprite.position]];
CCAction *action1 = [CCActionMoveTo actionWithDuration:duration position:targetNodeCoord];
I have this code:
CCSprite * monster = [CCSprite spriteWithCGImage:_imgInimigo.image.CGImage key:#"inimigo"];
I want to add rounded corner in this CCSprite. Its possible? How?
how could I tweak CCMenuItemSprite to support only one sprite?
Currently I have:
[CCMenuItemSprite itemWithNormalSprite:one selectedSprite:selectedOne]
But would like to have:
[CCMenuItemSprite itemWithNormalSprite:one]
EDIT: I want to modify CCMenuItem to work only with one CCSprite and not two. So I need to change also the internal methods.
You can just use the same (normal) sprite as the selected sprite. When clicked, the button will then do nothing.
You could just use
[CCMenuItemSprite itemWithNormalSprite:one selectedSprite:one]
this way, nothing would happen when you select the sprite
try this, just change colour of seleted sprite.
CCSprite *sprite1 = [CCSprite spriteWithFile:#"Button.png"];
CCSprite * sprite2 = [CCSprite spriteWithFile:#"Button.png"];
sprite2.color = ccc3(128, 128, 128);
CCMenuItemImage *itemEasyLevelImage = [CCMenuItemImage itemWithNormalSprite:sprite1
selectedSprite:sprite2
block:^(id sender){}];
So I'm making a game, and in this game I need to have a certain sprite to appear multiple times.
It's simply an image, with two buttons. One button underneath the image, and one above.
I am using Cocos2d, so any mention of sprite will be the CCSprite class. And the image is actually just a line.
Is there an easy way to implement something like this? I don't want to have to make a separate sprite for the image, and then add each button. Is there a way I can do this all in one sprite?
I'm assuming that I'll probably have to manually add everything (create a method that will create an image and position the buttons relative to the image), but I'm hoping I'm wrong and there is an easier/more efficient way of doing this.
Thanks!
I think you are looking for CCMenuItem and CCMenu
CCSprite *enabledSprite = [CCSprite spriteWithFile:#"myButtonSprite.png"];
CCSprite *selectedSprite = [CCSprite spriteWithFile:#"myButtonSprite.png"];
CCSprite *disabledSprite = [CCSprite spriteWithFile:#"myButtonSprite.png"];
CCMenuItemSprite *item [[[CCMenuItem alloc] initWithNormalSprite:enabledSprite
selectedSprite:selectedSprite
disabledSprite:disabledSprite
target:delegate
selector:selector] autorelease];
item.position = ccp(240, 160);
CCMenu *menu = [CCMenu menuWithItems:item, nil];
menu.position = ccp(0, 0);
[self addChild:menu];