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

Author Topic: Sprite not displaying?  (Read 2130 times)

0 Members and 1 Guest are viewing this topic.

raccoon12

  • Newbie
  • *
  • Posts: 1
    • View Profile
Sprite not displaying?
« on: April 14, 2010, 05:44:14 pm »
Whenever I run my program, I don't get the messagebox that should pop up if I don't have the image in the right spot, but I don't see it on the screen.

Head.png


And my code:
Code: [Select]

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <windows.h>
#include <vector>
#include <iostream>


int main()
{
std::string wordArr[32] = {"integer", "character", "void", "main", "function", "implicit", "null", "include", "typename", "cast", "debug", "command"};
for(int i = 0; i < 32; i++)
{
std::cout << wordArr[i] << "\n";
}

sf::RenderWindow App(sf::VideoMode(800, 600, 32), "Hangman: Programmer's edition");
const sf::Input& Input = App.GetInput();

sf::Image img;
if(!img.LoadFromFile("sprites/head.png"))
{
MessageBox(NULL, "Error loading headsprite", "Error loading sprite part: head, located in 'sprites/head.png'.", MB_OK);
}

sf::Sprite Sprite;
Sprite.SetColor(sf::Color(0, 255, 255, 128));
Sprite.SetX(200.f);
Sprite.SetY(100.f);
Sprite.SetPosition(200.f, 100.f);
Sprite.SetRotation(30.f);
Sprite.SetCenter(0, 0);
Sprite.SetScaleX(2.f);
Sprite.SetScaleY(0.5f);
Sprite.SetScale(2.f, 0.5f);
Sprite.SetBlendMode(sf::Blend::Multiply);

Sprite.Move(10, 5);
Sprite.Rotate(90);
Sprite.Scale(1.5f, 1.5f);
Sprite.SetImage(img);


while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();

if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}
App.Draw(Sprite);
App.Display();
}

return EXIT_SUCCESS;
}
[/code]

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Re: Sprite not displaying?
« Reply #1 on: April 14, 2010, 06:40:04 pm »
You can't see it because the background is black and your sprite is with multiply blending mode. Multiplying any color with black results in black.

try commenting this line
Code: [Select]
Sprite.SetBlendMode(sf::Blend::Multiply);
Pluma - Plug-in Management Framework

Mindiell

  • Hero Member
  • *****
  • Posts: 1261
    • ICQ Messenger - 41484135
    • View Profile
Re: Sprite not displaying?
« Reply #2 on: April 15, 2010, 08:34:49 am »
Quote from: "raccoon12"
And my code:
Code: [Select]

Sprite.SetColor(sf::Color(0, 255, 255, 128));
Sprite.SetX(200.f);
Sprite.SetY(100.f);
Sprite.SetPosition(200.f, 100.f);
Sprite.SetRotation(30.f);
Sprite.SetCenter(0, 0);
Sprite.SetScaleX(2.f);
Sprite.SetScaleY(0.5f);
Sprite.SetScale(2.f, 0.5f);
Sprite.SetBlendMode(sf::Blend::Multiply);

Sprite.Move(10, 5);
Sprite.Rotate(90);
Sprite.Scale(1.5f, 1.5f);
Sprite.SetImage(img);

Why not simply
Code: [Select]
Sprite.SetColor(sf::Color(0, 255, 255, 128));
Sprite.SetPosition(210.f, 105.f);
Sprite.Rotate(120);
Sprite.SetScale(3.0f, 0.75f);
Sprite.SetCenter(0, 0); // Be careful, rotation and scale will be based on (0,0) center when drawing the sprite
Sprite.SetBlendMode(sf::Blend::Multiply);
Sprite.SetImage(img);
Mindiell
----

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Sprite not displaying?
« Reply #3 on: April 15, 2010, 01:52:19 pm »
I think raccoon12 was just trying things out and forgot to comment/remove some lines  :wink:
Pluma - Plug-in Management Framework