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 - Jiggered

Pages: [1]
1
Graphics / Re: Render window pointer and sprites
« on: August 31, 2012, 01:08:13 pm »
I did originally assign it to the sprite, but I JUST realised, I assigned it in the wrong order, I assigned before the image was even loaded.

I'm not sure how to load the sprite inside my class file, but outside my function, I just get errors

So now the sprite loads, just not sure how to load it outside of functions.


2
Graphics / Render window pointer and sprites
« on: August 31, 2012, 12:37:08 pm »
I'm trying to load sprites through the renderwindow that I'm pointing to, it seems to work fine without errors, but when loading a sprite all I get is the white dot. I've tried everything I can think of, and still it refuses to render.

.h
class Invador
{
public:
Invador(sf::RenderWindow& window) :
        m_window(window)
                {}

    float Draw()
    {
                imag.LoadFromFile("sprite.png");
                sprite.SetPosition(10,1);
        m_window.Draw(sprite);
                return 0;
    }

private:
    sf::RenderWindow& m_window;
        sf::Image imag;
        sf::Sprite sprite;
       
};
 

main
int main()
{
sf::RenderWindow window(sf::VideoMode(SC_WIDTH, SC_HEIGHT, 32), "SFML Window");

Invador Draw(window);

while (window.IsOpened())
     {
         sf::Event Event;
         while (window.GetEvent(Event))
         {
             if (Event.Type == sf::Event::Closed)
                 window.Close();
         }
 
                 float elapsedTime = window.GetFrameTime();

                 /*cout << elapsedTime * 100 << endl;*/

         window.Clear();
                 Draw.Draw();

         window.Display();
     }
        return EXIT_SUCCESS;
}
 

3
Graphics / Re: Member function sprite call
« on: August 30, 2012, 03:43:56 pm »
Ok so going from the draw function, I get an error about the pointer

Error:
Quote
error C2662: 'sf::RenderTarget::Draw' : cannot convert 'this' pointer from 'const sf::RenderWindow' to 'sf::RenderTarget &'

void Invador::draw (const sf::RenderWindow& window)
{
        window.Draw(sprite);
}

the "window" part of the "window.draw(sprite)" gets the error.

4
Graphics / Re: Member function sprite call
« on: August 30, 2012, 03:16:48 pm »

int classFunction (sf::Renderwindow* window){
    window->draw(sprite); //here you use -> instead of a dot.
    return 0;
}

and in the main(), when you call the classFunction:

invadorObject.classFunction(&window);

hope that it helps :)

Thanks for the replies, I'm just testing both and seeing which would help me in the long run.
But in this example I don't really know what you meant by

invadorObject.classFunction(&window);

I just get the error "a nonstatic member reference must be relative to a specific object" when I use the call

Invador.draw(&window);

5
Graphics / Re: Member function sprite call
« on: August 30, 2012, 12:37:34 am »
Yeah I'm aware that the usual call is "window.draw(sprite)". But because my sprite and image are loaded via my class file, I can't call them using my main function because the window is defined in my main, not my class.

My class:

class Invador
{
public :

    static bool Init(const std::string& ImageFile)
    {
        return alien.LoadFromFile("sprite.png");
    }

    Invador()
    {
        sprite.SetImage(alien);
                sprite.SetPosition(100,100);
    }

private :

    static sf::Image alien;

    sf::Sprite sprite;
};

6
Graphics / Member function sprite call
« on: August 29, 2012, 02:43:24 pm »
Hi,
I used the example that is on the sfml doc pages that uses member functions as image management. http://www.sfml-dev.org/tutorials/1.4/graphics-sprite.php

And I implemented it fine, no errors. But I'm confused as how to call it? Because you need to apply it to the render window and call the sprite itself, but the render window is defined in my main, and my sprite is defined inside my class.

7
System / Re: Applying clock to movements
« on: August 24, 2012, 02:30:59 pm »
I looked through the example and that won't work for me because I'm using SFML 1.6. I tried re-writing it for 1.6 and I couldn't get it to work.

Are there any other solutions?

8
System / Re: Applying clock to movements
« on: August 24, 2012, 06:20:13 am »
The problem I am having is that I'm trying to make a sprite move across the screen, the movement of the sprite works fine, but without applying timesteps to make it move on every second (or whatever I set the timestep to) it just zooms across at full speed.

I don't have any other example, and I mixed them because I thought they were meant to go together, I guess not.

9
System / Applying clock to movements
« on: August 10, 2012, 03:52:55 pm »
In my game app I have moving sprites, but without them being tied to a clock they just fly across the screen. So I need help fixing my clock code so that my sprites move with the clock timer.

                 Sprite.Move(-1 * elapsedTime ,0);
                 if(elapsedTime>REFRESH_RATE){
                        // get current system time
                        GetSystemTime(&st);
                         if(Sprite.GetPosition().x <= 50)
                                 {
                                        Sprite.Move(0, 10 * elapsedTime);
                                 } else if (Sprite.GetPosition().y == 60)
                                 {
                                         Sprite.Move(1 * elapsedTime,0);
                                 }
                        Clock.Reset();
                }

Pages: [1]