Im using Level Helper and SpriteHelper to create my sprites, images, levels and more importantly animations and physics.
Note, by physics i mean the debugdraw you can see on the simulator that is used for collision detection.
I created a swimmer and added physics to this. Done the code so the physics follows the swimmer around the pool as they move. I have now come to animate the swimmer, make the legs kick etc. Now when i load my game and only the first sprite of the animation is the outline for the physics. So i can see the legs kicking on the swimmer but the debugdraw mesh of the physics doesn't animate as well. Now this is not really a problem until for example my swimmer loses their legs (weird game i know). I change the animation to now a swimmer with no legs but again the physics mesh still shows the legs. So any collisions with stuff still happens where the legs were but they shouldnt. This make sense?
Is there a way to update the physics on the new animation or do i need to remove my whole swimmer and draw a new one?
Any help at all would be great. Thanks
This makes sense, since your sprite uses the same box2d mesh in both states. If you want to have a different collision behavior after altering your Sprite, you should assign another (smaller) mesh body.
Note that even in cocos2d side, your sprite still has the same container box with the new animation.
In order to keep using the SpriteHelper functionality you might want to create 2 different sprite-body sets: one with the full body, then after the "accident" replace it with the legless sprite.
Now, gameplay-wise, my opinion is that there shouldn't be any collision for the legs anyway. since they are moving, players will not find it weird to have them not colliding. You could use a mesh body with no legs and use it for both sprites. Except if you want to have different collisions as a gameplay feature (Like giving the player the choice to cut his legs in order to fit in a smaller cave etc)
Related
I'm newbie with Chipmunk physics and want to make an easy example of polygon explosion.
I started with the SmashLogo demo but in this example the are no explosions, only so much ball movements.
I know how to do polygon collision but my dude is for example how to explode a cube into many little pieces.
Chipmunk doesn't support exploding objects in smaller ones. Your cube should in fact be composed of multiple fragments that will separate upon impact. If your cube is not frozen and is moving, you probably need to add some forces to keep the parts together before impact.
I am making a game using cocos2d and box2d that basically consists of a ball rolling down an infinite hill. My current approach consists of using CCFollow to create the scrolling effect, while iterating through a series of four background images to create continuity. I want the ball to bounce of the hill, so I considered making the hill from two b2Body objects that alternate one another. But this requires manually moving the bodies, which seems to make keeping track of the placement of the corresponding sprite somewhat confusing. Should the hill images even be sprites? Is there a better approach that makes this easier?
I have a sprite with a triangle shape and I want to know when this triangle intersects with another object (a CCSPrite). I have been using CGRectIntersectsRect but it is not accurate because it take the bounding box of the the two sprites and not the actual shape.
--Edit
I think one way is to define several points around the actual triangle and check intersection between those points with another sprite. I am just wondering if there is an easier way to do this.
You can use box2d to detect collisions accurately. It can be useful if you have many different complicated shapes. Or you can just check intersections of shape's edges.
If there is many objects to detect collisions with, I offer to use box2d. It has good internal optimizations to be able to work with large amount of objects. In this case you will just have to create physical body equal to the your sprite's shape before adding object to your game layer.
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.
I'm new to cocos2d so I am a bit confused by some things:
The term "child" keeps popping up. At
first I thought it was a subclass,
now I perceive to be a sort of
dynamic instance variable? Can
anyone explain this a bit better?
The class CCSpriteBatchNode is some kind of array of CCSprites
which calls a method that renders
the graphical part of its
elements/children from a sprite
sheet. Is my explanation somewhat
correct?
My book (learning cocos 2d a beginners guide) shows a design
setup where the CCSpriteBatchNode
has several objects as children. I'm
a bit confused because I'm used to
separating drawing classes from
logical classes, AKA "Separation of
concerns". Is this something cocos2d
doesn't abide by and we shouldn't
either?
Parent-child is just a relationship between CCNode and their subclasses in cocos2d. For example if you want a moon turning around the moving planet it is really hard to calculate the absolute path of the moon. But you can make it the child of a planet, and in this case its position, rotation and so on, will be relative to the planet's coordinates. So parent-child relationship is just grouping.
CCSpriteBatchNode is a parent to all its children, but the position of its children are relative to CCSpriteBatchNode parent. Such approach is used because BatchNode is rendering all its children at the same time. That is done to increase performance (no texture switching).
Batch rendering is faster. If your logic is good, CCSpriteBatchNode does not make it worse. For example, you can have a character with a body, arms and legs and you want to render it using BatchNode. You just add the body as a child to BatchNode, then add arms and legs as children to the body. Logic is kept, performance is increased.