CCSprite with rounded corners - ios

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?

Related

cocos2d v3: physicsBody of a CCSprite is positioned incorrectly

I'm very new to cocos2d development.
What I am trying to implement is some sprite nodes with physics bodies. As far as I understand, you're supposed to add them to the scene like this ("physics" here is the name of CCPhysicsNode declared earlier):
[physics addChild:node];
instead of
[self addChild:node];
The second one is pretty self-explanatory, I never had any trouble with it. But with the first the position of collision shapes does not match the position of the actual sprite (as seen in debug drawing, and by offset I mean greatly offset, like 2x the actual position). This is how I declare and add the node:
CCSprite *sprite = [CCSprite spriteWithImageNamed:#"sprite.png"];
sprite.position = position;
sprite.physicsBody = [CCPhysicsBody bodyWithRect:[sprite boundingBox] cornerRadius:0];
sprite.physicsBody.collisionType = #"SomeCollisionType";
sprite.name = #"Name";
[physics addChild:sprite];
What am I doing wrong? Please explain me how to make the positions match. TIA.

Get position of CCSprite

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];

How to set blink on CCSprite image?

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]];

Cocos2D: how to tweak CCMenuItem with only one sprite?

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){}];

UIImageView cornerradius and CGrect

I am making a game where you touch a ball and have to pass some bars. However the ball must not touch those bars. The ball is a gif-image. My problem is: The ball is a circle but the uiimageview is a square. If the corners of the uiimageview (which is not the ball image) touch the bars it says that the ball touches the bar. even if I do that
// imageMover is the UIImageView
// the radius of the ball is 30.0
[[imageMover layer] setMasksToBounds:YES];
[[imageMover layer] setCornerRadius:30.0f];
there is no change. I think i need a rounded frame (CGRect) but how do you "create" a rounded frame?
try this
imageMover.layer.shouldRasterize = YES;
imageMover.clipsToBounds = YES;
imageMover.layer.cornerRadius = 10.0f; // what number you want
you cannot creat a rounded frame.
but you can create an UIImageView with rounded corners.
Import the QuartzCore (#import ) header and play with the layer property of the UIImageView.
imageMover.layer.cornerRadius = yourRadius;
imageMover.clipsToBounds = YES;
see the CALayer class reference for detail:
https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html
thanks!

Resources