作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
我正在使用 SFML 和 Box2D 创建一个类似 peggle 的游戏,但是我的游戏单例出现了这个错误。
Error 1 error LNK2001: 未解析的外部符号“private: static class Game * Game::s_pInstance” (?s_pInstance@Game@@0PAV1@A) C:\Users\UserName\Desktop\PeggleClone\Maze\Maze\Game .obj
main.cpp
#include "Game.h"
#define SCALE 30.0f
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
int _tmain(int argc, _TCHAR* argv[])
{
Game* game = Game::GetInstance();
game->Initialize(WINDOW_WIDTH, WINDOW_HEIGHT);
//Stuff for timesteps
float timenow = (float)GetTickCount();
float timethen = (float)GetTickCount();
float timeelapsed = 0.0f;
while (true)
{
timeelapsed = (float)(timenow - timethen) / 1000.0f;
if(game->Update(timeelapsed) < 0)
break;
game->Render();
timethen = timenow;
timenow = (float)GetTickCount();
}
game->Terminate();
game->DeleteInstance();
return 0;
}
游戏.h
#pragma once
class BaseGameState;
class Game
{
public:
void Initialize();
/**********************************************************/
// Singleton Accessors:
static Game* GetInstance ( void );
static void DeleteInstance ( void );
/**********************************************************/
// Setup, Play, Cleanup:
bool Initialize ( unsigned int width, unsigned int height );
int Update ( float elapsedTime );
void Render ( void );
void Terminate ( void );
unsigned int GetWidth() {return m_uWidth;}
unsigned int GetHeight() {return m_uHeight; }
sf::RenderWindow* GetWindow() {return gameWindow;}
private:
/**********************************************************/
// Singleton Object:
static Game* s_pInstance;
Game(void) = default;
~Game(void) = default;
Game(const Game&) = delete; // copy constructor
Game& operator= (const Game&) = delete; // assignment operator
/**********************************************************/
// Game State Machine:
// - can ONLY be called by the state's Input, Update, or Render methods!!!
void PushState(BaseGameState* pNewState);
void PopState(BaseGameState* pNewState);
void ClearState(BaseGameState* pNewState);
vector<BaseGameState*> m_vStates;
// Window stuff
unsigned int m_uWidth, m_uHeight;
sf::RenderWindow* gameWindow;
};
游戏.cpp
#include "stdafx.h"
#include "Game.h"
#include "BaseGameState.h"
#include "MainMenuState.h"
bool Game::Initialize(unsigned int width, unsigned int height)
{
// Set up render window
gameWindow = new sf::RenderWindow(sf::VideoMode(width, height), "Peggle Ripoff");
// Clear state machine
m_vStates.clear();
//Start on main menu
PushState(MainMenuState::GetInstance());
return true;
}
Game* Game::GetInstance( void )
{
if( s_pInstance == nullptr )
s_pInstance = new Game;
return s_pInstance;
}
void Game::DeleteInstance( void )
{
delete s_pInstance;
s_pInstance = nullptr;
}
我最近购买了《C 编程语言》并尝试了 Ex 1-8这是代码 #include #include #include /* * */ int main() { int nl,nt,nb;
早上好!我有一个变量“var”,可能为 0。我检查该变量是否为空,如果不是,我将该变量保存在 php session 中,然后调用另一个页面。在这个新页面中,我检查我创建的 session 是否为空,
我正在努力完成 Learn Python the Hard Way ex.25,但我无法理解某些事情。这是脚本: def break_words(stuff): """this functio
我是一名优秀的程序员,十分优秀!