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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Jan666

Pages: [1] 2
1
Graphics / How animation with touch button
« on: September 22, 2022, 09:40:43 pm »
Hello,
i have a Spritesheet (the animation is in 24 Frames), now it only plays when my finger is on the touch Button (RectangleShape button). But i need to change this, i want that the SpriteSheet animation still plays automaticly one time when i touched the Button, without hold the finger on and without repeating the animation, how can i fix it? Here is the part if the code:


...

//init  Sprite( its a SpriteSheet)
sf::Texture texture;
texture.loadFromFile("test1.png");
sf::Sprite sprite;
sprite.setPosition(300, 500);
sprite.setScale(5, 5);
sprite.setTexture(texture);

//init Button
sf::RectangleShape button;
button.setSize(sf::Vector2f(600, 200));
button.setPosition( sf::Vector2f(500, 1900));
button.setFillColor(sf::Color::Red);

sf::Clock clock;
sf::Vector2f animRect;
       
        while (window.isOpen())
        {                                                      
       
       
                sf::Event event;

//Set Touch Coordinates to Screen
sf::Vector2i pixelPos = sf::Touch::getPosition(0, window);
sf::Vector2f worldPos = window.mapPixelToCoords(pixelPos);


//Set the Rect for the part of the SpriteSheet
sprite.setTextureRect(sf::IntRect (animRect.x * 101, animRect.y * 232, 101, 232));
               
                while (window.pollEvent(event))
                {                                              
                       
                if (event.type == sf::Event::Closed)
                                window.close();
                        }                      
//FloatRect fot the button Sprite              
sf::FloatRect btnRect = button.getGlobalBounds();
               
                //if touch the Button
                if(btnRect.contains(worldPos)){
                       
                        if(clock.getElapsedTime().asSeconds() >= 0.2){
                animRect.x++;
                if(animRect.x * 101 >= texture.getSize().x)
        animRect.x = 0;
           animRect.y = 0;
                clock.restart();
                        }                              
                }                      
 


2
Graphics / Manage different screens with touch button
« on: September 15, 2022, 08:48:47 pm »
Hello, i have a question i follow the Tutorial "manage for different Screens" on github. Now i wanna i build in a RectangleShape (btn1), who will used for a touch button to cgange on another screen, how i can handld this, here is my code:
class screen_1: public cscreen {
       
        public:        
         screen_1(void);        
        virtual int Run(sf::RenderWindow &App);
        void btn(sf::RenderWindow &App);
       
        private:
        sf::RectangleShape btn1;
        sf::FloatRect btn1Rect;
};

screen_1::screen_1(void){
       
        btn1.setSize(sf::Vector2f(500, 100));
        btn1.setPosition(sf::Vector2f(400, 500));
        btn1.setFillColor(sf::Color::Red);
       
}

void screen_1::btn(sf::RenderWindow &App){
       
        sf::Vector2i pixelPos = sf::Touch::getPosition(0, App);
                sf::Vector2f worldPos = App.mapPixelToCoords(pixelPos);
               
                btn1Rect = btn1.getGlobalBounds();
       
        if(btn1Rect.contains(worldPos)){
               
                screen_2::Run(); //dont work :(
               
}

int screen_1::Run(sf::RenderWindow &App){
       
        sf::Event event;        
        bool Running = true;
       
        while (Running) {              
       
        while (App.pollEvent(event))
        {                              
        if (event.type == sf::Event::Closed)                    {                      
                        return (-1);                   
                        }
                       
                               
                               
                               
                        }
        }
        App.clear(sf::Color(25, 200, 30));
        App.draw(btn1);
        App.display();
       
        }
        return (-1);
}



 


3
Graphics / If function for collision not working together
« on: August 15, 2022, 10:23:08 am »
Can someone Tell me why these four if functions not working together and how to fix it?

(playerBounds.intersects(wallBounds)){

if(wallBounds.left < playerBounds.left + playerBounds.width )

player.setPosition(wallBounds.left + wallBounds.width, playerBounds.top);


 if(playerBounds.left < wallBounds.left)

  player.setPosition(wallBounds.left - playerBounds.width, playerBounds.top);

if(wallBounds.top < playerBounds.top + playerBounds.height )

player.setPosition(playerBounds.left,  wallBounds.top + wallBounds.height);


 if(playerBounds.top < wallBounds.top)

  player.setPosition(playerBounds.left  , wallBounds.top - playerBounds.height);
   
}
 

4
Graphics / Collision Opposite Side
« on: August 09, 2022, 12:26:15 am »
Hey,
I have a question, the collision  between playerBounds and WallBounds works very good, but on the opposite Side not,  can somebody Tell me why?
 if(playerBounds.intersects(wallBounds)){
                       
        // Left Collision
 if (playerBounds.left < wallBounds.left + wallBounds.width && playerBounds.left + playerBounds.width > wallBounds.left)
         {
         
          player.setPosition(playerBounds.left, wallBounds.top - playerBounds.height);
          }
         
 
          // Boton Collision not working yet
 if( playerBounds.left >wallBounds.left + wallBounds.width && playerBounds.left + playerBounds.width > wallBounds.left)
          {
               
                player.setPosition(playerBounds.left, wallBounds.top - wallBounds.height);
            }  

 

5
Graphics / Erase only one rectangleShape
« on: July 21, 2022, 09:35:28 am »
Hi,
I have a player and when he intersects with the door, the door should erase, but the player still erase all doors, how can i fix it that he only erase the door he intersects, here is my code:
RectangleShape door;
std::vector<RectangleShape> doors(3u);

....

 (auto& door: doors){
 FloatRect playerBounds = player.getGlobalBounds();
 FloatRect doorBounds =  door.getGlobalBounds();
       
          for(int i = 0; i < doors.size(); i++){
       
         if(doorBounds.intersects(playerBounds)){
               
                doors.erase(doors.begin(), doors.end());
               
         }
 }     
       
 window.draw(doors[1]);
 window.draw(doors[2]);
       
       
 }

 

6
Graphics / Collision dont work exactly
« on: July 18, 2022, 12:33:45 pm »
Hello,
I have a collision question, the following code works, but when the player come the wall closer, the wall attracts the player like a magnet, can someone tell me how to fix it?

for (auto& wall : walls){
       
        FloatRect wallBounds = wall.getGlobalBounds();
        FloatRect playerBounds = player.getGlobalBounds();
       
nextPos = playerBounds;
nextPos.left += Vec.x ;
nextPos.top += Vec.y;
       
        if(wallBounds.intersects(nextPos)){
                       
        //Bottom Collision
 if (Vec.y > 0 && playerBounds.left < wallBounds.left + wallBounds.width && playerBounds.left + playerBounds.width > wallBounds.left )
         {
        Vec.y = 0;
          player.setPosition(playerBounds.left, wallBounds.top - playerBounds.height);
          }
        //Top Collision
if(Vec.y < 0 && playerBounds.left < wallBounds.left + wallBounds.width && playerBounds.left + playerBounds.width > wallBounds.left)
          {
                Vec.y = 0;
                player.setPosition(playerBounds.left, wallBounds.top + wallBounds.height);
            }  
 //Right Collision
if(Vec.x > 0 && playerBounds.top < wallBounds.top + wallBounds.height && playerBounds.top + playerBounds.height > wallBounds.top)
                   {
                  Vec.x = 0;
                 player.setPosition(wallBounds.left - playerBounds.width, playerBounds.top);
                   }
//Left Collision
if (Vec.x < 0 && playerBounds.top < wallBounds.top + wallBounds.height && playerBounds.top + playerBounds.height > wallBounds.top)
                      {
                      Vec.x = 0;
player.setPosition(wallBounds.left + wallBounds.width , playerBounds.top);

                      }
           
      }
 

7
Graphics / Collision with multiple RectangleShapes
« on: July 17, 2022, 12:17:10 pm »
Hello, i have a question, i have made multiple RectangleShapes
with following code:
RectangleShape* wall = new RectangleShape;
FloatRect wallRect = wall->getGlobalBounds();

std::vector<RectangleShape> walls;
walls.push_back(*wall);

...

for(int i = 0; i < walls.size(); i++){
       
        walls[i].setPosition(Vector2f(300, 2000));
     
     walls[i].setSize(Vector2f(50, 300));
        walls[1].setPosition(Vector2f(300, 800));
        walls[1].setFillColor(Color::Blue);
        walls[1].setSize(Vector2f(500, 100));
        walls[2].setPosition(Vector2f(900, 500));
        walls[2].setFillColor(Color::Yellow);
        window.draw(walls[i]);

 

How i can do the collision detection, i have
a simple RectangleShape for the Player, it doesnt work when i give both a FloatRect + getGlobslsBounds and intersects them, someone know?


8
Graphics / Touch joystick border radius
« on: June 18, 2022, 12:37:12 pm »
Hello,
I wanna create a touch controller, a small circle i can move around with a finger inside a bigger circle. But i have no idea, how i set a  border radius, that the smaller circle still movable just inside it, any help?

9
Graphics / floatrect move with a Sprite?
« on: June 14, 2022, 11:57:12 am »
Hello,
I have following problem:
I have an enemySprite who has a floatrect, a hitbox for the Player, that reduce his health when he collide with. But when the enemy move this floatrect stand still, any idea how to "parenting" this floatrect to the enemySprite when moves?

10
Graphics / HITBOX FloatRect
« on: June 10, 2022, 09:27:14 am »
Hello, i need a Hitbox for my player that is smaller than the Player Sprite Rect. I read that the FloatRect can do it, but theres is no getglbslBounds for it, can someonr give me an advise, how i can use a floatrect with globalbounds for my player sprite?

11
Graphics / Bullets turn direction failure
« on: May 30, 2022, 10:44:57 am »
Hello, i have a bullet direction Problem. I want that my Player can shot bullets to the right and left direction. I used this piece of code for that (I used setScale for flip the Players Direction):
bulletVec[i].bltFire(0, 2 * plr.plrSprite.getScale().x);
 
The Problem noq is that the firing Bullets always turning the direction when i turn the players direction, how i can change this?

12
Graphics / Bullet Face direction problem
« on: May 27, 2022, 08:04:33 am »
Hello, i need a solution for a 2d shot game. The player still shot to the right direction, i have no idea how i change the bullet direction when he walk to the left side?


//Touch Shot Button
if(btn.btnRect3.contains(worldPos)){
                                                                       
                           isFiring = true;      
}


//bullet shot details

if(isFiring == true){
       
        bullet newBullet (Vector2f( 20, 20));
        newBullet.bulletSetPos(Vector2f(player.playerSprite.getPosition().x  + 60, player.playerSprite.getPosition().y + 100));
        bulletVec.push_back(newBullet);
        isFiring = false;
   }



 

Any Ideas

13
Graphics / Player View dont stop with the Player
« on: May 23, 2022, 11:50:10 am »
Hi
I have another question about sf::View. It is center to my Player and follow him. But if the Player collide with a wall and stop the view still moves if the move button is pressed. So here is my code when the Player  collide:
...

void player::plrBounce(Vector2f &wallBounce){
       
wallBounce = plrSprite.getPosition();
        plrSprite.setPosition(wallBounce.x, wallBounce.y +5);
       
}

...

if(plr.plrSprite.getGlobalBounds().intersects(WallRect.getGlobalBounds())){
       
                plr.plrBounce(wallBounce);

 

and here is my view setting:

View plrview( FloatRect(0, 0, 1300, 2600));
    plrview.setCenter(plr.plrSprite.getPosition());

 

So what could i do that the playerview is parenting to the player and stops when he stops??

14
Graphics / Sf::View and How can i fix things on display?
« on: May 22, 2022, 08:06:09 am »
Hi,
I try to make 2d sidescroller with Touch on mobilephone. I used sf::View to follow my Player, and it works. But i have also 3 Buttons on display they move away. How can i fix them on display?

15
Graphics / 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???
               
}

 

Pages: [1] 2