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.


Topics - Dummie

Pages: [1]
1
Graphics / Save a sf::Sprite
« on: July 08, 2008, 06:30:20 pm »
Hey,

is there any way to save a sf::Sprite?

Code: [Select]

sf::Sprite spr(img);
sf::Rect<int> rect;
rect.Left = imgX1;
rect.Right = imgX2;
rect.Bottom = imgY2;
rect.Top = imgY1;
spr.SetSubRect(rect);
spr.Resize(32, 32);
// Save???


I need to save it to a png file to continue working with it.

Thanks in advance,
Dummie

2
Network / Receive loop
« on: July 01, 2008, 07:27:07 pm »
How will be a receive loop done in SFML?

This seems to be the wrong way:
Code: [Select]

char recvBuf[1024];
size_t received;
for (;;)
{
   sf::Socket::Status status = client.Receive(recvBuf, sizeof(recvBuf), received);
   if (status != sf::Socket::Done)
   {
      std::cerr << "Error: receive" << std::endl;
      return 1;
   }

   if (received == 0)
      break;

   recvBuf[received] = '\0';
   std::cout << "Server: " << recvBuf << std::endl;
}


How will it be done right in SFML?

Thanks,
Dummie

3
General / 2 Problems
« on: June 30, 2008, 10:47:28 am »
Hey,

I got two very annoying problems :(

I installed SFML 1.3 and all is working fine. I turned "Release-Mode" on and when the application start the program crashs. But if I use SFML 1.2 all works fine. But of course, I would prefer to use SFML 1.3.

I tried to link statically to the CRT(Multi-Threaded) so I don't have to provide the .NET-Framework and so on. Unfortunately it doesn't work. I get tons of linking errors. I used SFML 1.2 because SFML 1.3 doesn't work for me in release mode. Is SFML not compatible to it?

In all cases I used the static version of SFML.

Some solutions?

Thanks,
Dummie

4
Network / Client identification
« on: June 26, 2008, 04:22:37 pm »
Hey,

I'm using a selector and all works fine but I don't know how to identificate clients. For example I want to give them numbers. Is there a nice way to do this with help of SFML?

Code: [Select]

const unsigned int numSockets = selector.Wait();

for (unsigned int i = 0; i < numSockets; ++i)
{
sf::SocketTCP socket = selector.GetSocketReady(i);

if (socket == listener)
{
sf::IPAddress address;
sf::SocketTCP client;
listener.Accept(client, &address);
selector.Add(client);
}
else
{
char recvBuf[1024];
size_t received;
if (socket.Receive(recvBuf, sizeof(recvBuf) - 1, received) != sf::Socket::Done)
// ---------->  - 1 is needed, I think. But I didn't see it in tutorial.
{
selector.Remove(socket);
std::cerr << "Error: receive" << std::endl;
continue;
}
recvBuf[received] = '\0'; // ---------->  This is needed, I think. But I didn't see it in tutorial.

std::cout << "Client (" << i << ") : " << recvBuf << std::endl; // ----------> I hoped I could give numbers to them this way. But all clients got the number 0.

std::string sndBuf;
sndBuf = "Thanks for the message: ";
sndBuf.append(recvBuf);

if (socket.Send(sndBuf.c_str(), sndBuf.length()) != sf::Socket::Done)
{
selector.Remove(socket);
std::cerr << "Error: Send" << std::endl;
continue;
}
}
}


Any suggestions?

Thanks in advance,
Dummie

5
Graphics / New sprite dimesions after rotation?
« on: April 27, 2008, 08:11:41 pm »
Hi,

when I try to rotate a sprite the width and height vlues aren't changed. The functions GetHeight and GetWidth are returning the old values. Why? :)

In my opinion it would be very useful if this would be also done by SFML.
What do you think about it? :)

Thanks in advance,
Dummie

6
Graphics / Rotation and movement...
« on: March 21, 2008, 10:53:48 pm »
Hey,

Currently I'm checking out the possibillities to rotate a sprite. It works very great, but I got a question. Why the degree get with every turn +/-360?
I was wondering very much when I made a debug output with GetRotation() and saw a very big or very small value instead of something like 127...

In addition to that I'd like to build something like this:
http://www.tonypa.pri.ee/tbw/tut20.html

Could somebody provide me a code example that calculate the values I have to pass to SetLeft() and SetTop() to get the same result as on the page I posted above?

Thanks in advance :) :) :)


PS: If I rotate the sprite do I have to call this code again?
Code: [Select]

Sprite.SetRotationCenter(Sprite.GetHeight() / 2, Sprite.GetWidth() / 2);

Or is it done by SFML already?

7
Graphics / Explosions? How?
« on: March 19, 2008, 04:30:01 pm »
Hey,

How would be a nice explosion done in SFML?

I tried to display a explosion from a bitmap but the problem is the backgroundcolor. And isnt it very bad if I have to create for every underground a new explosion, just because of different backgrounds?

Colorkeying doesn't help at all, too.  I get very ugly corners and so on.

Is there a way to draw a explosion with some particles without bitmaps or has somebody else created a nice explosion that does display on every background fine?
Unfortunately I haven't experience with OpenGL so I would need to keep on be in 2D.

Thanks in advance :)

PS: This isn't a real problem with SFML graphics, so maybe wrong forum. But I thought its a good place to ask on the SFML webpage :) :D  :P

8
Graphics / ImageManager
« on: March 17, 2008, 01:22:22 pm »
Hey,

I'm currently trying to develop a ImageManager. Unfortunately I ran into a problem during developing it. My program crashs if I try to clean up the memory.

Code: [Select]

class ImageManager
{
    typedef std::map<std::string, sf::Image*> imagemap_t;
    imagemap_t images;

private:
    ImageManager() {}
    ImageManager(const ImageManager&);
~ImageManager() {
for (imagemap_t::iterator it = images.begin(); it != images.end(); it++) {
delete (*it).second; // !!!Crash!!!
}
}

public:
    sf::Image& getImage(std::string const & fileName)
    {
        const imagemap_t::iterator it(images.find(fileName));
        if (it != images.end()) return *it->second;
           
        imagemap_t::iterator insertIt (images.insert(std::make_pair(fileName, new sf::Image())).first);
        (*insertIt->second).LoadFromFile(fileName);
        return *insertIt->second;
    }

public:
    inline static ImageManager& instance()
    {
        static ImageManager instance;
        return instance;
    }
};


I don't know why :( Is there any solution? Has anybody here wrote succesfully a ImageManager already? Wheres the problem in my code?

Thanks in advance :)

9
Graphics / LoadFromFile() Problem:"[...] Reason : Unable to open f
« on: February 09, 2008, 03:48:20 pm »
Hey guys,

I got a problem with the function LoadFromFile() of sf::Image...

When I'm trying to load a image I got a error in the console window "Failed [...] Reason : Unable to open file"...

I already tried to use other images and so on but it doesn't make any changes.

I'm using Visual Studio 2005 and Windows XP/SP 2 :)

The code compiles well so I guess there isn't a problem. Any solutions?

Thanks in advance,
Patrick

PS: I used this code: http://sfml.sourceforge.net/tutorials/sources/graphics-sprite.cpp

Edit: It seems I solved the problem with using the Release mode of Visual C++. And I also solved the problem with using sfml-system-d.lib etc. for Debug Mode. I now get some warnings in Debug mode but it works. Maybe you should mention this problem. All in all: Keep up the good work! I like SFML very much  :D

Pages: [1]
anything