I'm having major issues trying to resize/scale/reshape a b2body's fixture... I've read so many tutorials and since I'm a n3wb at box2d most of it doesn't make sense.
What I'm trying to do exactly is make the collision box of a b2body scale to a CCSprite in cocos2d as the sprite moves dynamically through the application.
Any reference code would be greatly appreciated, I know you have to destroy and recreate the fixture but I have no idea how to do it correctly! I've been at this for hours now with no success. Thanks!
I think you need to create new fixture with new body. Please check out tutorial, it solve another problem, but you will learn many useful things (e.g. how to recreate body with new fixture):
http://www.raywenderlich.com/14302/how-to-make-a-game-like-fruit-ninja-with-box2d-and-cocos2d-part-1
http://www.raywenderlich.com/14393/how-to-make-a-game-like-fruit-ninja-with-box2d-and-cocos2d-part-2
Related
I am new to LevelHelper.
I have created a Car+2 wheels using Wheel Joint(The same as the one in Wheel Joint of LevelHelper youtube tutorial).
My question is how can I programmatically add multiple Car with all the wheel and physics???
Should I add separate Sprite and Add my joints and then bind them???
Help is much appreciated
Regards;
I Was in the same sittuation as you are now. I have created track and my bike object in separate level and created separate levelhelperloader object for track and bike and add it to the b2world.
This is worked for me. I hope it will work for you also.
I'm making a platform game, and everything was great. My sprite moved when i touched the left side of the screen, and jumped when i touched the right side. But then i decided to make it move by itself. so i added the ccmoveto function, but now it does not jump! I'm new to cocos2d but everything is working ok, except this, already searched but couldn't find the answer can someone please help me?
I tried everything, but it only jumps if i delete the ccmoveto action.
I'm using cocos2d 2.0
Thank you!!
CcMoveTo will override any manual position changes, inluding changes from other actions like CCJump. Your character is set to move to destination in a straight line, no matter what.
It's issues like these why I always recommend not to use actions for gameplay logic. Especially position, you need to retain full control over it. Use a direction vector and integrate position every update: and you're free to do everything you need.
my advice is to use one of the physics engines provided with cocos2d: Box2D and Chipmunk physics. Thanks to this engines you can define the characteristics of the world (i.e. gravity vector) a shape and a mass for your sprite (i.e. a rectangle with a weight). Then when you need it to jump you will just create a force vector with the characteristics you need (i.e. angle, etc.) and keep updated your sprite with its physical body. This will make your sprite jump and land quite realistically.
Hi. I am new on this website and also in cocos2d. I am a student and I need your help.
I am making a game based on one of the tutorials in a cocos2d game development book. The concept is simple; different objects are falling from the top of the screen and I have to avoid or catch them by tilting the device. The main character, which is one which has to avoid objects, has different properties which can change by grabbing different objects (e.g. the player may have a shield if it grabs one). In order to display the shield I have to change the sprite of the player. I am not sure how I can achieve this. Could anyone help me in providing some guidelines on this?
Use setTexture to switch the image (texture) of your current sprite with another:
[playerSprite setTexture:[[CCTextureCache sharedTextureCache] addImage:#"playerWithShield.png"]];
Hi guys
I am new to the cocos2D.In my game i have one scene and several layer to display Menu,pause,level finish,game over. now i want to find out the layer which is being used on top of the scene. i already tried and got the solution to solve it by using boolean variable for every layer. but this is not a good way to use i thought.
please provide some suggestions
Thanks
Riash
You can simply keep a pointer to the active layer. And it is better to have different scenes for every game state because in this case your management will become much simpler. That's because typically your game scene will have more then one layer. For example: background, level objects, controls and so on.
I am working on a game which would take touch gestures as inputs. Now, i would like to display the path/gesture as the user draws it. Can someone please tell me how to do this in cocos2d?
I tried to override the draw method and used ccDrawPoint(). But the point just keeps following the touch. I guess this is because the previous drawing is getting overwritten.
Can you tell me where i am going wrong here or suggest a better way to implement this?
i found a solution with CCRenderTexture sample test in cocos2d. Though i could not find enough documentation on it, but the sample code is enough for a start.