Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Not walk trough th Rect?  (Read 1178 times)

0 Members and 1 Guest are viewing this topic.

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Not walk trough th Rect?
« on: May 20, 2022, 01:49:34 pm »
Hello again,
Sry i dont want annoying to fill this Forum with newbie questions, but this Forum give me the best answers.

So i am working on a sidescroller, in the middle of the Screen is a RectangleShape, and if i collide it with my playerSprite, the Background Moves. Now i want that the Player not go through the Rectangle, ho can i fix it, here is my codepart:


if(playerSprite.getGlobalBounds().intersects(rect.getGlobalBounds())){
               
        backgroundSprite.move( 0, -3);
        // playerSprite dont walk trough rect???
               
}

 

Jan666

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
Re: Not walk trough th Rect?
« Reply #1 on: May 20, 2022, 03:36:29 pm »
I got it
Solution:



void player::plrBounce(){

Vector2f wallBounce = plrSprite.getPosition();
plrSprite.setPosition(wallBounce.x, wallBounce.y -5);

 

anything