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

Pages: [1]
1
General / [SOLVED ]Do calculations after window.clear(), is it bad?
« on: February 24, 2017, 01:29:40 pm »
Hi,

so I did a small code for do a sort of tilemap, that uses an std::vector of a class that inherits of sf::Sprite. So basically, a

std::vector<sf::Sprite> tilemap(i, sf::Sprite(sprite));

But I have to draw this tilemap in the constructor, where other operations are done. So I am basically doing this:

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

    std::vector<Tile> tilemap(i, Tile(tile));

    for(int a = 0; a < tilemap.size(); a++)
    {
        tilemap[a].setPosition(a * xpos, ypos);
    }

    for(int a = 0; a < tilemap.size(); a++)
    {
        window.draw(tilemap[a]);
    }

     window.draw(hero);

     window.display();

This is my till class, that inherits of sf::Sprite.

Tile::Tile(sf::Texture texture, int x, int y, int scalex, int scaley)
{
    t = texture;
    xpos = x; ypos = y; scx = scalex; scy = scaley;

    this->setTexture(t);
    this->setPosition(xpos, ypos);
    this->setScale(scx, scy);
}

Tile::Tile()
{

}

So my question is, is it bad, to do things beetween window.clear and window.display, or that doesn't matter? Will that impact the framerate of the program?

Thanks

Ah, I have of course done a class for do the vector and all, TileArray:

#include "TileArray.h"

TileArray::TileArray(int I, int x, int y, Tile &tile, sf::RenderWindow &window)
{
    i = I;
    xpos = x; ypos = y;

    std::vector<Tile> tilemap(i, Tile(tile));

    for(int a = 0; a < tilemap.size(); a++)
    {
        tilemap[a].setPosition(a * xpos, ypos);
    }

    for(int a = 0; a < tilemap.size(); a++)
    {
        window.draw(tilemap[a]);
    }
}

2
General / SFML 2.4 bugged?
« on: November 20, 2016, 12:53:04 pm »
Hello everyone. I saw that sfml 2.4 was released a few days ago, so I decided to try it out. I installed it and copied/pasted the example code of the sfml tutorial to see if it works. But the console said that he failed to open window's context or something like that. So I thought that maybe, it was my installation of the new sfml that was wrong. I installed the sfml 2.2 again to test, but with the old version, it works perfecty. Am I just stupid, or is it a real problem?

3
General / [Solved] sf::Event in Button class
« on: August 03, 2016, 08:42:33 pm »
Hi,
I have made a class Button and inside I've placed a bool Button::isClicked(). With this code it worked fine:

bool Button::isClicked()
{
    sf::Event event;

    sf::Vector2f mousePosition = static_cast<sf::Vector2f>(sf::Mouse::getPosition());

    if(this->getGlobalBounds().contains(mousePosition)
    && sf::Mouse::isButtonPressed(sf::Mouse::Left)) //if clicked
    {
        return true;
    }
    else
    {
        return false;
    }
}

But I couldn't place other buttons on the same place on an "other window" (I did a thing like this:)

if(status == "MENU")
                  {
                        ...

                        window.clear();
                        window.draw(...);
                   }
                   if(status == "GAME")
                  {
                          ...

                        window.clear();
                        window.draw(...);
                   }
                   

So I tried to do something like that:

bool Button::isClicked()
{
    sf::Event event;

    sf::Vector2f mousePosition = static_cast<sf::Vector2f>(sf::Mouse::getPosition());

    if(this->getGlobalBounds().contains(mousePosition)
    && event.type == sf::Event::MouseButtonReleased
    && event.mouseButton.button == sf::Mouse::Left) //if clicked
    {
        return true;
    }
    else
    {
        return false;
    }
}

but it doesn't work. The program runs fine (I have no errors) but I can't press the buttons. So I tried to put that code in the main.cpp for see if it is the fault of the event that could be written with a wrong syntax:

while(window.isOpen())
                 {

                  ...

                sf::Vector2f mousePosition = static_cast<sf::Vector2f>(sf::Mouse::getPosition());

                 if(button.getGlobalBounds().contains(mousePosition)
                 && event.type == sf::Event::MouseButtonReleased
                 && event.mouseButton.button == sf::Mouse::Left) //if clicked
                 {
                       //Do something
                 }

                   }

   Instread of:

while(window.isOpen())
                 {

                  ...

                 if(button.isClicked()) //if clicked
                 {
                       //Do something
                 }

                   }

And that works. Any ideas?

Pages: [1]
anything