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

Pages: [1]
1
SFML projects / SF Video Player
« on: September 08, 2010, 03:25:44 pm »
You should also post this to the wiki! http://www.sfml-dev.org/wiki/en/sources

2
General / Need help used separate void functions
« on: September 07, 2010, 07:53:14 am »
Code: [Select]

class Application
{
public:
   SpriteManager Spr_Mgr(); //Create Sprite Manager for Application
};


This is a function declaration. You are declaring a member function called Spr_Mgr that returns SpriteManager object. Get rid of the () to declare an object called Spr_Mgr of type SpriteManager.

You should also declare it private because you don't need to call it through an instantiated Application object, like in the main() function.

Code: [Select]

Application::Application()
{
   Spr_Mgr.LoadPictures(); //Load Pictures with Sprite Manager - ERROR, Spr_Mgr not recognized!!
}


This occurs due to the above mistake.

Code: [Select]

void Application::DrawStuff()
{
   Window.Draw(Image_1); //Display the Picture
}


You might want to read up on encapsulation and class access specifiers. You're trying to call the object Image_1 declared within the Application class. Your SpriteManager class would have to either have a member function that returns a reference or pointer to your Image_1 object or declare the Image_1 object as public and then call it like Spr_Mgr.Image_1.

Anyway, your SpriteManager class design won't work well in the long run because you will have a lot redundant code. There are readily available resource managers in the wiki you may want to take a look at: http://www.sfml-dev.org/wiki/en/sources.

/me waits for corrections from the experts.

3
General / Need help used separate void functions
« on: September 07, 2010, 02:28:33 am »
Use a class:

Code: [Select]
#include <SFML/Graphics.hpp>

class Application
{
private:
sf::RenderWindow Window;
sf::String Hello;

void DrawStuff();
public:
Application();
void Run();
};

Application::Application()
{
Window.Create(sf::VideoMode(326, 600), "Title");

Hello.SetText("Hello!");
Hello.SetColor(sf::Color(0, 128, 128));
Hello.SetPosition(100.f, 100.f);
Hello.SetSize(30.f);
}

void Application::DrawStuff()
{
Window.Draw(Hello);
}

void Application::Run()
{
while (Window.IsOpened())
    {
        sf::Event Event;
        while (Window.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed)
                Window.Close();
        }
 
DrawStuff();

        Window.Display();
    }
}

int main()
{
Application Game;
Game.Run();

return 0;
}


I didn't test it so it might have some bugs, but you get the idea.

4
General / Using the Collision-Detection
« on: August 28, 2010, 04:52:27 pm »
Yeah, you could put all the sprites into a vector or list and where you check for collisions you would iterate through the container and check for collision for each sprite.

5
General / Is a function way efficient for playing a new game, if lose?
« on: August 27, 2010, 10:19:06 pm »
You need to elaborate a little more. Do you mean that is it a good practice to put all your game code inside a function (like runGame()) that you can call whenever you want to start a new game?

6
General / Small Problem
« on: June 29, 2010, 06:50:04 am »
Try disabling image smoothing. This seems to have been a problem for a number of people.

7
Network / Strange client outputs...
« on: June 28, 2010, 09:01:25 pm »
It's the c_str() that's appending the null termination:

Quote
c_str(): Generates a null-terminated sequence of characters (c-string) with the same content as the string object and returns it as a pointer to an array of characters.

A terminating null character is automatically appended.

http://www.cplusplus.com/reference/string/string/c_str/


You can use data() to return const char* string without null termination:

Quote
data(): Returns a pointer to an array of characters with the same content as the string.

Notice that no terminating null character is appended

http://www.cplusplus.com/reference/string/string/data/


And length() will return size_t length of the string.

So replace

Code: [Select]
mainSocket.Send(buffer.c_str(),sizeof(char) * (buffer.size() + 1));

With

Code: [Select]
mainSocket.Send(buffer.data(), buffer.length());

Pages: [1]