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

Pages: [1]
1
General / Unable to load image SFML 2.3
« on: June 03, 2015, 10:21:51 pm »
Before you start barking at me about incorrect file paths, I'd like to remind you that I've been using SFML for a long time on both Windows and Linux. I have ported an app from Linux to Windows on Visual Studio and I have the assets directory under the VC++ Project file directory. When I launch my program it says that SFML is unable to load the image. I have used an older version of SFML under my Linux machine so I don't know what's exactly changed with regards to how SFML loads images. The image I have is a *.png file so I assume SFML supports it because they use a png example on the tutorials. I've also duplicated the assets folder everywhere (silly, I know) and I still get the same error. I even added the absolute path of the image file and I still get the same error. This code runs under Linux just fine, so I honestly don't see how it can't work under Windows 8.1 64-bit. All libraries are linked and SFML runs just fine. I even compiled and ran the tutorial example and that ran fine too. I'm convinced that this is a SFML 2.3 bug.

#include <SFML/Graphics.hpp>
#include <iostream>
using namespace std;

int main()
{
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");

        sf::Texture texture;
        if (!texture.loadFromFile("assets/graphics/explorer.png"))
                cerr << "Unable to load image!" << endl;

        sf::Sprite sprite;
        sprite.setTexture(texture);

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

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

        return 0;
}

This is how I load the image. Before you start pointing the finger at pointers I also tried them as raw variables, but I still get the same error. I've also checked the drawing method, but that isn't important right now because not even the image is being loaded. I might roll back to version 2.1 since that was the most stable version on my part.

Can anyone explain why on SFML 2.3 loading images has suddenly stopped working? :-)) Is there another dependency I'm supposed to also link to?

2
Graphics / Bullet not firing
« on: April 24, 2014, 07:30:28 am »
So I have a player class that just shoots a bullet and for some reason it is not shooting the bullet the way I want it to. The problem is trying to get the bullet to shoot from the player's location in the direction upwards. So, player would have this:


void Player::shoot(Bullet &bullet)
{
    bullet.isFired(true);
}

 

All the shoot function does is simply tell the bullet object that it has been fired and should now update, thus:

void Bullet::update(sf::Vector2f position, sf::Vector2f speed)
{
    if (wasFired == true)
    {
        setPosition(position.x + speed.x, position.y + speed.y);
    }
    else if (wasFired == false)
    {
        wasFired = false;
    }
}
 

The code here is only raw and written on the fly just to get a base up and running. And in the initialisation thereof:

void Game::update()
{
    bullet.update(tank.getPosition(), sf::Vector2f(0, -10));
}
 

When I run the game, the bullet moves by 10 units upwards, but it does not update the position thereafter; however it does update the position according to the player's x-axis.

3
Graphics / Query about draw function
« on: February 18, 2014, 09:14:14 pm »
Suppose I have a class like this:

Class GraphicalEntity : public sf::Drawable, sf::Transformable
{
public:
GraphicalEntity();

private:
sf::Sprite aSprite
void draw(sf::RenderTarget &target, sf::RenderStates states) const;
};
 

And then there's the implementation thereof with draw():

draw(sf::RenderTarget &target, sf::RenderStates states) const
{
aSprite.setPosition(100, 100); // Error
target.draw(aSprite);
}
 

I get an error when I want to set the position of the sprite, visual studio complains:

Quote
Error: no instance of overloaded function "Sprite::setPosition" matches the argument list and object (the object has type qualifies that prevent a match)
argument types are: (int,int)
object type is: const Sprite

However, if I declare a sprite within draw's implementation then I can easily apply various transforms. What I want to know is, how can I use aSprite within the draw function? If I declare a local sprite within the draw() function, then I can't use it outside the function.


4
Graphics / Help with Tile collisions
« on: February 06, 2014, 04:13:47 pm »
So far I got collisions between sprites that are of type sf::Sprite; but my tiles are not of type sf::Sprite so the collisions do not work. My tiles are of sf::VertexArray type, and I used the tile-map as a base from

http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php

I can get my player to check for collisions with the tile-map, but the only problem is that because all the numbers represent a tile the collision check returns true.

Using the code from the tutorial above, how can I implement a simple tile collision with a player that has a type sf::Sprite? Thanks for reading.

5
General / Help with Tile Map tutorial
« on: January 23, 2014, 10:26:16 pm »
Hi, I've been following the tile map tutorial on the SFML website and so far my tiles load very well, but one improvement I've been trying to make is having the map be loaded from a *.txt file. Essentially instead of having

I want to be able to contain those values in a *.txt file and load them so I don't have to keep recompiling. The problem is that when I create a raw array the amount of characters is fixed and I do not want that. I want to be able to store the characters from the text file into a vector array. I tried doing this but to not avail. I'd like to know how I can go about this and what I need to change either in the load() function to accommodate this.

From what I understand, a vertex array is based on a vector array, so by analogy my raw array would be treated as a vector array thereby dynamically allocating memory as required. Is this correct?

http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php

I've been following the tutorial mentioned in the foresaid link.

tl;dr:

1. I want to load a map from a .txt file while still being able to load tilesets in conjunction thereof. How can I implement this?
2. I want to use a vector array, rather than a raw array. (If necessary)

Pages: [1]
anything