Book Image

Cocos2d-x by Example: Beginner's Guide

By : Roger Engelbert
Book Image

Cocos2d-x by Example: Beginner's Guide

By: Roger Engelbert

Overview of this book

Table of Contents (19 chapters)
Cocos2d-x by Example Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – let's do some drawing!


Time to implement the drawing inside LineContainer.cpp. You will notice that this class already has most of its methods implemented, so you can save a little typing. I'll go over what these methods represent once we add the game's main update method. But basically LineContainer will be used to display the lines the player draws on screen to manipulate _rocket sprite, as well as display an energy bar that acts as a sort of timer in our game:

  1. What we need to change here is the update method. So this is what you need to type inside that method:

    _energy -= dt * _energyDecrement;
    if (_energy < 0) _energy = 0;
    clear();
    
    switch (_lineType) {
      case LINE_NONE:
       break;
      case LINE_TEMP:
       drawLine(_tip, _pivot, Color4F(1.0, 1.0, 1.0, 1.0));
       drawDot(_pivot, 5, Color4F(Color3B::WHITE));
       break;
                
      case LINE_DASHED:
       drawDot(_pivot, 5, Color4F(Color3B::WHITE));
       int segments = _lineLength / (_dash + _dashSpace);
       float t = 0.0f;
      ...