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

Pages: [1]
1
General / Hard Coding Value of Sprite's Position
« on: June 21, 2017, 05:46:11 am »
If I hard code the value of Sprite's position, will the sprite's position change if the program is used in a different device?

I wonder if stays the same or the program will stretch the sprite depending on the size of the device.  Mostly in my code, I position all my sprite with absolute value. Is it okay to hard code the value of sprite position?
 

2
General / Swapping element in a Vector
« on: June 13, 2017, 11:36:55 am »
Can anyone point out what's wrong with my code? I tried swapping the vector's element to another element of the vector itself using std::swap(). It worked, the member class of each other have swapped but the problem is that in the left image the Blue Bar did not swap with the Red Bar.




Main.cpp


int main()
{
        unsigned int width = 800;
        unsigned int height = 600;

        sf::RenderWindow window(sf::VideoMode(width, height), "Algorithm Visualizer");

        std::vector<Bar> bars;

        for (size_t i = 0; i < 10; i++)
        {
                Bar bar(sf::Vector2f(5, i + 10), sf::Vector2f(100 + i * 10, 300));
                bars.push_back(bar);
        }

        std::cout << "Blue 1 height:  " << bars[1].getHeight() << std::endl;
        std::cout << "Blue 1 pos X:  " << bars[1].getPos().x << std::endl;
        std::cout << "Red 9 height:  " << bars[9].getHeight() << std::endl;
        std::cout << "Red 9  pos X:  " << bars[9].getPos().x << std::endl;

        bars[1].setColor(sf::Color::Blue);
        bars[9].setColor(sf::Color::Red);

        std::swap(bars[1], bars[9]);

        std::cout << "After swapping new value: " << std::endl;

        std::cout << "Blue 1 height:  " << bars[1].getHeight() << std::endl;
        std::cout << "Blue 1 pos X:  " << bars[1].getPos().x << std::endl;
        std::cout << "Red 9 height:  " << bars[9].getHeight() << std::endl;
        std::cout << "Red 9 pos X:  " << bars[9].getPos().x << std::endl;
 

Bar.cpp

Bar::Bar(sf::Vector2f size, sf::Vector2f pos)
{
        rect.setSize(size);
        rect.setOrigin(rect.getOrigin().x, size.y);
        rect.setPosition(pos);
}

Bar::~Bar()
{
}

void Bar::setColor(sf::Color color)
{
        rect.setFillColor(color);
}

void Bar::setProperty(ShapeProperty property)
{
        rect.setFillColor(property.fill_);
        rect.setOutlineColor(property.outline_);
        rect.setOutlineThickness(property.thickness_);
}

void Bar::setPosition(sf::Vector2f pos)
{
        rect.setPosition(pos);
}

void Bar::setSize(sf::Vector2f size)
{
        rect.setOrigin(rect.getOrigin().x, size.y);
        rect.setSize(size);
}

void Bar::draw(sf::RenderWindow & window)
{
        window.draw(rect);
}


void Bar::update()
{
}

int Bar::getWidth()
{
        return rect.getGlobalBounds().width;
}

int Bar::getHeight()
{
        return rect.getGlobalBounds().height;
}


sf::Vector2f Bar::getPos()
{
        return rect.getPosition();
}
 


3
Graphics / Failed Loading Texture - Reason Out of Memory
« on: June 06, 2017, 04:30:03 pm »
I'm trying to load a Texture with a size of 32,768 x 4096 but it failed to do so. What does it mean of this error? how can I solve it? also, what is the maximum size SFML can load textures?

4
Graphics / One Texture Shared to Multiple Sprites
« on: May 26, 2017, 05:38:50 pm »
Is it possible to share only one texture into a different Sprites in order to minimize creating texture object?
or should I just make a Copy of it?



sf::Sprite enemy;
sf::Sprite player;

sf::Texture *texture;
texture = new Texture();

if (texture->loadFromFile("assets/player.png"))
player.setTexture(texture);

if (texture->loadFromFile("assets/enemy.png"))
enemy.setTexture(texture);

 

Pages: [1]
anything