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

Pages: [1] 2 3
1
General / Re: Unable to load image SFML 2.3
« on: June 04, 2015, 01:09:23 am »
That depends on how you compile your project and not on your operating system!

32 bits is the default.

I'm running Windows 8.1 64-bit and have the 64-bit version of the library and am compiling and running the library on a 64-bit configration. I honestly don't know what's going on here. I should probably try an earlier version and see if that might help.

2
General / Re: Unable to load image SFML 2.3
« on: June 04, 2015, 12:54:50 am »
I've updated the question so it can include a minimal-working example of the problem I have. As you can see, I load in the texture through the file, then I allocate the texture to a sprite which is then drawn. The error 'Unable to load image' is the only error that is shown up on the console - no other errors appear. This is strange because in earlier versions of SFML there used to be an error message. Also, I downloaded this package from SFML's website and it was the 64-bit version for Visual Studio 2013. Although that's obvious, it was just for reassurrance sake. Can anyone run the code in the original post and see if they're experiencing a problem? Should I just use the 32-bit version of the libraries instead?

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

4
Graphics / Re: Bullet not firing
« on: April 25, 2014, 12:32:59 am »
It makes sense now! Because the update function was in the while(windowisOpen) loop it was constantly initialising the bullet's position to that of the player's; but we only had to initialise the position if the bullet was shot. The only thing in this case that needed to be updated was the position. Thanks for your help!

5
Graphics / Re: Bullet not firing
« on: April 24, 2014, 10:52:08 pm »
Sorry lol. I've deleted the else statement:- repose en paix!

6
Graphics / Re: Bullet not firing
« on: April 24, 2014, 09:40:43 pm »
Thanks for your responses. This is what I've amended now:

]
void Bullet::update(sf::Vector2f position, sf::Vector2f speed, sf::Time elapsedTime)
{
    if (wasFired)
    {
        move(speed * elapsedTime.asSeconds());
    }
    else
    {
        wasFired = false;
    }
}
 

I've inserted a new parameter to take into account the elapsed time, which is initialised here:

void Game::update()
{
    alien.activateAI(true);
    bullet.update(tank.getPosition(), sf::Vector2f(0, -10), pClock.getElapsedTime());
}
 

Suffice it to say the bullet fires; albeit it does not fire from the initial position of the tank. The problem is that it only fires from the bullet's own initial position. I have been able to update the bullet's position relative to the tank's position but then I can't shoot a bullet as intended. It seems I can't do one or the other for now. Is there any way I can resolve this issue? My first solution was to create an updatePosition(@param) function which simply updates the position of the bullet according to where the tank is. Are there better solutions?

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

8
General / Re: SFML on Linux - Shared Library versions
« on: April 22, 2014, 05:40:36 am »
Ubuntu 14.04 has SFML 2.1 in its repositories. I suggest upgrading to spare the hassle; just make sure you link your libraries right. I use Code::Blocks btw.

9
Graphics / Re: Query about draw function
« on: February 21, 2014, 10:14:06 pm »
Update: I scouted through some old code of mine and reused it in conjunction with the vertex arrays example you referred me to. I got a tile loader up and running thanks, now I just need to apply collisions somehow.

10
Graphics / Re: Query about draw function
« on: February 21, 2014, 02:45:51 pm »
Use one sprite per tile, not one for everything. You shouldn't have to modify anything when you draw, everything should be ready (and ideally prepared once, in an init/load function).

Have a look at the vertex array tutorial, and especially at the tilemap example at the end.

I have looked at it, but the problem is I use a 2D vector array, whereas the tutorial uses a const int; and VectorArray is 1D. I wouldn't know how to convert. Infact, I used this tutorial before I commenced work on another tile loader, namely because I couldn't get collisions up and running.

11
Graphics / Re: Query about draw function
« on: February 20, 2014, 11:29:03 pm »
Thanks for your response. The reason I asked this question is because my tile map can't be drawn if I set positions and the textureRect according to a use case within the draw() function; for example:

                        case 0:
                                tile_sprite.setPosition(j * TileSize.x, i * TileSize.y);
                                tile_sprite.setTextureRect(sf::IntRect(i * 0, j * 0, TileSize.x, TileSize.y));
                                break;

                        case 1:
                                tile_sprite.setPosition(j * TileSize.x, i * TileSize.y);
                                tile_sprite.setTextureRect(sf::IntRect(i * 40, j * 0, TileSize.x, TileSize.y));
                                break;
 

Declaring a local sprite within the draw() function and using the above transformations will draw the tilemap, but how can I apply these transformation outside the draw() function while still being able to draw the sprite? I've tried placing the transformations and the use cases in a separate function, but that causes the tilemap not to be drawn.

12
Graphics / Re: Query about draw function
« on: February 18, 2014, 09:40:01 pm »
Yes, I understand that; but I don't want to be limited by a Sprite only being declared within the draw() function. Is there a way for me to draw a sprite with the transforms applied externally? Say I want to be able to do something with the sprite externally, I can't do that through the draw() function; hence I want to be able to have more flexibility in how I use a sprite without it being constant. If the problem is

void draw(sf::RenderTarget &target, sf::RenderStates states) const;
 

Then what can I do to resolve this issue?

13
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.


14
Graphics / Re: Help with Tile collisions
« on: February 11, 2014, 04:30:05 pm »
There is nothing wrong with that line of code. That is a well known method to convert from a 2D coordinate into a 1D array index. But hey, you just know that all your other code is producing the correct values, right? :/

Edit: except that it shouldn't be a floating point value...

Please tell me you're not assuming pTiles is a 2D array, right? :-/ It's 1D to begin with.

15
Graphics / Re: Help with Tile collisions
« on: February 10, 2014, 11:05:23 pm »
Quote from: gop_t3r
it appears the issue hasn't been resolved and am convinced that this has definitely something to do with the way tileNo is calculated [...]

There doesn't seem to be anything wrong with how the tile number is calculated. It's probably the input values to the calculation that are wrong (i.e. you're returning something funky from 'map.getTileSize()' and/or 'map.getDimensions()').

Quote from: gop_t3r
Have you tested the code to see if you can detect the issue?

Where is the code? :/

The code is everywhere as far as I'm aware. Suffice it to say that I've tested everything and there is nothing obscure as to the values produced. All the input values are correct and I'm convinced that there's something weird with the way the computer treats where the player is located at on the grid.

What I noticed is that a collision only happens when the player is touching the bottom of the tile. I really just want a collision which returns true if any of the sides are touched by the player.

Pages: [1] 2 3