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

Author Topic: Can you draw a shaped sprite?  (Read 2853 times)

0 Members and 1 Guest are viewing this topic.

moonbeamer2234

  • Newbie
  • *
  • Posts: 10
    • View Profile
Can you draw a shaped sprite?
« on: July 24, 2012, 04:42:20 pm »
Ive drawn a character for my game in gimp, but when i display sprite it brings up the character and the surrounding white box. Is there anyway to make the surounding white box transparent or to make the surrounding white box blend in with whatever enviroment its in? ;D

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Can you draw a shaped sprite?
« Reply #1 on: July 24, 2012, 04:45:38 pm »
sf::Image::createMaskFromColor() to specify a color which becomes transparent.

Or use an alpha channel and save the image as PNG file.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11028
    • View Profile
    • development blog
    • Email
Re: Can you draw a shaped sprite?
« Reply #2 on: July 24, 2012, 04:46:21 pm »
What image format are you using?
Do you have the background of the character set to transparent?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
Re: Can you draw a shaped sprite?
« Reply #3 on: July 24, 2012, 04:46:46 pm »
It's a problem with your texture (or maybe code), show as how you draw.

solver

  • Newbie
  • *
  • Posts: 12
    • View Profile
    • Email
Re: Can you draw a shaped sprite?
« Reply #4 on: July 24, 2012, 05:06:31 pm »
1. Launch gimp
2. Create new file
3. Layer -> Mask -> Add layer mask -> "Black (full transparency)" -> OK
4. Layer -> Aply layer mask
5. Draw your image and save it with .png.

moonbeamer2234

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Can you draw a shaped sprite?
« Reply #5 on: July 24, 2012, 05:27:05 pm »
Thank you so much that definatly helped!!! But is there any way to do it within the code?

moonbeamer2234

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Can you draw a shaped sprite?
« Reply #6 on: July 24, 2012, 05:28:52 pm »
because for collision that could be a problem since collision would be considered the transparent box, not the character itself

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Can you draw a shaped sprite?
« Reply #7 on: July 25, 2012, 09:37:33 am »
But is there any way to do it within the code?
Yes, read my answer.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11028
    • View Profile
    • development blog
    • Email
Re: Can you draw a shaped sprite?
« Reply #8 on: July 25, 2012, 03:25:51 pm »
I don't get what you're talking about with collision and transparent and not transparent, could please alaborate on this and mabye explain how you do or want to do collision testing?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

moonbeamer2234

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Can you draw a shaped sprite?
« Reply #9 on: July 25, 2012, 04:22:33 pm »
When i use sprite collision wont the transparent area produce the collision area. For example if my character collides with an object. The character colliding wont actually produce and effect if it collides with said object. When the transparent box collides with said object wont the effect be produced? Or is there some way to work around this. Like this:
(I saw on some other guys post that you dont like this code format but i cant figure out the other one so im sorry, this is what i learned at cplusplus.org ;/)  :'(
Code: [Select]
void collision(sf::Sprite character, sf::RectangleShape &enemy)
{
    if(character.getPosition().x + character.getSize().x < enemy.getPosition().x ||
           character.getPosition().x > enemy.getPosition().x + enemy.getSize().x ||
           character.getPosition().y + character.getSize().y < enemy.getPosition().y ||
           character.getPosition().y > enemy.getPosition().y + enemy.getSize().y)}
{
}
else
{std::Cout << "Collision" << std::endl;}
Wont character.getposition().x = The x including the transparent area. And wont character.getposition().y = the y including the transparent area? So when the transparent area colides with enemy it will cout collision instead of couting collision when the sprite inside the transparent area collides with enemy?