I have a GameUI.h
, Round1.cpp
and GameUI.cpp
file.
In GameUI.h, I have declared:
static cocos2d::sprite* battery;
Both Round1.cpp
and GameUI.cpp
has included GameUI.h
and this is creating multiple definition problem and giving
linker command failed with exit code 1 - Error
GameUI.h file is
#ifndef __GAME_UI_H__
#define __GAME_UI_H__
#include "cocos2d.h"
#include "common.h"
class GameUI : public cocos2d::Layer
{
public:
static cocos2d::Sprite *_batteryPannel;
};
#endif
GameUI.cpp file is
#include <GameUI.h>
USING_NS_CC;
Node* GameUI::createBatteryPanel()
{
Vec2 origin = Director::getInstance()->getVisibleOrigin();
auto batteryNode = Node::create();
_batteryPannel = CommonFunc::createSpriteFromCache("BatteryPanel.png", 0, 0);
batteryNode->addChild(_batteryPannel, 2);
return batteryNode;
}
Round1.cpp file I have
#include "Round1.h"
#include "GameUI.h"
USING_NS_CC;
// on "init" you need to initialize your instance
bool RoundA::init()
{
auto batteryPosition = GameUI::_batteryPanel->getPosition();
}