Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: texture and sprite  (Read 3000 times)

0 Members and 2 Guests are viewing this topic.

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
texture and sprite
« on: May 09, 2015, 06:15:07 pm »
Can i load more than one image to texture and set texture to sprite?

example:
sf::Texture texture;
texture.loadFromFile("image1.png");
texture.loadFromFile("image2.png");

does the image1 get destroyed? if not how can i choose which image i want to render.
example:
sprite.setTexture(texture.choosewhatiwanttoset("image1.png"));
sprite.setTexture(texture.choosewhatiwanttoset("image2.png"));
...
same question for sprite,
window.draw(sprite.choosewhatiwanttorender("image1.png"));

thanks



BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: texture and sprite
« Reply #1 on: May 09, 2015, 06:47:33 pm »
Can i load more than one image to texture and set texture to sprite?
Short: No, yes.
Long: No you cannot load multiple "images" intro one sf::Texture, You can use/set sprite to draw a sf::Texture

does the image1 get destroyed? if not how can i choose which image i want to render.
Short: yes, ?
Long: The image1.png will be released/destroyed, and image2.png will be loaded.

Global answer: You probably want to make two sf::Texture and load each one with different image.
Then you can use sf::Sprite to chose which one you want to draw via sf::Sprite spr1; spr1.setTexture(...) function. That's how you can go around switching around what you want to draw.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: texture and sprite
« Reply #2 on: May 09, 2015, 07:57:21 pm »
You can use/set sprite to draw a sf::Texture
i mean can i set more then one texture to sprite without the previous texture getting destroyed,
but you already answered it in global answer.

thanks :)

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: texture and sprite
« Reply #3 on: May 10, 2015, 12:42:45 pm »
@BaneTrapper

by the way, would you recommend having one sprite object for each tetxture object? so you will only load 1 time per texture, instead of one sprite for more than one texture

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: texture and sprite
« Reply #4 on: May 10, 2015, 01:27:35 pm »
Sprites setTexture(...) function is cheap, you can use only one sprite, and change texture which you want to display/draw.

In the end it depends on what you want to do, there shouldn't be any noticeable difference doing it ether way.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: texture and sprite
« Reply #5 on: May 10, 2015, 01:47:58 pm »
@BaneTrapper
Im just thinking about the process when using only one sprite,by the way thank you i get it all now.

can you help me in my new thread?
http://en.sfml-dev.org/forums/index.php?topic=18118.0

 

anything