Cocos2D scale animation - cocos2d-iphone

I'm trying to do something pretty simple in Cocos2D and running into trouble. I would like to scale a CCNode with animation.
In the code below you will see what is happening
// load object of CCNode subclass GameOver
_gameOver = (GameOver*)[CCBReader load:#"gamePlayItems/GameOver"];
[self addChild:_gameOver];
_gameOver.positionType = CCPositionTypeNormalized;
_gameOver.position = ccp(.5, .75);
At this point the CCNode is on the screen at the proper position
//scale it up
_gameOver.scale = .2;
id scale = [CCActionScaleTo actionWithDuration:.8 scale:1];
CCActionEaseBackOut* bounce = [CCActionEaseBackOut actionWithAction:scale];
[_gameOver runAction:bounce];
The animation is never fired. The GameOver object is on the stage scaled to .2
Any suggestions would be greatly appreciated.
Thanks!

Related

Repeating Sprite Cocos2d 3.0

Im trying to make a scrolling affect in the background of my app
The sprite moves from north to south
This is successful but how can I repeat the sprite sprite to continuously do this? The sprite moves south and the end of the png file is seen, how could it be made that it repeats at this point so the sprite never ends? Thank you!
- (void) Buildings
{
rightBuilding = [CCSprite spriteWithImageNamed:#"rightBuilding.png"];
rightBuilding.positionType = CCPositionTypeNormalized;
rightBuilding.position = ccp(0.9f, 0.5f);
[self addChild:rightBuilding];
}
- (void) scrollBuildings:(CCTime)dt
{
rightBuilding.position = ccp(rightBuilding.position.x, rightBuilding.position.y - .5);
}

CCSprite Direction Cococs2d 3.0

How can i shoot the sprite "ink" straight up? The player Squiddy moves across the screen and i would like it to shoot the ink up, straight up, everytime. The code i have so far shoots the ink but it shoots it to a certain point on the screen
The code
CGPoint targetPosition = ccp(self.contentSize.width/2, self.contentSize.height/2 + self.contentSize.height);
ink = [CCSprite spriteWithImageNamed:#"MarioTube_Body_Rev.png"];
ink.position = Squiddy.position;
ink.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:ink.contentSize.width/2.0f andCenter:ink.anchorPointInPoints];
ink.physicsBody.collisionGroup = #"playerG roup";
ink.physicsBody.collisionType = #"projectileCollision";
CCActionRotateBy *actionSpin = [CCActionRotateBy actionWithDuration:.5f angle:360];
[ink runAction:[CCActionRepeatForever actionWithAction:actionSpin]];
[_physicsWorld addChild:ink];
CCActionMoveTo *actionMove = [CCActionMoveTo actionWithDuration:.75f position:targetPosition];
CCActionRemove *actionRemove = [CCActionRemove action];
[ink runAction:[CCActionSequence actionWithArray:#[actionMove,actionRemove]]];
As I said before, try to apply a force or impulse to ink.physicsBody:
CGPoint force = ccpMult(ccp(0,90), 600); //x=0, y=90, force=600
[ink.physicsBody applyForce:force];
With a value of x=0, the force will go up. Just play with the values.
Hope this helps

Cocos2d Box2d Scaling Radius Circle Bodies

Currently, in cocos2d, I have a an app that does the following:
Initiate with a Blank Screen.
When I tap the screen, I get a circle to pop-up. As I hold the circle, the circle will continue to grow at a constant rate. However, despite the fact that the sprite is growing, the box2d physical body isn't, which means that the sprite will not collide with other bodies. I been trying to figure out a way to change the radius that scales with the sprite but no such question exist here for cocos2d. I have noticed other box2d for things other than cocos2d but I am having a hard time translating them over.
//smile.position = ccp(touchLocation.x, touchLocation.y);
smile.scale = .05;
[self addChild:smile];
// b2BodyDef smileBodyDef;
smileBodyDef.type = b2_dynamicBody;
smileBodyDef.position.Set(touchLocation.x/PTM_RATIO, touchLocation.y/PTM_RATIO);
smileBodyDef.userData = smile;
smileBody = world->CreateBody(&smileBodyDef);
//Radius
b2CircleShape smileCircleShape;
int radius = 80;
//Fixture
smileFixtureDef.shape = &smileCircleShape;
smileFixtureDef.density = 0.00f;
smileFixtureDef.friction = .2f;
smileBody->CreateFixture(&smileFixtureDef);
if (CGRectContainsPoint(smileRect, touchLocation)) {
growForever = [CCRepeatForever actionWithAction: [CCScaleBy actionWithDuration: .5 scale: 1.2]];
[growForever setTag:1];
[smile runAction:growForever];
Each time you want to change your radius, grab the shape object associated with the b2Fixture that you created for your body, and then set the new value accordingly:
fixture->GetShape()->m_radius = new_radius/PTM_RATIO;

Shooting bullets with a joystick cocos2d

I have a working joystick in my cocos2d app but I cannot figure out how to make the 'player' shoot bullets out of it in the direction the joystick is pointing. I have the player moving and rotating. Also the bullets need to disappear when they hit the edges of the screen. Any help would be great. Thanks in advance.
You should get the angle from joystick.
For instance, SneakyInput has a degrees property which enables you to rotate your bullets like this :
_bullet.rotation = -joystick.degrees;
And your update method can be like this :
void update:(ccTime) delta
{
float moveAngle = _bullet.rotation;
CGPoint deltaPos = CGPointMake(cos(moveAngle) * velocity, sin(moveAngle) * velocity);
_bullet.position = ccpAdd(self.position, deltaPos);
}

cocos2d: Why can't I change a scaled node's position?

I think I'm just understanding scaling/positioning nodes/layers incorrectly. I'm setting up my node like this (node class is derived from CCNode):
-(id) init
{
if ((self = [super init]))
{
// Create parallax background node.
background = [BackgroundNode node];
[self addChild:background z:0];
// Create foreground node.
foreground = [ForegroundLayer node];
[self addChild:foreground z:0];
self.position.y = 500.0f;
self.scaleX = 1.5f;
self.scaleY = 1.5f;
}
return self;
}
It doesn't seem to matter what I set the self.position.y to - the scaled node is always displayed as though it was positioned in the bottom-left of the screen. I've tried playing around with anchorPoint as well, but it doesn't really seem to change anything.
The reason I'm asking is because I'd like to be able to pan vertically when I'm zoomed in - this doesn't seem to really be the right way to accomplish it, though. Any ideas?
self.position.y = 500.0f;
doesn't work. It should be
self.position = ccp(self.position.x, 500.0f);
Please refer to "Cocoa Objective-c Property C structure assign fails".