Sign in to follow this  
BaneTrapper

SFML question about Image/Texture

Recommended Posts

Hello.
I am currently learning SFML, i am following tutorial.
I came across a point that i am suposed to do this
[CODE]
sf::Sprite MySpriteName;
MySpriteName.SetImage(image,true);
//Except sf::Sprite.SetImage does not exist.

I included everything
<SFML/Window.hpp>
<SFML/Graphics.hpp>
<SFML/System.hpp>
[/CODE]
Only thing it has is Texture, and i am reading its not same thing...
A guy downloaded SFML 2.0 linked it, and used that code...
My IDE does not provide it as possibility, and compiler is giving me error:
[CODE]
C:\c++ Project\The Knight of Avalion2\Tile.cpp|5|error: 'class sf::Sprite' has no member named 'SetImage'|
[/CODE]

EDIT:
Here is what sf::Sprite class holds from official site
[url="http://www.sfml-dev.org/documentation/2.0/classsf_1_1Sprite.php"]http://www.sfml-dev....f_1_1Sprite.php[/url]

Question is, are sf::Texture replacing sf::Image cause there is still sf::Image in the class, but i cant use it... Edited by BaneTrapper

Share this post


Link to post
Share on other sites
I can tell you right now that the code :

sf::Sprite MySpriteName;
MySpriteName.SetImage(image,true);

Is not SFML 2.0 as Laurent changed the naming convention of methods to always start with a lowercase letter, and sprites take a Texture instead of an Image.

In terms of things that are drawn, the Texture class replaced the Image class. The Image class is used for loading, manipulating, and saving image files which is why it still exists in the system.

Basically, when you define a Texture object, that data is stored on the GPU to help speed up the drawing. An instance of an Image, however, is stored in local memory where it can be accessed and changed easier than if it were on the GPU.

Share this post


Link to post
Share on other sites
Jebbles is spot on. This is most likely version 1.6 code. Which means even if you switch code to

[CODE]
sf::Texture image;
image.loadFromFile("image.png");
sf::Sprite mySpriteName;
mySpriteName.setTexture(image);
[/CODE]
there will still be some other things which might need to be changed. There were many changes up until the release candidate of sfml 2.0 which makes following many tutorials online a little difficult. However, it can be done if you put in some effort and make the changes as needed yourself.

Good Luck!

Share this post


Link to post
Share on other sites
[quote name='frazchaudhry' timestamp='1347715783' post='4980366']
Jebbles is spot on. This is most likely version 1.6 code. Which means even if you switch code to

[CODE]
sf::Texture image;
image.loadFromFile("image.png");
sf::Sprite mySpriteName;
mySpriteName.setTexture(image);
[/CODE]
there will still be some other things which might need to be changed. There were many changes up until the release candidate of sfml 2.0 which makes following many tutorials online a little difficult. However, it can be done if you put in some effort and make the changes as needed yourself.

Good Luck!
[/quote]

Its kinda difficult to find a proper tutorial,
That will show how to manipulate pixels in texture/image,
make audio,

Allot of tutorials got sfml 2.0 in context and are 1.6 100% since they use sf::Sprite.SetImage();
its annoying that people do that.

Thanks on encouragement!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this