- fixed mouse cursor position problrm at game startup

This commit is contained in:
Mark Vejvoda
2010-06-25 00:45:46 +00:00
parent 90ba101d7e
commit 9b2b544b84
3 changed files with 21 additions and 0 deletions

View File

@@ -551,10 +551,21 @@ void Game::render() {
// Ensure the camera starts in the right position // Ensure the camera starts in the right position
if(isFirstRender == true) { if(isFirstRender == true) {
isFirstRender = false; isFirstRender = false;
/*
Map *map= world.getMap(); Map *map= world.getMap();
const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex()); const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex());
gameCamera.init(map->getW(), map->getH()); gameCamera.init(map->getW(), map->getH());
gameCamera.setPos(Vec2f(v.x, v.y)); gameCamera.setPos(Vec2f(v.x, v.y));
//const Vec2i &mapPos = Map::toSurfCoords(v);
Renderer &renderer= Renderer::getInstance();
Vec3f screenPos = renderer.computeScreenPosition(gameCamera.getPos());
SDL_WarpMouse(v.x, v.y);
*/
gameCamera.resetPosition();
this->restoreToStartXY();
} }
renderFps++; renderFps++;

View File

@@ -269,6 +269,11 @@ void Program::setState(ProgramState *programState, bool cleanupOldState)
try { try {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
int X = 0;
int Y = 0;
SDL_GetMouseState(&X,&Y);
programState->setStartXY(X,Y);
showCursor(true); showCursor(true);
sleep(0); sleep(0);

View File

@@ -45,6 +45,9 @@ class ProgramState{
protected: protected:
Program *program; Program *program;
int startX;
int startY;
public: public:
ProgramState(Program *program) {this->program= program;} ProgramState(Program *program) {this->program= program;}
virtual ~ProgramState(){}; virtual ~ProgramState(){};
@@ -70,6 +73,8 @@ public:
virtual void keyDown(char key){}; virtual void keyDown(char key){};
virtual void keyUp(char key){}; virtual void keyUp(char key){};
virtual void keyPress(char c){}; virtual void keyPress(char c){};
virtual void setStartXY(int X,int Y) { startX=X; startY=Y; }
virtual void restoreToStartXY() { SDL_WarpMouse(startX, startY); }
}; };
// =============================== // ===============================