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

Pages: [1]
1
Please help!  :cry:

For those who don't know, I've been working on a debugging-themed top-down shooter called Bugger! for the last 9 months: the above video shows the animations working on Ubuntu 10.04 64bit. They've been working since very early on in fact.
However on Windows systems and now on Ubuntu 10.10 32bit, using exactly the same animation code , the offsets are incorrect! For example for this sheet:



We end up with bits of the green separating pixels appearing in frame:


(ignore the tearing - that's just Ubuntu's screen-capture playing up)




:cry: It's driving me insane!

Minimal code:

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

using namespace std;
using namespace sf;

void moveRect(IntRect& rect, int x, int y)
{
    rect.Offset(-rect.Left,-rect.Top);
    rect.Offset(x,y);
}

int main()
{
    //Create the main window
    RenderWindow window(VideoMode(640, 480, 32),"Animation Test");
    window.UseVerticalSync(true);
    window.SetFramerateLimit(5);

    //Load a sprite to display
    Image image;
    if (!image.LoadFromFile("sheet.png"))
        return EXIT_FAILURE;

    IntRect frame(0,0,64,64);
    Sprite sprite(image);
    sprite.SetPosition(300,300);

    //Start the game loop
    int i = 0;
    while (window.IsOpened())
    {
        i = (i+1)%5; //increment frame number and loop around
        moveRect(frame,i*(frame.GetWidth()+1),0); //move rectangle
        sprite.SetSubRect(frame); //bind rectangle to sprite-sheet to cut out correct frame

        //Process events
        Event event;
        while (window.GetEvent(event))
        {
            // Close window : exit
            if (event.Type == Event::Closed)
                window.Close();

        }

        // Clear screen
        window.Clear(Color(255,255,0));

        // Draw the sprite
        window.Draw(sprite);

        // Update the window
        window.Display();
    }

    return EXIT_SUCCESS;
}


File used for minimal example:


Whether the animation works or not may depend heavily on your system. Let me know what you see and what OS you're using so we can pinpoint exactly what the problem is.

Thanks,

William

2
Graphics / Zoom to mouse (as in Google maps)?
« on: April 12, 2011, 06:35:05 pm »
Hi all,

I'm trying to implement a zoom towards the mouse similar to the system used for Google Maps or Supreme Commander. I can't seem to get it to work though: has anyone done anything similar recently?

Thanks,


William

3
Graphics / Blending shadows correctly
« on: March 12, 2011, 01:29:36 pm »
I'm having a bit of trouble correctly blending shadows - I don't want the area to be darkers when there are multiple shadows lying on top of eachother:


Is there a way to iteratively build a sort of layer and then composite it on top of the render target? At the moment I'm exporting a list of vertices from the pathing matrix and projecting each point of each one to create a 4 point polygon.

William

4
SFML projects / "Bugger!" -- a game about debugging
« on: December 07, 2010, 04:38:19 pm »
Hi guys!

I keep forgetting to post this: I've been working for some time on a game called "Bugger!", written in C++ using SFML 1.6. Still a lot of work to do, but I think it has reached that "critical mass" moment when things start getting a little easier:



Basically you play as a lone programmer, shooting up various "bugs" with debugging equipment. Not at all inspired by life experience  :roll:

Rather than repeating myself, for more information, clips, screenshots and so on, here are some links. Right now there isn't a demo available, but I'm hoping to release an early playable build sometime at the beginning of next year. Till then:
[/b]
Very happy with the library so far: compared to SDL it's a dream come true, and since this is a 2D game there's no need for the added functionality (and complexity) or "pure" OpenGL. I'm using it for everything media-oriented: I also wrote my own custom draw-order-manager which I'd be happy to explain.
Anyway yeah, I owe Laurent a lot  :wink:

Tell me what you think of this idea (but bear in mind that the art is placeholder)!

William  :D

5
Audio / incorrect documentation of Sound::SetRelativeToListener!
« on: November 06, 2010, 11:54:51 pm »
Hi there,

Been beating my head against this for some time and thought I'd share the solution now that I've found it.

The documentation says that the argument 'Relative' in "SetRelativeToListener(bool Relative)" should be "True to set the position relative, false to set it absolute". 'False' is the default value.

In fact it's the opposite. In other words, sounds are played with spatialisation by default, and it is turned off and not on by with "SetRelativeToListener(true)". I figured this out thanks to the example at the bottom of this page: Laurent never turns on spatialisation!

Bit counter-intuitive though - and the documentation definately needs to be changed or people are doing to be as confused as I has, and lose many hours (not to mention hair) trying to figure out the problem!

William

6
Feature requests / sf::Rect<T>.MoveAbsolute
« on: October 14, 2010, 10:53:54 pm »
Hi everyone,

Loving the library, but a few functions I'd like to see. It would also be good to be able to move an sf::IntRect to a position without doing two Offsets in a row:

Code: [Select]
void sf::IntRect MoveAbsolute(int x, int y)
{
   Offset(rect.Left,rectTop);
   Offset(newX,newY);
}


Yes, I have obsessive compulsive disorder. I also don't know how to use Templates:

Code: [Select]
void moveRect(sf::FloatRect& rect, float x, float y)
{
    rect.Right += x - rect.Left;
    rect.Bottom += y - rect.Top;
    rect.Left = x;
    rect.Top = y;
}

void centreRect(sf::FloatRect& rect, float x, float y)
{
    moveRect(rect,x-rect.GetWidth()/2,y-rect.GetHeight()/2);
}


