Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Learning Cocos2d-x Game Development
  • Toc
  • feedback
Learning Cocos2d-x Game Development

Learning Cocos2d-x Game Development

By : Siddharth Shekar
3 (1)
close
Learning Cocos2d-x Game Development

Learning Cocos2d-x Game Development

3 (1)
By: Siddharth Shekar

Overview of this book

If you are a hobbyist, novice game developer, or programmer who wants to learn about developing games/apps using Cocos2d-x, this book is ideal for you.
Table of Contents (13 chapters)
close
12
Index

Creating the HUD layer and displaying as well as updating scores


HUD is usually used to display information to the player such as score, health, and points. In our game, we are going to add the score variable we previously created in the HelloWorldScene files and move it to this layer for convenience.

Similar to how we created GameplayLayer, we will create HUDLayer. So, now in your Classes folder in the system, you will have HUDLayer.h and HUDLayer.cpp; add them in the Solution Explorer panel in the Classes tab by clicking on Add existing file.

In the HUDLayer.h file, add the following code:

#ifndef __wp8Game__HUDLayer__
#define __wp8Game__HUDLayer__

#pragma once
#include "cocos2d.h"
using namespace cocos2d;

class HelloWorldScene;

class HUDLayer : public CCLayer
{
public:
    HUDLayer(void);
    ~HUDLayer(void);

    CCSize visibleSize;
    CCLabelBMFont* scoreLabel;

    void updateScore(int score);
    
};
    

#endif

Here, we add the constructor and destructor for the HUDLayer class...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete