SFML community forums
General => SFML projects => Topic started by: Neomex on January 02, 2012, 03:27:45 pm
-
Here's my result of few days of learning sfml :)
http://www.youtube.com/watch?v=CpXinpvImgM
My 'framework' took me 3 days to look like a framework :D
and game itself one day.
I've started with rendering grid and cells using primitives, but it was definitely bad idea, now grid and cells are just sprites, whereas I noticed, that filling image with color in-code, gives ~20fps performance for me.
Without any cells shown it runs with 900fps, with 100 cels about 260 fps.
I'm quite sad with sfml (1.6) rendering speed, maybe just my code is wrong, but for now showing for example many tiles is just impossible.
I'll probably extend this 'game' as a part of learning openGL :)
LMB - set cell talive
RMB - set cell dead
G - toggle grid
P - pause/unpause simulation
+/- change speed of simulation
-
Some tiles are definitely no problem for SFML, even if performances have been further improved in SFML 2.
Do you manipulate sf::Image objects every frame?
-
No, I simply apply single image for single sprite at initialisation point:
imgBlueLifeForm.Create( 16, 16, sf::Color::Blue );
BlueLifeForm.SetImage( imgBlueLifeForm );
and draw it this way:
for( int i = 0 ; i < 64 ; i ++ )
{
for( int j = 0 ; j < 48 ; j ++ )
{
if( isAlive[i][j] == true )
{
BlueLifeForm.SetPosition( i * GridSpacing, j * GridSpacing );
AppWindow.Draw( BlueLifeForm );
}
}
}
-
Okay, that shouldn't be too slow. Did you already try SFML 2?
And if your images consist of a single color, you might also consider to use sf::Shape instead of sf::Sprite.
-
Haven't yet, waiting for it to be released, I'll play some more time with 1.6 and eventually move then :)
Also yes, tried with shapes, but it was 2x slower.
Does it create new object with every call?
AppWindow.Draw( sf::Shape::Rectangle( i * GridSpacing, j * GridSpacing, i * GridSpacing + GridSpacing, j * GridSpacing+ GridSpacing, sf::Color( 0, 0, 255 ), 0, sf::Color::Black ) );
To be honest didn't though about it before.