scaling ccsprite and ccphysicsbody - cocos2d-iphone

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.

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.

Related

OpenCV Camera to Object Horizontal Angle Calculation

So, I'm a high school student and the lead programmer on my local robotics team, and this year I decided to try out OpenCV and do some vision processing on our robot.
From my vision code, I need to know a few things about some objects on our competition field. These things are: distance (ft), horizontal angle from camera, and horizontal distance from camera (ft). Essentially, one large right triangle.
I already have the camera successfully detecting these objects and putting a boundingRect around them. With a gyroscope on our robot, we should be able to get our robot to ~90 degree angle to the object once it is detected (as it's a set angle on the field). Thus, I can calculate distance just based on an empirically made function of the area of the boundingRect of the object.
The horizontal angle of the object from the camera, however, I'm not exactly sure how to approach. Once I have that, though, I can do some simple trig and get the horizontal distance.
-
So here's what we have/know: Distance to object in ft, object is at ~90 degrees to camera, camera has horizontal fov of 67 degrees w/ resolution of 800x600, the real world dimensions of the object, and a boundingRect around the object.
How would I, using all of this information, calculate the horizontal angle from the camera to the object?

Rocket like movement in cocos 2d V3 with chipmunk

On tapping on screen I`m gonna apply impulse and angular rotation to sprite to move it to the sides. But after some time OR parameters of physics body attached to sprite should go back to initial (impulse 0, angular speed = 0). What are the best ways to do that (use CCAction or on update detect parameters of physics body and change them to initial)?
If i were in your position, I would probably start a timer at the first collision of the sprite and then use a CCAction to transition to the initial state to make it look smooth. Don't know if its the best way though.

Sprite and attached physics body anchor points differ

When rehearsing Cocos2d V3 physics with debug mode enabled I noticed that physics body attached to its sprite has different anchor point from that of the sprite itself. Here's how it looks:
And this is how I create a sprite with physics body:
CCSprite *beam=[CCSprite spriteWithSpriteFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:#"w272.png"]];
beam.physicsBody=[CCPhysicsBody bodyWithRect:beam.boundingBox cornerRadius:0];
beam.position=ccp(125, 160);
[physicsWorld addChild:beam];
Do you have any idea how to fix this? I don't set any anchor point anywhere.
Physics objects automatically calculate a center of gravity, which is slightly different than an anchor point. Your real problem though is that you are using the sprite's bounding box as the rectangle to create the body and that's expressed in local coordinates. You want to make a text that goes from (0,0) to content size.

How to handle collision openGL

This is separate to a previous question I asked.
To make the collision detection simpler I am now using euclidean distance to work out if objects intersect.
I am working in a 3D environment using openGL with bounding walls around the
edges.
I have a player (just displayed as a quad for now)
There are also several randomly displayed cylinders acting as pillars, created using gluCylinder.
Intersection with the walls is fine, and I know that if there is an intersection with the left wall for example the player should be positioned at an X co ordinate that is 0.5 away from the bounding wall.That way if the player is going to go through the wall then it will have the appearance of being able to walk into the wall but not through it.
I am having trouble with the inner pillars, and what i should do with the player when i detect they are within a certain distance of a pillar.
I am using a euclidean distance calculation to detect collisions when diet is < than a value 1 for example.
double dist = sqrt(pow((playerX - xPosi[i]),2) + pow((playerZ - zPosi[i]),2));
xPosi[i] and zPosi[i] are arrays holding the x and z co ordinates of my pillars, and player X and Z hold the co ordinates of the player. Could anyone suggest how to handle the interaction with the pillars, as i now have the collision detection working.
The player will only be travelling in either a +ve or -ve x direction or +ve or -ve z direction, I would like the player to stop if a collision is detected and no longer be able to move through the pillar.

cocos2D collision on edge shape only

I'm developing an iOS game with cocos2D.
My game is simple, there are levels, and a rotating sprite.
The sprite need to go from the beginning to the end of the level without losing his lives.
So there is two possibilities for me :
1°) Already working good
Tilemap based levels with 2D pixels styles tilesets
Custom collision detection on the edge of the hero's sprite bounding box, and the tilemap collision.
2°) Would be better graphics, and better users experience (without physics, only collision):
map base on vector graphics / SVG
collision detection using the edge of the hero's sprite shape and the map
But, i read the cocos2D/Box2D documentation, and i doesn't found a collision detection on the edge of the sprite's shape ONLY. It's like a pixel perfect collision (already found algo).
I only want to know if one of the 4 edge of my hero's shape is colliding a border of the level, and if yes which shape is colliding (because my sprite is rotating).
Someone have an idea ?
Thank you a lot for your time.
One polygon shape should be attached to your Hero's body via fixture.
To detect a collision point use contacts between dynamic(hero) and static(walls) bodies.
Just take your hero's shape and divide in half to find the pixel width of the hero shape (the radius) and detect collision if the distance between your hero and another sprite is equal to or less than this radius.