Paresh Thakor
Paresh Thakor

Reputation: 1835

scaling ccsprite and ccphysicsbody

The player which is scaled down (after few seconds as game progresses) but its associate body is not being scaled down.

I have create a Player object with SpriteBuilder with following details:\

CCSprite with Physics enabled
- Dynamic Body
- Allows rotation and affected by gravity
- Density is 1.00
- Friction is 0.00
- Elasticity is 0.00
- Physics shape is Circle with corner radius 13.00

Here, my player is perfect and its physics body fits it exactly.

I want the player to be scaled down as game progresses, like, the player leaves trails like asteroid and eventually becomes smaller from 26 pixels to 10 pixels.

I am using __player.scale += 0.1 to increase or decrease the player size. But this scales the size of player image only. It does not affect player's physics body.

Please suggest me how to redefine PhysicsBody with CCSprite so it fits player.

Upvotes: 0

Views: 69

Answers (1)

Leandro
Leandro

Reputation: 132

It won't scale down the PhysicsBody when you use setScale() method alone. You should use setContentSize() method to scale your PhysicsBody of the sprite itself.

Sprite->setScale(Scale);
Sprite->setContentSize(ContentSize);

The above code will scale the Sprite image and its PhysicsBody in according to your defined arguments.

Upvotes: 1

Related Questions