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.


Messages - Jan666

Pages: 1 [2] 3 4 5
16
Graphics / Re: Erase only one rectangleShape
« on: July 22, 2022, 12:00:47 pm »
The remove thing dont work i try this, but still booth doors gone,

RectangleShape door;

std::vector<RectangleShape> doors(3);

std::vector<RectangleShape>::iterator it;

...

while (window.isOpen())
        {
               
                sf::Event event;
                while (window.pollEvent(event));

...

for (int j = 0; j < doors.size(); j++){
       
       
       
        doors[j].setFillColor(Color::Cyan);
       
        doors[1].setSize(Vector2f(100, 100));
        doors[1].setPosition(Vector2f(650, 1000));
       
        doors[2].setSize(Vector2f(100, 100));
     doors[2].setPosition(Vector2f(650, 700));
       
       
 }
 
 for (auto& door: doors){

 FloatRect playerBounds = player.getGlobalBounds();
 
 FloatRect doorBounds = door.getGlobalBounds();
 
 for ( auto it = doors.begin(); it != doors.end();)
  {
               
  if(doorBounds. intersects(playerBounds)) {
       
 
         it = doors.erase(it);
         
          }
          else
          {
          ++it;
          }
         
           
       
 window.draw(doors[1]);
 window.draw(doors[2]);
       
       
 }
 
 }

 

17
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]);
       
       
 }

 

18
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);

                      }
           
      }
 

19
Graphics / Re: Collision with multiple RectangleShapes
« on: July 17, 2022, 07:44:49 pm »
Thanks, this help me a lot

20
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?


21
Graphics / Re: Touch joystick border radius
« on: June 22, 2022, 12:29:21 pm »
I dont understand, can you explain it in a code example ?

22
Graphics / Re: Touch joystick border radius
« on: June 22, 2022, 12:04:52 am »
Okay i got it, can you give me an advise how to stop the joytsick circle when it reach the distance?

if(plr.contains(mapPos)){

diff.x =circOutRectPos.x - circIn.getPosition().x;
diff.y =circOutRectPos.y - circIn.getPosition().y;
distance = sqrt(diff.x * diff.x + diff.y * diff.y);

circIn.setPosition(circIn.getPosition().x, mapPos.x);
circIn.setPosition(circIn.getPosition().y, mapPos.y);

 if(distance < 175)
????????
 

How i can stop the circIn (Circle for touch ), it should slidly move along the radius border (distance),

23
Graphics / Re: Touch joystick border radius
« on: June 20, 2022, 11:22:48 pm »
Yes i know the theory but i cant get fix it with the code, but thsnks for your reply

24
Graphics / Re: Touch joystick border radius
« on: June 20, 2022, 04:08:03 pm »
I have android, i wanna build the touch controll by myself just with a circle, but iam not fit in math, sin, cos etc. I just need to know how i can rotate/ move a circle in a radius

25
Graphics / Re: Touch joystick border radius
« on: June 20, 2022, 02:10:21 pm »
Can samone give me an advise
                sf::Vector2i currPos = sf::Touch::getPosition(0, window);
                        sf::Vector2f mapPos = window.mapPixelToCoords(currPos);
                       
float distance = sqrt((circIn.getPosition().x * circIn.getPosition().x) + (circIn.getPosition().y * circIn.getPosition().y));



angle = atan2(circIn.getPosition().x, circIn.getPosition().y);


angle = angle * 180 / 3.141592654f;
 



plr = circIn.getGlobalBounds();

if(plr.contains(mapPos)){

sf::Vector2i touch = sf::Touch::getPosition(0, window);


touch.x = Origin.x + 150 * cos(angle);
touch.y = Origin.y + 150 * sin(angle);
circIn.setPosition(touch.x , touch.y);
 

It doenst work anyway

26
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?

27
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?

28
Graphics / Re: HITBOX FloatRect
« on: June 10, 2022, 12:21:35 pm »
Okay i find solution:
FloatRect playerHitbox = PlayerSprite.getGlobalBounds();
 
 if(playerHitbox.intersects(EnemySprite.getGlobalBounds())){

 

How i can set the size for playerHitbox?

29
Graphics / Re: HITBOX FloatRect
« on: June 10, 2022, 11:42:04 am »
I have no idea yet how to modify a rect returned by globalbounds, is there any example out in the web?

30
Graphics / Re: HITBOX FloatRect
« on: June 10, 2022, 09:42:09 am »
How i reduce a sprite rect, there is no setSize function for it?

Pages: 1 [2] 3 4 5