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

Pages: [1]
1
Window / Re: Drawing/Displaying sprites from another function
« on: October 22, 2012, 09:24:01 am »
You can for instance pass the render window as reference to the function and draw things from there.

I tried to pass it as reference but whenever i use a command such as *Window.draw(Sprite) in the function i get this error: error: request for member 'draw' in 'Window', which is of non-class type 'sf::RenderWindow*'

Why do i get this error?

Here's the code. It is just a test code with only 2 functions. soooo, it's really easy to understand.

#include <SFML/Graphics.hpp>
#include <iostream>

void Test(sf::RenderWindow *Window)
{
    sf::Texture Texture;
    Texture.loadFromFile("GreenCircle.png");

    sf::Sprite Sprite;
    Sprite.setTexture(Texture);
    Sprite.setPosition(300, 300);

    *Window.draw(Sprite);
}

int main()
{
    //Declaring and defining the window
    sf::VideoMode VMode (640, 480, 32);
    sf::RenderWindow Window (VMode, "Standard window application", sf::Style::Default);

    //Declaring the Event
    sf::Event Event;

    //The main loop
    while (Window.isOpen())
    {

        Test(&Window);

        while (Window.pollEvent(Event))
        {
            // Escape key : exit
            if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
                Window.close();
        }
        Window.display();
    }

return 0;
}
 

2
Window / Drawing/Displaying sprites from another function
« on: October 21, 2012, 06:55:26 pm »
Drawing/Displaying sprites from another function

I've been learning c++ and recently started learning how to use SFML (I'm a newbie).

I made this game (see attachment) with Code::Blocks and came over this question.

When i'm using the term "main function" i refer to the "mainLoop function" in the attachment.

Can i draw/display anything in my window from another function?
like, if i had a main function that rendered a window and contained the main loop of my game, Could i make an "Enemy" function that displayed/drew anything in my main functions window?

If my function was returning anything, i would just have a value, which is not what i am looking for. I want the function to display something on my window and therefore i set it as a "void" type of function. However, if the function contains AI that interacts with other functions (eg. the Player) in the game, i would need to connect all the variables for all the sprites on the screen together so that they can interact with each other.

Is there any easy solution for this?  ???

If not, i would love to have some suggestions on how to organize all of my sprites in the main function :) it gets kinda messy in my main function  :-\

[attachment deleted by admin]

Pages: [1]