#include "bullet.h"
USING_NS_CC;
using namespace std;
using namespace ui;
using namespace CocosDenshion;
Bullet::Bullet(Layer *layer,int x ,int y)
{
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto visibleSize = Director::getInstance()->getVisibleSize();
sp = Sprite::create("bullet.png");
sp->setScale(1);
sp->setPosition(Vec2(x,y));
layer->addChild(sp, 1000);
auto bulletbody = PhysicsBody::createBox(Size(sp->getContentSize().width, sp->getContentSize().height));
sp->setPhysicsBody(bulletbody);
bulletbody->setCollisionBitmask(10001);
bulletbody->setContactTestBitmask(true);
bulletbody->setDynamic(false);
auto moveToD = MoveBy::create(10, Vec2(8000, 0));
sp->runAction(moveToD);
}
This is how I create the bullet.
how to destroy it. i want to delete it completely when it collides with another object