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

Pages: [1] 2 3
1
Graphics / sf::Image subrect exceeds borders
« on: May 13, 2011, 11:53:10 am »
Just to confirm that this problem occurs in 1.6 too, and definitely has something to do with pixel-fractions:
http://www.sfml-dev.org/forum/viewtopic.php?p=31462#31462

The quickest fix seems to be to ensure that everything is cast/rounded to an integer value. Doesn't look quite as nice but you don't get any of the graphical glitches.

2
Ironically though using separate images will generally take up more space, both in memory and on the disk, than using atlases: it might be harder to cut things down, but you'll need to cut them down less. I also find it more convenient to edit a single file for each character/monster in the game.

If you ever need a hand with sprite-sheets, I've got it all working again (though the pixel-snap is less pleasing on the eyes than the interpolation) and would be happy to help  :wink:

edit: I should mention that I'm also using XML files to manage the sheets, rather than hard-coding everything. This certainly makes it a lot less fiddly than it was before  :?

3
The borderlines appear occasionally when the camera has a very specific offset  - specific down to the pixel. Well, actually it seems to be a questions of fractions of a pixel. I can't figure out the pattern of it though. I got lucky a few times and managed to sit in the sweet-spot to take a screenshot:

too big to embed in post (shrinking would make it harder to see the problem)

What's weird is:
A/ if part of the border is appearing then the sub rectangle used my the background tiles must be off by a pixel, BUT...
B/ it isn't (I've made sure - the offsets are always correct), which is not at all surprising since...
C/ the position of the camera in no way influences how the sub rectangles are calculated anyway :shock:


So why do bits of borderline appear?

Remember that I'm using an sf::FloatRect for views because I didn't realise SFML already had one? Well, I changed this line:
Code: [Select]
stamp.SetPosition(x*CELL_SIZE-view->Left,y*CELL_SIZE-view->Top);

To this:
Code: [Select]
stamp.SetPosition((int)(x*CELL_SIZE-view->Left),(int)(y*CELL_SIZE-view->Top));

In other words the Sprite used for printing all the background tiles is snapped to the nearest pixel. This causes the problem to stop. The only possible explanation is that, even when smoothing is turn off:

 :o Moving a Sprite to a position that is a fraction of a pixel may cause parts of the source image that are not in the defined sub rectangle to be drawn!

Phew - I figured it out  :D And while fairly dirty, casting to int before drawing isn't really a visible difference.

4
That worked  :shock: Haha! So it wasn't my fault  :D

Sorry I didn't reply before: I had trouble with my internet connection.

Wait a minute though... I'm still getting little border-lines very rarely: when I'm travelling along I'll see a flash of yellow border-pixels, every so often, but haven't been able to reproduce it effectively  :?
NB - I'm not actually using SFML's views because I was too lazy to read the manual, so wrote my own using sf::FloatRect.

5
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

6
Graphics / Zoom to mouse (as in Google maps)?
« on: April 16, 2011, 01:13:17 pm »
Ah! I completely misunderstood what the code did: so it basically makes the zoom all nice and smooth :D Certainly an effect I'd like to have now that I've seen, but not actually the one I was originally trying to implement  :?

Maybe I should have been more specific in the description. How to explain...

1. go to http://maps.google.com/.
2. place the cursor on a city.
3. zoom in.

Google Maps zooms directly towards or away from whatever your mouse is hovering over. However if I place the mouse on the square in your example, I have to keep move the mouse to zoom in on it accurately.

Still, I'm definitely going to use this smooth zoom of yours  :wink:

7
Graphics / Zoom to mouse (as in Google maps)?
« on: April 16, 2011, 12:39:29 pm »
Yeah - that was my original code. Here's a changed version, but clearly I'm not implementing this correctly:

Code: [Select]
float lerp(float value, float start, float end)
{
    return start + (end - start) * value;
}

