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

Author Topic: if position with sfml  (Read 4816 times)

0 Members and 1 Guest are viewing this topic.

jancsika998

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
if position with sfml
« on: November 26, 2021, 10:38:16 am »
I want to ask for help that I don't know how to use if for position in sfml.
For example, if I want something to go as long as it is given inside the if.

I have this code:

#include <SFML\Graphics.hpp>
#include<SFML\Audio.hpp>
#include<SFML\Network.hpp>

int main{
sf::RenderWindow window(sf::VideoMode(1080, 600), "sfml tutorial", sf::Style::Close | sf::Style::Resize);
sf::View Player1(sf::Vector2f(-32.f, 0.f), sf::Vector2f(512.f, 512.f));
sf::RectangleShape slot1(sf::Vector2f(64.f, 128.f));

slot1.setPosition(-264.f, 128.f);

while(window.isOpen())
        {
               
                sf::Event evnt;
               
               
                while(window.pollEvent(evnt))
                {
                        if(evnt.type == evnt.Closed)
                        {
                                window.close();
                        }
                }
window.draw(slot1);
window.display();
                }
               
       
        }
       
        return 0;
}
I want make one animation with this Rectangle, while something Dont true.

Sorry for my english.

« Last Edit: November 26, 2021, 11:11:57 am by eXpl0it3r »

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: if position with sfml
« Reply #1 on: November 26, 2021, 11:54:43 am »
I didn't know for sure if I got what you mean by "something to go as long as it is given inside the if".


do you want to move the slot1 to move around when you press some key on the keyboard? if that's it, check this:
https://www.sfml-dev.org/tutorials/2.5/window-inputs.php#keyboard

OBS.: you forgot to clear() the window in your code.
Visit my game site (and hopefully help funding it? )
Website | IndieDB

jancsika998

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: if position with sfml
« Reply #2 on: November 26, 2021, 06:22:55 pm »
for example

if(player position <= object position)
{
  do anything.
}

Stauricus

  • Sr. Member
  • ****
  • Posts: 369
    • View Profile
    • A Mafia Graphic Novel
    • Email
Re: if position with sfml
« Reply #3 on: November 26, 2021, 08:12:17 pm »

while (player position <= object position)
{
  //do anything
}

this is not really SFML related... have a check on some basic tutorials about loops and conditions (do, for, while)...
Visit my game site (and hopefully help funding it? )
Website | IndieDB

 

anything