- 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
if(isFirstRender == true) {
isFirstRender = false;
/*
Map *map= world.getMap();
const Vec2i &v= map->getStartLocation(world.getThisFaction()->getStartLocationIndex());
gameCamera.init(map->getW(), map->getH());
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++;

View File

@@ -269,6 +269,11 @@ void Program::setState(ProgramState *programState, bool cleanupOldState)
try {
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);
sleep(0);

View File

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