bool Game :: treatEvents(RenderWindow& window)
{
    float targetzoom = 0;
    float currentzoom = 0;
    float previouszoom = 0;
    bool zooming = false;

    static Event event;
    while (window.GetEvent(event))
    {
        switch(event.Type)
        {
            //exit events

            case Event::MouseWheelMoved:
                zooming = true;
                targetzoom = 0.5;
                currentzoom = 0;
                break;

            case Event::MouseMoved:
                break;

            default:
                break;
        }
    }

    if (zooming)
    {
        currentzoom = lerp(0.01, currentzoom, targetzoom);
        window.GetDefaultView().Zoom(currentzoom - previouszoom);
        previouszoom = currentzoom;
        if (abs(targetzoom - currentzoom) < 0.1) // Lerp will never reach the target.
            zooming = false;
    }


    //no exit event detected: continue running
    return true;
}
:?

8
Graphics / Zoom to mouse (as in Google maps)?
« on: April 16, 2011, 11:53:32 am »
Okay, I'll give it a try (and edit in what happens). By the way, this is the code I was using - it didn't quite work :(

Code: [Select]
bool Game :: treatEvents(sf::RenderWindow& window)
{
    static sf::Event event;
    while (window.GetEvent(event))
    {
        switch(event.Type)
        {
            //exit events

            case sf::Event::MouseWheelMoved:
                window.GetDefaultView().Zoom(1+ZOOM_SPEED*event.MouseWheel.Delta);
                window.GetDefaultView().SetCenter(mouse_position);
                mouse_position = window.ConvertCoords(mouse_position.x,mouse_position.y, &window.GetDefaultView());
                break;

            case sf::Event::MouseMoved:
                mouse_position = window.ConvertCoords(event.MouseMove.X,event.MouseMove.Y,&window.GetDefaultView());
                break;

            default:
                break;
        }
    }
    //no exit event detected: continue running
    return true;
}

9
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

10
Graphics / Blending shadows correctly
« on: March 13, 2011, 10:34:12 am »
Okay then - good to know their way. Guess I'd better switch to 2.0 for my next project...

11
Graphics / Blending shadows correctly
« on: March 12, 2011, 03:12:34 pm »
You forget that I'm fluent in French (I just occasionally get my genres wrong)  :P

Thanks for the link - still, is there no way to build an image iteratively in 1.6? Something along the lines of (pseudo-code):

Code: [Select]

pixel_buffer temp_image(view.width,view.height,colour(255,255,255));
for each vertex in view
{
   Polygon shadow(colour(0,0,0));
   shadow.add(vertice.start); //A
   shadow.add(projection(vertice.start)); //B
   shadow.add(projection(vertice.end)); //C
   shadow.add(vertice.end); //D

   temp_image.draw(shadow);
}

temp_image.set_alpha(200);
window.draw(temp_image);

I've been following this guide on tigsource:


12
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

13
General / "gdb.exe has stopped responding" codeblocks
« on: December 12, 2010, 03:56:14 pm »
bump  :?

Exactly the same problem, both on XP virtual-machine and dual-booted Windows 7. I'm trying to port my game and can't debug the various problems that have come up, because the debugger won't run  :(

14
SFML projects / "Bugger!" -- a game about debugging
« on: December 12, 2010, 03:19:09 pm »
Quote from: "Nexus"
Looks funny :D

I think, you could make it even funnier if there were more game elements such as different bugs, power-ups, more weapons, maybe different game modes, ... Just be creative ;)

We still a long way to go  :wink: I'm planning on including 9 enemies (named after common bugs) and 6 weapons (named after debugging techniques). Other double-entente stuff will be there as well (like teleports called "jump-to statements", etc).

Actually: while you're here, I was just trying to compile the game for Windows. It works... fairly well, but one big problem is that there is no sound   :(

I've included the following DLLs in the working directory:
  • libgcc_s_dw2-1.dll
  • libsndfile-1.dll
  • OpenAL32.dll
  • sfml-audio.dll
  • sfml-graphics.dll
  • sfml-system.dll
  • sfml-window.dll
And there are no errors. It also seems to be drawing 129x129 sections of an Image when I ask it to draw 128x128 sprite. Windows :roll:

On Monday I'll upload the file (if I can't fix it): my internet is far too slow at home (wifi citéU - go figure).

If you use Linux you'll be able to give the bug-free (except for the enemies of course) version a spin  :D

15
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

Pages: [1] 2 3
anything