The second function is one that I use constantly, but it's probably a bit to specific for a library that's supposed to be very simple. Also the main reason I use it is because I didn't realise that SFML supported views, so I wrote my own :?

That's all I can think of for now, but unless I write this stuff down I'll forget about it and/or kludge my way around it.

Tanks,

William

7
Audio / Cleaning up sf::Sounds and "Inconsistency detected by l
« on: September 29, 2010, 12:45:34 pm »
I have a resource manager (World) that loads and hashes sf::SoundBuffer objects into an std::map, and an object factory (Level) that creates an stores Instance objects in an std::vector. All the objects in the game can access the object factory and the resource manager, so can create sf::Sound objects from the buffers that the latter stores.
To test playing sounds I used a dirty kludge:

Code: [Select]
///Fire projectiles
static ushort reloading = 0;

if(reloading)
reloading--;
else if(input.IsMouseButtonDown(sf::Mouse::Left))
{
other = level->add_instance(INST_PROJECTILE,x,y);

towardsMouse = getDirection(x,y,input.GetMouseX()+level->view.Left,input.GetMouseY()+level->view.Top);
other -> setMotion(10,towardsMouse);

reloading = 15;

static sf::Sound* sound;
sound = new sf::Sound(*level->world->getSoundBuffer(SOUND_GUN));
sound->Play();
}


This works fine, for the first 256 shots fired. Then it stops playing - clearly I have created too many Sound objects without cleaning up:

Code: [Select]
AL lib : ALc.c:1879: exit(): closing 1 Device
AL lib : ALc.c:1808: alcCloseDevice(): destroying 1 Context(s)
AL lib : ALc.c:1420: alcCloseContext(): destroying 256 Source(s)
Inconsistency detected by ld.so: dl-close.c: 731: _dl_close: Assertion 'map->l_init_called' failed!


I'd sort of hoped that any Sound that doesn't loop would be deleted automatically when it finishes playing. I'm not really sure how sf::Sound objects actually work at a slow level: maybe after starting to play the sound I can delete the handle? Like mutex attributes in pthread.

Code: [Select]
static sf::Sound* sound;
sound = new sf::Sound(*level->world->getSoundBuffer(SOUND_GUN));
sound->Play();
delete sound;


Nope - deathly silence. Clearly I can't just create a new sound whenever I need one, unless I store them in a container and make sure I delete them when they finish playing. I could try using the same sf::Sound for all the shots fired:

Code: [Select]
static sf::Sound* sound = new sf::Sound(*level->world->getSoundBuffer(SOUND_GUN));
sound->Play();


But obviously this isn't the best solution, even for the unique Player object doing the firing: depending on the reload speed I may need to be playing the sound twice at the same time, or it sounds really bad!

I've got a few other ideas, like giving the Projectile object an sf::Sound attribute that it plays upon creation and destroys upon destruction, but I'm wondering if anyone knows of a "propre" way of doing this?

Perhaps more importantly, I get that error whether or not I'm creating too many sf::Sounds or not!

Code: [Select]
Inconsistency detected by ld.so: dl-close.c: 731: _dl_close: Assertion 'map->l_init_called' failed!

If you have any idea why, please let me know!

William

8
Graphics / Drawable.SetColor() not working!!
« on: September 14, 2010, 02:10:13 pm »
Hi there,

I have great faith in SFML, but I think I may actually have found a bug  :shock:
I'm creating a black rectangle and trying to turn it white retroactively. I stubbornly remains black. SetColor() doesn't seem to be working!

Here the minimal code:

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

int main()
{
    //Create the main Window
    sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Michael Jackson!");

    //Create a black rectangle
    sf::Shape mj;
    mj = sf::Shape::Rectangle(0,0,128,128,sf::Color(0,0,0));

    //attempt to change the rectangle's colour to white
    mj.SetColor(sf::Color(255,255,255));

    //Create Event handler
    sf::Event event;

    //Start main loop
    bool running = true;
    while (running)
    {
        //Read each Event, store in 'event' and treat
        while (window.GetEvent(event))
            if(event.Type == sf::Event::Closed || event.Type == sf::Event::KeyPressed)
                    running = false;

        //Clear the Windows
        window.Clear(sf::Color(200, 0, 0));

        //Draw the rectangle
        window.Draw(mj);

        //Redraw the Window
        window.Display();
    }

    //Destroy the Window
    window.Close();

    return EXIT_SUCCESS;
}


In actual fact I'm doing stuff a lot trickier than this, but the problem is still visible in this dumbed-down version: the rectangle is created black, and refuses to change colour!

Is this is bug or is it my code? I just don't see what I could be doing wrong when there's so little of it...


William

9
Network / Sending "types" of packet via UDP
« on: September 09, 2010, 02:07:38 pm »
This is probably a very stupid question, but bear with me.

I'm trying to build my first ever network game. For this I need to be able to send many different kinds of "message" between the computers. For instance:
- connection request
- you have x time left before you lag-out
- object y is at position z
- object t has been created at position u
- etc

So I don't know what my packet will contain until I open it, but until I open it I don't know what it will contain  :(
My idea was to give each packet a sort of "header" which lets the receiver know how to open it. The header would always be, say, a short unsigned integer.

I know this is possible if I'm just sending bytes but it would be rather fiddly. Is there a way of implementing this kind of stuff with SFML packets?

Thanks,


William

Pages: [1]