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 - Daora

Pages: [1]
1
Graphics / Re: move function doesnt work with variables?
« on: April 23, 2017, 05:20:05 pm »
omg im fucking stupid haha

2
Graphics / move function doesnt work with variables?
« on: April 23, 2017, 04:36:47 pm »
I have a weird problem. I Just started with SFML yesterday and wanted to make a simple game for the beginning, now i want to move a rectangle object 0.5pixel in x and y with every loop, so when i write
ball.move(0.5, 0.5);
everything works as expected, but if i put x and y into variables it stops working, anyone know what causes this behavior?

Here is the full code for reference:

#include <SFML/Graphics.hpp>
#include <stdio.h>
#include <iostream>

int main()
{
        sf::RenderWindow window(sf::VideoMode(1280, 718), "", sf::Style::Close);
        sf::RectangleShape ball(sf::Vector2f(15, 15));

        ball.setPosition(640, 359);

        int p1score = 0;
        int p2score = 0;

        int xspeed = 0.5;
        int yspeed = 0.5;

        int x = ball.getPosition().x;
        int y = ball.getPosition().y;

       

        //mainloop
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        //close
                        if (event.type == sf::Event::Closed)
                        {
                                window.close();
                        }

                }

                window.clear(sf::Color::Black);



                ball.move(xspeed, yspeed);

                window.draw(ball);
               
                window.display();
        }


        return 0;
}




Pages: [1]