[Cocos3.0 Tutorial] Use the Cocos2d-x-3.0 game engine. Write a Tower Defender Game.(Part06)

Has anyone tested the code on Linux?

Thanks.

has any one run without crash?
i have some problem in touchMoved and touchEndded event.

Can you share your source code and image in resource?

The same error for me:

this->nextProjectile = Projectile::projectile();

Have you solved it?

I also have the error.

Hi,

Revisiting the code, I’m having a problem at this line of code;

m->_gameLayer->convertTouchToNodeSpace(touch);

It crashes while trying to evaluate

kmMat4 tmp = getWorldToNodeTransform();

at Point Node::convertToNodeSpace(const Point& worldPoint) const
(file CCNode.cpp).

Tested with both gcc and clang. What could possibly be the cause?

Thanks.

in Tower.h , try add this

class Tower: public Sprite
{
public:
int range;
Sprite* sprite;
Creep* target;
Sprite * selSpriteRange;
Creep* getClosestTarget();
Projectile* nextProjectile; // add this
CREATE_FUNC(Tower);

};

1 Like

In TutorialScene.cpp:

Scene* TutorialScene:createScene()
{
auto scene = Scene::create();

auto layer = TutorialScene:create();

auto myGameHUD = GameHUD::shareHUD();

DataModel *m = DataModel::getModel();
m -> _gameHUDLayer = myGameHUD;
m -> _gameLayer = layer;  // add this

scene -> addChild(layer);
scene->addChild(myGameHUD, 1);

return scene;

}