DrawNode() not drawing :/

  • Random123abcxyz
    Likes 0

    Problem Description

    Hi all. I have to create a class of dots. I have a Dot.h file:

        #include "cocos2d.h"
        USING_NS_CC;
        class Dot : public cocos2d::DrawNode{
        public:
            virtual bool init();
            CREATE_FUNC(Dot);
        private:
            bool circumstanceA = 1;
            bool circumstanceB = 0;
        };

    and a Dot.cpp file:

        #include "Dot.h"
        USING_NS_CC;
        
        bool Dot::init()
        {
            if ( !DrawNode::init() )
                return false;
            Size visibleSize = Director::getInstance()->getVisibleSize();
            Vec2 origin = Director::getInstance()->getVisibleOrigin();
            
            drawDot(Vec2((arc4random() % (int)(visibleSize.width - visibleSize.width / 6)) + visibleSize.width / 12, (arc4random() % (int)(visibleSize.width - visibleSize.width / 3.5)) + visibleSize.width / 7), 0, Color4F(1,1,1,1));
                auto scale = ScaleTo::create(0.5, (visibleSize.height / 6) + (arc4random() % (int)(visibleSize.height / 15)) - visibleSize.height /30);
            auto scale_ease = EaseBackOut::create(scale->clone());
            this->runAction(scale_ease);
            
            return true;
        }

    But when I try to create a new Dot from the current scene:

        auto newDot = Dot::create();
        this->addChild(newDot, 1);

    no dot is displayed in the simulator.
    I tried also creating it from the scene, like

        auto prova = DrawNode::create();
        prova->drawDot(Vec2(visibleSize.width / 2, visibleSize.height / 2), 50, Color4F::WHITE);
        this->addChild(prova, 1);

    but the result is the same :/

    Where am I mistaking?

    I tried also with DrawLine, nothing is being displayed.

    I'm kinda new to this cocos2d-x syntax, so any help would be very appreciated :)

    Many thanks!

    ps: Is it correct to use

        this->runAction(scale_ease);

    from the object's class init() function?


  • Sonar Systems admin
    Likes 0

    Are you trying to draw primitives?

  • Random123abcxyz
    Likes 0

    Yes. I got a satisfying answer here: http://discuss.cocos2d-x.org/t/how-to-use-scaleto-like/21553

    Thank you for the disponibility and I hope this will be helpful for someone else too :)


  • Sonar Systems admin
    Likes 0

    Great to hear that you have found an answer.

Login to reply