Cocos2d-x / control drawNode from function -
Cocos2d-x / control drawNode from function -
i'm trying animate drawnode declared "dotnode" function "helloworld::touchdetector" in code above.
but exc_bad_access when click , fired function. (debug area shows: "dotnode cocos2d::drawnode * null 0x0000000000000000" / "this cocos2d::node * null 0x0000000000000000" or that.)
does has thought why happens? thought code work because declared drawnode public in helloworld.h, doesn't. (label worked same code.)
thanks,
helloworld.h
#ifndef __helloworld_scene_h__ #define __helloworld_scene_h__ #include "cocos2d.h" class helloworld : public cocos2d::layergradient { public: static cocos2d::scene* createscene(); virtual bool init(); create_func(helloworld); cocos2d::drawnode *dotnode; void touchdetector(double locationx, double locationy); }; #endif // __helloworld_scene_h__
helloworld.cpp
#include "helloworldscene.h" using_ns_cc; scene* helloworld::createscene() { auto scene = scene::create(); auto layer = helloworld::create(); scene->addchild(layer); homecoming scene; } bool helloworld::init(){ if ( !layer::init() ) { homecoming false; } size visiblesize = director::getinstance()->getvisiblesize(); point origin = director::getinstance()->getvisibleorigin(); drawnode *dotnode = drawnode::create(); dotnode->drawdot(point(visiblesize.width*.5, visiblesize.height*.5), 10, color4f(color3b::white)); this->addchild(dotnode, 1); auto listener = eventlistenertouchonebyone::create(); listener->setswallowtouches(true); listener->ontouchbegan = [=](touch *touch, event *event) mutable{ point location = touch->getlocation(); helloworld::touchdetector(location.x, location.y); homecoming true; }; this->geteventdispatcher()->addeventlistenerwithscenegraphpriority(listener, dotnode); homecoming true; } void helloworld::touchdetector(double locationx, double locationy){ finitetimeaction* scale = easebounceout::create(scaleto::create( 0.45f, 1.0f)); dotnode->runaction(scale); return; }
the error declare local variable drawnode *dotnode = drawnode::create();
in init method in helloworld.cpp. remove declaration , should work.
cocos2d-x cocos2d-x-3.0
Comments
Post a Comment