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...