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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - dodo

Pages: [1]
1
Graphics / Re: Problem with displaying multiple sprites (1.6)
« on: February 15, 2013, 04:08:03 pm »
thanks for the quick reply, i will be switching to sfml 2.

the problem is at the constructor:
Player()
        {
                Sprite.SetImage(Image);
        }
 

if i manually call "Player1.SetImage(Image);", and set Image to public, it works. "Player1.Sprite.SetImage(Image);" doesnt work, could someone explain this to me?

EDIT: God I am dumb, i drew the class instead of the Sprite <.< sorry for wasting your time

2
Graphics / Problem with displaying multiple sprites (1.6)
« on: February 15, 2013, 02:37:06 pm »
I tried to display 3 sprites while loading the image only once, using this tutorial: http://www.sfml-dev.org/tutorials/1.6/graphics-sprite.php (bottom).

Instead of 3 200*200 Sprites, 3 white pixels are displayed: http://i.imgur.com/qEmUDSo.png

Code:
#include "stdafx.h"
#include <SFML/Graphics.hpp>
#include <iostream>

class Player : public sf::Sprite
{
public:

        static bool Init(const std::string &ImageFile)
        {
                return Image.LoadFromFile(ImageFile);
        }

        Player()
        {
                Sprite.SetImage(Image);
        }

private:

        static sf::Image Image;

        sf::Sprite Sprite;
};
sf::Image Player::Image;

int main()
{      
        sf::RenderWindow App(sf::VideoMode(800, 600, 32), "pewpew");
        App.UseVerticalSync(true);

        if(!Player::Init("player.png"))
                return EXIT_FAILURE;

        Player Player1;
        Player Player2;
        Player Player3;

        Player1.SetPosition(50.0f, 50.0f);
        Player2.SetPosition(300.0f, 350.0f);
        Player3.SetPosition(550.0f, 200.0f);

        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();

                        if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::F1))
                        {
                                sf::Image Screenshot = App.Capture();
                                Screenshot.SaveToFile("screenshot.png");
                                std::cout << "Screenshot saved!" << std::endl;
                        }
                }

                App.Clear(sf::Color(0, 150, 0));

                App.Draw(Player1);
                App.Draw(Player2);
                App.Draw(Player3);

                App.Display();
        }

        return EXIT_SUCCESS;
}

Pages: [1]