Hi hi,
I'm creating a game for my portfolio and at present it's a simple sprite running around a screen (no rotations or anything implemented yet) and I'm finding a minor issue quite annoying.
If a player is holding down the up key to move vertically and then hits the right key to head right, whilst still holding down the up keupon release of the right key the sprite doesn't move upwards as you'd expect.
I can kind of see why it does what it's doing, but I can't think of a solution. Any ideas?
Here's my input function:
[source lang="cpp"]void Game::getInput(){ sf::Event Event; while (MyGameWindow->GetEvent(Event)) { if (Event.Type == sf::Event::Closed) MyGameWindow->Close(); if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)) MyGameWindow->Close(); if(Event.Type == sf::Event::KeyPressed) currentKey = Event.Key.Code; if(Event.Type == sf::Event::KeyReleased) currentKey = sf::Key::Numpad9; if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::R)) paused = false; }}[/source]
And then my update function:
[source lang="cpp"]void Game::update(){ if(!paused) { ELAPSED_TIME = myClock.GetElapsedTime(); if (ELAPSED_TIME > FRAMERATE) { switch(currentKey) { case sf::Key::Up: P1.MoveUp(10); break; case sf::Key::Down: P1.MoveDown(10); break; case sf::Key::Left: P1.MoveLeft(10); break; case sf::Key::Right: P1.MoveRight(10); break; case sf::Key:[img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]: paused = true; break; } myClock.Reset(); } }}[/source]
Cheers guys!
- Viewing Profile: Topics: Dezachu
14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!
Community Stats
- Group Members
- Active Posts 7
- Profile Views 813
- Member Title Member
- Age 20 years old
- Birthday November 23, 1992
-
Gender
Male
-
Location
Tamworth/Leicester, UK
-
Interests
Snowboarding, paintball, swimming, gaming, football and of course coding!
106
Neutral
User Tools
Contacts
Dezachu hasn't added any contacts yet.
Latest Visitors
Topics I've Started
SFML - Key Presses?
28 November 2012 - 03:32 PM
Jumpy rotation animation?
10 November 2012 - 07:31 PM
Hey guys, bit of a noob with OpenGL (Only just started utilising it on my course!). C++.
Got this:
[source lang="cpp"]if((float)Clock.GetElapsedTime()>REFRESH_RATE){ // Clear colour and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // reset the ModelView Transform matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Apply some transformations glTranslatef(0.f, 0.f, -100.f); //glRotatef(15.f,1.f,0.f,0.f); glRotatef(i,0.f,1.f,0.f); glRotatef(i-15,0.f,0.f,1.f); glRotatef(i+15,1.f,0.f,0.f); // ********************** // drawCylinder(20,20,40); // ********************** // i++; Clock.Reset(); }[/source]
The drawCylinder uses to TRIANGLE_FAN objects and then QUAD_STRIP's, all created via a for loop. The parameters passed in are radius, numberOfSides and height.
i++ is a float declared at the beginning of the program: float i = 30; (I know it should be called f for float, but more confusion to be made there that I was better off avoiding).
When I run the program, the animation is very jumpy as it rotates. Any clues as to why? Cheers
EDIT: Dropping the framrate from 0.03 to 0.01 has improved it somewhat. Still, I'd imagine the animation would be more stuttery than jumpy. The animation basically flashed back to the previous frame every so often, looked a bit daft.
Got this:
[source lang="cpp"]if((float)Clock.GetElapsedTime()>REFRESH_RATE){ // Clear colour and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // reset the ModelView Transform matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Apply some transformations glTranslatef(0.f, 0.f, -100.f); //glRotatef(15.f,1.f,0.f,0.f); glRotatef(i,0.f,1.f,0.f); glRotatef(i-15,0.f,0.f,1.f); glRotatef(i+15,1.f,0.f,0.f); // ********************** // drawCylinder(20,20,40); // ********************** // i++; Clock.Reset(); }[/source]
The drawCylinder uses to TRIANGLE_FAN objects and then QUAD_STRIP's, all created via a for loop. The parameters passed in are radius, numberOfSides and height.
i++ is a float declared at the beginning of the program: float i = 30; (I know it should be called f for float, but more confusion to be made there that I was better off avoiding).
When I run the program, the animation is very jumpy as it rotates. Any clues as to why? Cheers
EDIT: Dropping the framrate from 0.03 to 0.01 has improved it somewhat. Still, I'd imagine the animation would be more stuttery than jumpy. The animation basically flashed back to the previous frame every so often, looked a bit daft.
#pragma once
28 September 2012 - 11:45 AM
Hi hi guys 
Going into my second year of uni and it's about time I really knuckled down, endured many headaches and cracked on with some C++!
Quick question about '#pragma once'. I know it makes sure a header file is only included once in the compilation. Well, source files, not strictly headers
Anyway, I wanted to know if it's worth including this in EVERY header file I write, or is there a particular reason one may wish to repeatedly include a particular file?
Thanks guys!
Going into my second year of uni and it's about time I really knuckled down, endured many headaches and cracked on with some C++!
Quick question about '#pragma once'. I know it makes sure a header file is only included once in the compilation. Well, source files, not strictly headers
Anyway, I wanted to know if it's worth including this in EVERY header file I write, or is there a particular reason one may wish to repeatedly include a particular file?
Thanks guys!
- Home
- » Viewing Profile: Topics: Dezachu

Find content