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

Pages: [1]
1
Graphics / Running Heavy Graphics
« on: September 28, 2011, 07:01:34 pm »
Here's the code:
(the two tiles are 32x32 png images)
Code: [Select]
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML\System.hpp>
#include <SFML\Graphics.hpp>
#include <SFML\Window.hpp>

////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
    // Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 8), "A-Mazing Game");
float movespeed = (32.0f);

sf::Image T1;
if (!T1.LoadFromFile("grass (2).png"))
return EXIT_FAILURE;
T1.SetSmooth(false);

sf::Image T2;
if (!T2.LoadFromFile("water.png"))
return EXIT_FAILURE;
T2.SetSmooth(false);

   

    // Create the sprite
    //sf::Sprite Sprite(Image);
sf::Sprite Tile1(T1);
sf::Sprite Tile2(T2);

int map[25][19]= {0};

map[24][0]= 1;


    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

App.Clear();
int px = 0;
int py = 0;

for (float qq = 0; qq <= 800; qq +=32)
{
for (float ii = 0; ii <= 608; ii += 32)
{
if (map[px][py] == 0)
{
App.Draw(Tile1);
Tile1.SetPosition(qq,ii);
}

if (map[px][py] == 1)
{
App.Draw(Tile2);
Tile2.SetPosition(qq,ii);
}
py++;
}
px++;
py=0;
}



        // Clear screen
        // Display sprite in our window
        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}

Just a question, how would I go about using only one sprite per cell?

2
Graphics / Running Heavy Graphics
« on: September 28, 2011, 02:29:56 am »
Hi everyone, I've been messing around with SFML lately and have really come to like the language. However, I am running into roadblocks literally when it comes to drawing large png images or tiles. When I draw my titlescreen images or tilemap, the framerate drags down to 8 or so fps. For example:

Code: [Select]
px = 0;
py = 0;

for (float qq = 0; qq <= 800; qq +=32)
{
for (float ii = 0; ii <= 608; ii += 32)
{
if (map[px][py] == 0)
{
App.Draw(Tile1);
Tile1.SetPosition(qq,ii);
}

if (map[px][py] == 1)
{
App.Draw(Tile2);
Tile2.SetPosition(qq,ii);
}
py++;
}
px++;
py=0;
}


Is a simple script I wrote to display tiles in a 800x600 window (yes I could have gotten the resolution and changed the array size, but that's not the point). This script running constantly to draw 475 png tiles is really slow.

So my question is, is there a way to draw a sprite or an image only once, so that it does not eat up memory or processing time?
Thanks
-K55

Pages: [1]