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 - 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 / Re: Swapping element in a Vector
« on: June 13, 2017, 12:43:55 pm »
Yeah, it worked. thanks by the way  8) I'm trying to make a bubble sort algorithm. Do you think this would completely swap them both?

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

        sf::Vector2f temp = bars[1].getPos();
        bars[1].setPosition(bars[9].getPos());
        bars[9].setPosition(temp);



3
General / Re: Swapping element in a Vector
« on: June 13, 2017, 12:14:22 pm »
After swapping the red/190 bar is no longer at index 9, so what you print are the properties of the blue/110 bar. But the thing is, there's still a red/190 and a blue/110 bar, just organized differently in your vector.

Oh, I see I'm outputting the wrong way. but how should I swap each other properties?
Will this good enough?

        sf::Vector2f temp = bars[1].getPos();
        bars[1].setPosition(bars[9].getPos());
        bars[9].setPosition(temp);

bar[


4
General / Re: Swapping element in a Vector
« on: June 13, 2017, 11:51:15 am »
You just changed their index in the vector, but their properties remain the same. Moving a bar from index 9 to index 1 won't magically change its graphical position, after the swap it is still red and at x = 190.

You said that x = 190 after the swap but I'm confused why's output  X = 110 after the swapping?

5
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();
}
 


6
Graphics / Re: Failed Loading Texture - Reason Out of Memory
« on: June 06, 2017, 05:20:51 pm »
I have 8GB ram and only 4GB is in use.

The image is a texture atlas which contains all the game objects that I can use in my game. I put it all into one image to minimise instantiating multiple textures.

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

8
Graphics / Re: One Texture Shared to Multiple Sprites
« on: May 26, 2017, 06:31:41 pm »
You should just try out the code you posted and see if it works  :)
I'm too lazy to start a new project and do set up all over again.   ;D

I'll just have to implement the alternative approach you have said and I think that's how it should be done anyway.

9
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