Answer the question
In order to leave comments, you need to log in
C++ memory error?
Hello, I am far from the C ++ Zen, and I read little on it, which I sin on .. and for me, to be honest, this is an unusual and mysterious mistake.
#ifndef MMUSICANTLAYER_H
#define MMUSICANTLAYER_H
#include "cocos-ext.h"
#include "../Common.h"
USING_NS_CC;
class MMusicantLayer : public Layer
{
public:
CREATE_FUNC(MMusicantLayer);
~MMusicantLayer();
bool onTouchBegan(Touch *touch, Event *event);
void onTouchMoved(Touch *touch, Event *event);
void onTouchEnded(Touch *touch, Event *event);
private:
bool init();
MMusicantLayer();
Point* m_beginPoint;
};
#endif // MMUSICANTLAYER_H
#include "MMusicantLayer.h"
MMusicantLayer::MMusicantLayer()
{
m_beginPoint = new Point(0,0);
}
MMusicantLayer::~MMusicantLayer()
{
CC_SAFE_DELETE(m_beginPoint);
}
bool MMusicantLayer::init()
{
if(!Layer::init()) {
return false;
}
Object* it;
CCARRAY_FOREACH(MGameState::getInstance()->getActiveTeam(), it) {
MMusicant* musicant = static_cast<MMusicant*>(it);
addChild(musicant);
}
CCARRAY_FOREACH(MGameState::getInstance()->getPassiveTeam(), it) {
MMusicant* musicant = static_cast<MMusicant*>(it);
addChild(musicant);
}
setTouchEnabled(true);
return true;
}
bool MMusicantLayer::onTouchBegan(Touch *touch, Event *event)
{
Point newLoc = touch->getLocation();
m_beginPoint->setPoint(newLoc.x, newLoc.y);
return true;
}
void MMusicantLayer::onTouchMoved(Touch *touch, Event *event)
{
CCLOG("%lf %lf", m_beginPoint->x, m_beginPoint->y);
}
void MMusicantLayer::onTouchEnded(Touch *touch, Event *event)
{
}
#define CC_SAFE_DELETE(p) do { delete (p); (p) = nullptr; } while(0)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question