How to have two physics sprites not collide in spritebuilder? - cocos2d-iphone

I'm using Spritebuilder and I have two nodes that are using physics and I want them to just ignore each other. The two nodes are player 1 and 2, I don't want them to do anything when they collide but I still want them both to collide with other objects and so using a sensor body won't work.
Does anyone know what I can do?

Have a look at the docs. Basically, all you have to do is to add both nodes to the same collision group. You can do this either in Spritebuilder (in the physics properties tab) or in code.

Related

Cocos2d-x Remove sprites in specified rectangular area

I'm using Cocos2d-x and I'm just looking for efficient way to remove sprites under some rectangular region.
For example if I have a lot of random located sprites on the scene and I want to remove all of them if they belong to rectangular (x1, y1),(x2, y2), then what I need to do?
I see that there are two ways to remove sprite from the scene:
this->removeChildByTag(tag);
or
sprite->removeFromParent();
So from these methods it seems that we need somehow to find which sprites are located inside the area and after that delete them.
But what is the most efficient way to do it?
Thanks!
The only way to do this using default cocos functionality would be to iterate over each child detect overlapping and remove nodes that match criteria. removeFromParent() as well as removeChildByTag() will invoke parent->removeChild(this);. And removeChild() uses std::find in Vector of child nodes. With complexity O(n). So first step of optimization would be to use detachChild that utilizes index of child.
But if that is not fast enough I would recommend using special data structure to quickly search for overlapping like interval tree.

OpenCV - Detection of moving object C++

I am working on Traffic Surveillance System an OpenCv project, I need to detect moving cars and people. I am using background subtraction method to detect moving objects and thus drawing counters.
I have a problem :
When two car are moving on road closely them my system detects it as one car, I have used all efforts like canny-edge detection, transformation etc. Can anyone tell me any particular methodology to solve this type of problems.
Plenty of solutions are possible.
A geometric approach would detect that the one moving blob is too big to be a single passenger car. Still, this may indicate a car with a caravan. That leads us to another question: if you have two blobs moving close together, how do you know it's two cars and not one car towing a caravan? You may need to add some elementary shape detection.
Another trivial approach is to observe that cars do not suddenly multiply. If you have 5 video frames, and in 4 of them you spot two cars, then it's very very likely that the 5th frame also has two cars.
CV system tracks object as moving blobs (“clouds” of moving pixels) identifies them and distinct one from another in case of occlusions. When two (or more) blobs are intersected, system merges them in one combined object and marks it by IDs of all those source-objects that currently included in the combination. When one of objects separates from the combination CV system recognize which one is out and re-arrange ID appropriately.

Checking connectivity of two bodies through open space

The title is a little vague, but I'll explain better here.
The Setup
I'm trying to program a little water level simulator, much like the water levels in the game, LIMBO. When an opening is made, allowing water to flow between two bodies of water, the levels equalize. The setup I have now is two containers, with blue blocks inside representing water levels. My mouse removes chunks of terrain away, and so, when an opening is made between the bodies, they should adjust and their Y values should move to match.
Image examples:
Semi-filled tanks:
Equalized tanks:
Now, I know some maths could be done to figure out how much to adjust the levels and the ratios between different sized tanks. That part I think is pretty straight forward. But I can't figure out a good method of determining if and when the two bodies of water are connected.
Any algorithm, pseudo-code, or references would be much appreciated!
If you need more clarification, please, don't hesitate to ask. I look forward to all feedback and will edit my post for specific clarification.
Thanks!
~ natebot13
BTW: I'm using C++, SFML, and Box2D (Box2D is for some other physics related things I need, not necessarily needed for this example).
You need to check whether the edge of the container1 is connected to container2 at any point of time if so then adjust the water level. I guess you are working on a image so you can use the connected components algorithm to check if any of the edge pixels of container1 is connected to any of edge pixels of container2 and also get their positions.
Algorithm :-
puts edges of container1 in one set which is connected to a dummy parent1.
puts edges of container2 in another set which is connected to another dummy parent2.
say after every one second add the new added pixels to sets using connected components
check at end of every union whether dummy parent1 and parent2 are connected.
You can use DFS to check the exacts points of connection by starting from one edge set1 and reaching the other. The last pixel and
the previous first pixel in edge set1 are connection end points.
Note:-
There is a implementation of disjoint set in c++ boost lib which might be useful in implementation of connected components.
I think you can start from left to right for example:
the right side of the left tank position is known.
search the column to its right for a blue square.
once found, search its surrounding squares - up, down and to the right.
keep searching until you get to the known left side of the right tank.

Using Box2d bodies for infinite scrolling

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?

Animation of Sprite not updating physics

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)