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

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

0 Members and 1 Guest are viewing this topic.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
How to draw a sprite to another sprite
« Reply #15 on: January 26, 2011, 10:16:25 pm »
You don't need SFML 2, Image::Copy is all that you need. Unless you do more than a plain pixel copy (like applying an overlay color, transformating it, etc.).
Laurent Gomila - SFML developer

mercurio7891

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
How to draw a sprite to another sprite
« Reply #16 on: January 27, 2011, 05:51:22 am »
To the OP, i think groogy method would be good.  You can create a 2D scene graph to represent your aircraft. So you have something like
Code: [Select]

            Aircraft
            /       \
 Front wing     Back wing
 hardpoint1     hardpoint2


When drawing, you just need to tranverse your aircraft tree and draw respectively.

I do not know how sfml really batch their sprites, but if you are going to batch your sprites, it doesn't really affect if you draw 3 extra sprites or anything. For your record the the amount of vertices being push to the GPU every frame is in the order of mbs. My vertex cache is 32mb big for my game and I push them into the GPU in blocks of 8mb, so your few extra sprite is not going to really impact your game much. Don't worry too much =).

regards

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #17 on: January 27, 2011, 02:11:40 pm »
Thanks Laurent that Copy function look like what I want  :D

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #18 on: January 27, 2011, 02:27:30 pm »
But this function is not in class sf::Sprite  :roll:  :cry: how can I do it with sf::Sprite please?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
How to draw a sprite to another sprite
« Reply #19 on: January 27, 2011, 02:47:43 pm »
Is there a reason why you need to do it with sprites and not images?
Laurent Gomila - SFML developer

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #20 on: January 27, 2011, 04:32:22 pm »
Because I can draw Sprite but I cannot draw Image  :roll:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
How to draw a sprite to another sprite
« Reply #21 on: January 27, 2011, 04:37:16 pm »
But you don't need to draw them, you just want to draw the resulting image, right?

Look. Here is what you want to do:
Code: [Select]
load image1
load image2

create sprite1(image1)
create sprite2(image2)

create sprite3 = sprite1 + sprite2
draw sprite3


And here is what I'm talking about:
Code: [Select]
load image1
load image2

create image3 = image1 + image2

create sprite3(image3)
draw sprite3

Is it clearer?
Laurent Gomila - SFML developer

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #22 on: January 27, 2011, 04:41:51 pm »
Yes that looks good, so I use + to compare some sprites or images, right?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
How to draw a sprite to another sprite
« Reply #23 on: January 27, 2011, 04:44:31 pm »
This was just some pseudo-algo language, not actual C++... ;)
Laurent Gomila - SFML developer

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #24 on: January 27, 2011, 05:02:21 pm »
OK I will copy images to one image and then use sprite.setimage() to put there final picture is it okey?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
How to draw a sprite to another sprite
« Reply #25 on: January 27, 2011, 06:01:33 pm »
Absolutely.
Laurent Gomila - SFML developer

reDo

  • Full Member
  • ***
  • Posts: 104
    • View Profile
How to draw a sprite to another sprite
« Reply #26 on: January 27, 2011, 06:15:35 pm »
Thank for all help  :D