Check physics chipmunk collision enemy - player

Check physics chipmunk collision enemy - player

How can I check the collision between player and enemy when all enemies have the same colistionbitmash?

in class enemy.h

 #include "cocos2d.h"
 #include "ui/CocosGUI.h"
using namespace cocos2d;
class Enemy : public Sprite
	Enemy(Layer *layer, int x, int y,int id);
	int hp = 100;
	Sprite *sp;
	void damage();
#endif // _ENEMY_H_

in class enemy.cpp

#include "enemy.h"
using namespace std;
using namespace CocosDenshion;


Enemy::Enemy(Layer *layer,int x,int y, int id)
 Vec2 origin = Director::getInstance()->getVisibleOrigin();
 auto visibleSize = Director::getInstance()->getVisibleSize();

    sp = Sprite::create("enemy");

    auto Enemybody = PhysicsBody::createBox(Size(sp->getContentSize().width, sp->getContentSize().height));
void Enemy::damage()
     hp -= 10;

in class helloword.h i creat enemy Enemy *EN[10];

.How to check for collision and call func damage() when all enemy collisionbitmash = 1


Cpp-tests has a few working examples of exactly this


Refer this :

1 Like

If I put together a CollisionBitmask, other objects with the same CollisionBitmask but no collisions are affected??


I dont know what you are saying but if you read my that post very carefully then you will understand.
Please follow that way, dont use true, false, 0 or 1.


and let me state again that cpp-tests has working examples of this concept.