Hello Community,
First apology if this isnt the right position for this question. Now to my problem at the beginning i've moved a sprite only by move and a x.xx number. Now i try to move it with sf::Clock to not be bound at the framerate. But then sometimes the sprite moves through the texture. My OS is Windows 7 home premium. Here is a little snippet of the code:
window.setFramerateLimit(60);
sf::Clock clock;
while (window.isOpen())
{
sf::Time elapsedTime = clock.restart();
speed = elapsedTime.asSeconds() * Game::speed;
sprite.move(speed, gravity);
//checking for collisions etc.
}
For more code just ask.
P.S: Sorry for the bad english.
If you're asking why your player falls through the floor sometimes (just guessing), that probably has more to do with how you test for collisions than anything else, so you should probably show us that code.
Hi but with the max. framerate my sprite dont fall through the floor, but here is the code:
if(playerrect.intersects(rect)){
if(playerrect.top - playerrect.height < rsprite.getPosition().y && playerrect.left + playerrect.width > rect.left + 1 && playerrect.left < rect.left + rect.width - 1 && playerrect.top + playerrect.height < rect.top + rect.height + 1)
collisiontop = true;
currentcollision = true;
}else
collisiontop = false;
if(playerrect.intersects(rect)){
if(psprite.getPosition().y > rsprite.getPosition().y)
collisionbottom = true;
}else
collisionbottom = false;
if(playerrect.intersects(rect)){
if(psprite.getPosition().x < rsprite.getPosition().x)
collisionleft = true;
}else
collisionleft = false;
if(playerrect.intersects(rect)){
if(psprite.getPosition().x > rsprite.getPosition().x)
collisionright = true;
}else
collisionright = false;
if(collisiontop == true){
Game::jumpable = true;
Game::collisiontop = true;
}
if(collisionleft == true && collisiontop == false){
Game::collisionleft = true;
}
if(collisionright == true && collisiontop == false){
Game::collisionright = true;
}
if(collisionbottom == true){
Game::collisionbottom = true;
}
if(Game::collisiontop == true && collisiontop == false){
currentcollision = false;
}
if(posY < rect.top - 250 && currentcollision == true){
Game::up = false;
currentcollision = false;
}