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:
#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