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

Author Topic: How to draw a sprite to another sprite  (Read 8559 times)

0 Members and 1 Guest are viewing this topic.

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« on: January 21, 2011, 08:53:48 am »
How can I draw a sprite to another sprite example
Code: [Select]
sf::Sprite pic1(image1);
sf::Sprite pic2(image2);
pic2.Draw(pic1);  

How ca I do this?  :roll:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to draw a sprite to another sprite
« Reply #1 on: January 21, 2011, 09:33:37 am »
With SFML 1 you can't. However you can copy an image to another.

Why do you want to do that?
Laurent Gomila - SFML developer

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #2 on: January 21, 2011, 02:47:08 pm »
I forgot the reason but with SFML 2 it will be possible?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to draw a sprite to another sprite
« Reply #3 on: January 21, 2011, 02:51:09 pm »
It is already possible.

Quote
I forgot the reason

So why are you asking? :roll:
Laurent Gomila - SFML developer

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #4 on: January 21, 2011, 03:21:36 pm »
I forgot the reason! But with SFML 1.6 this code doesn't work.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
How to draw a sprite to another sprite
« Reply #5 on: January 21, 2011, 03:51:27 pm »
Quote
I forgot the reason!

Ok I got it, what I mean is: if you don't know why you're asking, then who cares about the answer? Why are we having this discussion? It's hard to solve a problem that doesn't exist.

Quote
But with SFML 1.6 this code doesn't work.

Ok but I can't give you an alternative because none of us knows what you want to do...
Laurent Gomila - SFML developer

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #6 on: January 21, 2011, 06:05:36 pm »
When I remember I will write it  :wink:

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #7 on: January 26, 2011, 07:13:08 pm »
I got it.
I am going to do a game with aircraft. And you can tune up your plane during in the game, so the plane has to consist of parts. This is that situation. You draw parts to one sprite and then draw always this sprite to one position, instead of drawing many parts to many positions. So so what you recommend me?  :roll:   :?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
How to draw a sprite to another sprite
« Reply #8 on: January 26, 2011, 07:27:23 pm »
That is more an design issue. Though just thinking quick I would use relative positions and use the conversion methods to transform them to world coordinates. This way we can draw the sprites seperatly.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #9 on: January 26, 2011, 07:37:51 pm »
But I think it is not so good like draw it one time to one sprite and then draw always it like one picture.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
How to draw a sprite to another sprite
« Reply #10 on: January 26, 2011, 08:24:18 pm »
then have it like one image? If you want it to be static you don't need it in separate parts. If you want the sprites to change over time or when something happens then you are forced to do like I said.

What you more or less wants/describes are creating an image at runtime(which is available in SFML2). But since it's for a game you can simply have the image already premade with all the separate parts in it.

Though if you like I said, want the parts to change, like position, size, image and so on then you have to do it like I said or something similar. Here "drawing a sprite to a sprite" would only mean that every time we change the object's state in a way that the parts are affected we would have to do everything again.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #11 on: January 26, 2011, 08:32:55 pm »
Quote from: "Groogy"

What you more or less wants/describes are creating an image at runtime(which is available in SFML2).

Thanks I wanted exactly this which is availaible in SFML 2, so I will wait for a little while :D, so I can draw a sprite to another sprite in SFML2

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #12 on: January 26, 2011, 08:41:56 pm »
Quote from: "reDo"
Quote from: "Groogy"

What you more or less wants/describes are creating an image at runtime(which is available in SFML2).

Thanks I wanted exactly this which is availaible in SFML 2, so I will wait for a little while :D, so I can draw a sprite to another sprite in SFML2

There's no need to wait to use SFML2, I'm using it in a game right now and it works fine.

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #13 on: January 26, 2011, 08:52:56 pm »
Can you give here example code of drawing sprite to another sprite please?  :roll:

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
How to draw a sprite to another sprite
« Reply #14 on: January 26, 2011, 09:10:07 pm »
Code: [Select]
sf::RenderImage image;
image.Create( /* look in the documentation for values */ );
image.Draw(theFirstSprite);
image.Draw(theSecondSprite);
image.Draw(theThirdSprite);
image.Display();

sf::Sprite wholeSprite(image.GetImage());
window.Draw(wholeSprite);


Though I think you don't actually understand what you actually want to do. For in-game graphics, the sprites will change so often that you will recreate the sprite every frame.

Documentation: http://www.sfml-dev.org/documentation/2.0/classsf_1_1RenderImage.htm
Developer and Maker of rbSFML and Programmer at Paradox Development Studio