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

Pages: 1 [2]
16
Graphics / how does Transform::setOrigin works ?
« on: July 09, 2017, 04:23:32 am »
hi...
for example i have this code
Code: [Select]
rect.setOrigin(rect.getSize().x / 2, rect.getSize().y / 2);
rect.rotate(1);
rect.setOrigin(0, 0);

the rect doesn't rotate according to the origin in the middle but according to the origin of top left
why ?

17
General / resetting origin over and over
« on: July 08, 2017, 05:15:33 am »
hi, so I want to reset origin over and over :)
so it went like this
when I want to rotate the origin will be at the middle
when I want to check if the shape is out of window, the origin will be either top-left or bottom-right
does setting the origin over and over cause speed difference

18
SFML website / no time where topic were made
« on: July 05, 2017, 06:08:16 am »
hi...I wonder why there is no time where topic were made... ???

19
Graphics / sfml-graphics-2.dll is missing
« on: June 20, 2017, 12:09:38 pm »
weird...I am pretty sure that sfml-graphics-2.dll never existed yet when I tried to open the program it said that...
I have put all the .dll excluding audio and OPENAL

20
hey guys...now I know how vertex array works..
so I have a game that has an enemy that multiplies by 2 when you killed it...
so considering I use loop to draw it...it gets too slow eventually
now.. I have this class
class Zombie
{
private :
    sf::RectangleShape Rect;
    const float speed;
    int health;
public :
    Zombie(const sf::RenderWindow& window, float speedVal, int healthVal) :
        speed(speedVal),
        health(healthVal)
    {
        std::srand(time(0));
        Rect.setSize(sf::Vector2f(37, 37));
        Rect.setOrigin(Rect.getSize().x / 2, Rect.getSize().y / 2);
        sf::Vector2f position;
        rand();
        position.x = rand() % window.getSize().x;
        rand();
        position.y = rand() % window.getSize().y;
        Rect.setPosition(position);
        Rect.setFillColor(sf::Color(0, 200, 0));
    }
    void move(User& user)
    {
        if (Rect.getPosition().x < user.getPosition().x)
        {
            Rect.move(speed, 0);
        }
        else if (Rect.getPosition().x > user.getPosition().x)
        {
            Rect.move(-(speed), 0);
        }
        if (Rect.getPosition().y < user.getPosition().y)
        {
            Rect.move(0, speed);
        }
        else if (Rect.getPosition().y > user.getPosition().y)
        {
            Rect.move(0, -(speed));
        }
        sf::Vector2f difference;
        difference.x = user.getPosition().x - Rect.getPosition().x;
        difference.y = user.getPosition().y - Rect.getPosition().y;
        float face = std::atan2(difference.y, difference.x);
        float degrees = face * pi / 180;
        Rect.setRotation(degrees);
    }
    void reInit(const sf::RenderWindow& window)
    {
        srand(time(0));
        rand();
        sf::Vector2f position;
        position.x = rand() % window.getSize().x;
        rand();
        position.y = rand() % window.getSize().y;
        Rect.setPosition(position);
        health = 50;
    }
    void decHealth(int val)
    {
        health -= val;
    }
    const int& getHealth() const
    {
        return health;
    }
    const sf::Shape& getShape() const
    {
        return Rect;
    }
    bool hit(User& user)
    {
        if (Rect.getGlobalBounds().intersects(user.getGlobalBounds())) return true;
        return false;
    }
};

 

and I have this code
std::vector<Zombie> zombie;
 

considering the fact that when it gets too big it becomes slow...
how do I compress it to vertex array rather how do I transform only a member of the vertex array

21
Graphics / Movement
« on: May 05, 2017, 04:37:53 pm »
hey, uh..there's a little problem here.. I'm trying to make experiment with movement based on angle..(only 0 works fine)

I wonder what's wrong..
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <cmath>
#include <iostream>

class User
{
private :
    sf::RectangleShape Rect;
    const float speed;
    const float rotation;
public :
    User() :
        speed(0.8),
        rotation(0.2)
    {
        Rect.setSize(sf::Vector2f(38, 17));
        Rect.setOrigin(Rect.getSize().x / 2, Rect.getSize().y / 2);
        Rect.move(Rect.getSize().x / 2, Rect.getSize().y / 2);
    }
    sf::Shape &getShape()
    {
        return Rect;
    }
    void Action(const sf::RenderWindow &window)
    {
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        {
            Rect.rotate(rotation);
        }
        else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        {
            Rect.rotate(-(rotation));
        }
        if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        {
            sf::Vector2f Direction;
            Direction.x = speed * std::cos(Rect.getRotation());
            Direction.y = speed * std::sin(Rect.getRotation());
            Rect.move(Direction);
        }
        check(window);
    }
    void check(const sf::RenderWindow &window)
    {
        if (Rect.getPosition().x < 0) Rect.move(speed, 0);
        else if (Rect.getPosition().x > window.getSize().x) Rect.move(-(speed), 0);
        if (Rect.getPosition().y < 0) Rect.move(0, speed);
        else if (Rect.getPosition().y > window.getSize().y) Rect.move(0, -(speed));
    }
};

int main()
{
    sf::RenderWindow window(sf::VideoMode(900, 600), "some window");
    User user;
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed) window.close();
        }
        user.Action(window);
        window.clear(sf::Color::Black);
        window.draw(user.getShape());
        window.display();
        std::cout << user.getShape().getRotation() << std::endl;
    }
}

 

Pages: 1 [2]
anything