Check physics chipmunk collision enemy - player

Check physics chipmunk collision enemy - player
0
#1

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
{
public:
	Enemy(Layer *layer, int x, int y,int id);
	int hp = 100;
	Sprite *sp;
	void damage();
private:	
};
#endif // _ENEMY_H_

in class enemy.cpp

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

USING_NS_CC;

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

    sp = Sprite::create("enemy");
    layer->addchild(sp,1);

    auto Enemybody = PhysicsBody::createBox(Size(sp->getContentSize().width, sp->getContentSize().height));
  sp->setPhysicsBody(Enemybody);
    Enemybody->setCollisionBitmask(1);
    Enemybody->setContactTestBitmask(true);
    Enemybody->setDynamic(false);
}
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

#2

Cpp-tests has a few working examples of exactly this

#3

Refer this :

1 Like
#4

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

#5

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.

#6

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