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

Author Topic: How to mix two sprites?  (Read 1529 times)

0 Members and 1 Guest are viewing this topic.

GamDev

  • Newbie
  • *
  • Posts: 29
    • View Profile
How to mix two sprites?
« on: May 13, 2018, 06:36:10 pm »
Good afternoon, can someone tell me how to mix both sprites like we can see in this screenshot?

Tigre Pablito

  • Full Member
  • ***
  • Posts: 226
    • View Profile
    • Email
Re: How to mix two sprites?
« Reply #1 on: May 14, 2018, 02:38:38 am »
Hello (or good night here in Bs As)

I would try setting both images' alpha to half (128) and overlapping them

You can try this:

sprite1.Color = new Color(255, 255, 255, 128);
sprite1.Position = new Vector2f(someX, someY);
window.Draw(sprite1);

sprite2.Color = new Color(255, 255, 255, 128);
sprite2.Position = new Vector2f(someX, someY);
window.Draw(sprite2);
 

Hope this helps

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: How to mix two sprites?
« Reply #2 on: May 14, 2018, 08:43:16 am »
Note that Tigre's code is in C#, just to prevent some confusion here. :D

Texture blending like this is probably best done in a shader.
Alternative you can, as already pointed out, set the sprite's alpha value and then use blend modes to try and get a similar result.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything