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 - Elias Daler

Pages: 1 ... 38 39 [40]
586
Graphics / Re: Sprite Efficiency
« on: February 06, 2013, 11:38:19 am »
Laurent, it's because of scrolling. Level is much bigger that what's on screen

587
Graphics / Re: Sprite Efficiency
« on: February 06, 2013, 11:08:22 am »
Thanks again, I'll try to come up with something later. :)

588
Graphics / Re: Sprite Efficiency
« on: February 06, 2013, 10:59:55 am »
FRex, I've seen those before, I was just wondering if what tutorials from this list you were reffering to
It's 16x16 on 240x320 than scaled to 2x. I'm making NES-like game, so it's okay for now ;)

krzat, there's no trouble with your code, I was just interested in exploring more methods so I can come up with mine.

589
Graphics / Re: Sprite Efficiency
« on: February 06, 2013, 10:28:46 am »
FRex, I can't find those examples. Can you post links, please?
Well, my method rebuilds only part of array too. For example if I want to draw sprites idX:[2-4], idY[6-7], for example, I set:
 
left = 2; right = 5; top = 6; down = 8;
And only 24 members of VertexArray are rebuilt. Actually this is what I use(viewRect is what is seen on the screen at the moment)
int left = 0;
        if(viewRect.left > 0) left = viewRect.left / tileWidth;
        int top = 0;
        if(viewRect.top > 0) top = viewRect.top / tileHeight;

        int right = (viewRect.left + viewRect.width) / tileWidth + 1;
        int down = (viewRect.top + viewRect.height) / tileHeight + 1; // '+1', because some tiles are chopped off
        if(right > width) right = levelWidth;
        if(down > height) down = levelHeight;

Laurent, this sounds interesting. But I can't understand how can I do that. I only draw 20 * 15 tiles, so how will quad-tree look like?

590
Graphics / Re: Sprite Efficiency
« on: February 06, 2013, 09:54:41 am »
It's pretty useless now, yeah. But it will be very useful in future when I'll implement collision system, so I can assign different properties to each tile. And I need to rebuilt VertexArray each time I draw my level(well, because I don't need to draw each tile, I just need to draw tiles which are on the screen at the moment).

Or maybe there's no need to do that?

591
Graphics / Re: Sprite Efficiency
« on: February 06, 2013, 09:19:55 am »
Thanks, everyone! I've got it working now. So my game used ~19132 kb or RAM, and now it uses ~18672kb. Considering a level is not very big it's pretty good result. However I'm wondering if I'm doing it right.
So, my Tile struct looks like this now:
struct Tile {
        //collision information, animation information will be there soon
        int tx, ty; // position of tile in a tileset texture
};

Tileset is defined like this:
std::map<char, Tile*> tilesetMap;

And map is just:
std::vector<char> map

So for example my level is

SSSSS
SSSSS
SSSSS
GGGGG

And it's very easy to get corresponding tile from a tileset:
Tile currentTile = &tilesetMap[map[x + y * width]];

So, back to rendering. Here's how I set up VertexArray:

//these are not changing so it's outside drawing function
sf::RenderStates states;
states.texture = &tileset.getTilesetTexture();
sf::VertexArray map(sf::Quads, 4 * levelWidth * levelHeight);
int w, h;
w = h = 16;

...

//left, right, top, down - these are the number of tiles currently seen on screen
        for (int i = left; i < right; ++i)
    for (int j = top; j < down; ++j)
    {
        id = i + j * levelWidth;
                float tx = tileset.getTile(tiles[id])->tx;
        float ty = tileset.getTile(tiles[id])->ty;

        map[(id) * 4 + 0] = sf::Vertex(sf::Vector2f(i * w, j * h), sf::Vector2f(tx, ty));
        map[(id) * 4 + 1] = sf::Vertex(sf::Vector2f((i + 1) * w, j * h), sf::Vector2f(tx + w, ty));
        map[(id) * 4 + 2] = sf::Vertex(sf::Vector2f((i + 1) * w, (j + 1) * h), sf::Vector2f(tx + w, ty + h));
        map[(id) * 4 + 3] = sf::Vertex(sf::Vector2f(i * w, (j + 1) * h), sf::Vector2f(tx, ty + h));
        }

//So let's draw it.
        mainWindow->draw(map, states);

 

Am I drawing my map efficiently now?

592
Graphics / Re: Sprite Efficiency
« on: February 05, 2013, 08:10:08 pm »
Well, I looked through API over and over again and didn't find answer to my question, sorry.

The problem is with this line:

window.draw(sprite, &tileset);

It references pointer to tileset texture somehow, but I cannot find a way to assign a texture to a sf::VertexArray, because these examples are incomplete. I managed to draw one sprite, but I don't really get how to draw the whole map using sf::VertexArray

593
Graphics / Re: Sprite Efficiency
« on: February 05, 2013, 06:46:56 pm »
Nexus, I fixed everything I could in this code, however I don't really know how to fix "window.draw" error

594
Graphics / Re: Sprite Efficiency
« on: February 05, 2013, 06:13:55 pm »
There're some problems with your code, Laurent. First of all, there're some problems with your loop and second, sf::VertexArray has its arguments switched, and third, window.draw doesn't work this way, so this code doesn't work for me. :(

595
Graphics / Re: Sprite Efficiency
« on: February 05, 2013, 02:16:45 pm »
krzat, thanks, I don't think I will use the entire code, but some parts will be very helpful

Laurent, so do I have to keep one texture in a tileset instance(for example) and keep pointers to this texture in the tiles? If so, how do I use a part of a texture?(I'm new to SFML haven't figured this yet)

About sprite position... yeah, it was pretty stupid I guess. :) EDIT: I have to do this, because I have only n instances of Tile, where n - number of tiles in the tileset, because creating different instance for each tile in map will be overkill, so I have similar tiles in a tileset, I just draw them in a different places, therefore I have to assign sprite position for a tempSprite
 I don't have to make N calls, because I draw just those tiles which are seen on the screen at the moment.

Quote
you could just gather all these static sprites (they never change, right?) into a single entity composed of many quads
Is there any examples? I've never done such things before, so example would be very helpful and I believe it will really boost the perfomance.

596
Graphics / Re: Sprite Efficiency
« on: February 05, 2013, 01:03:39 pm »
Some things are not pretty clear though...
Right now I use this method. I have a tileset map, with char keys(chars are needed to read information from level file)

std::map<char, Tile*> tilesetMap;
Where Tile is just a simple struct(which will then contain collision information, animation etc.) with a texture created in a Tileset class(using the tileset sf::Image) and a sprite which uses this texture

struct Tile {
        sf::Texture texture;
        sf::Sprite sprite;
};
 

The level is stored like this:
std::vector<Tile*> map;

So when I draw a tile I just do:
int id  = x + y * width;
sf::Sprite tempSprite = map[id]->sprite;
tempSprite.setPosition(x * TILE_SIZE, y * TILE_SIZE);
mainWindow->draw(tempSprite);

What changes do I have to make to use vertex arrays?

(my method works pretty good, though
18068 kb in RAM for 4x4 map and 18088 kb for 276*15 map)

597
Graphics / Re: Sprite Efficiency
« on: February 05, 2013, 11:46:29 am »
Thanks again, I'll try to do it that way. :)

598
Graphics / Re: Sprite Efficiency
« on: February 05, 2013, 11:27:27 am »
Thanks, Laurent!

And another question: what are the main differences between using sf::Sprite and sf::VertexArray for tiles?

599
Graphics / Re: Sprite Efficiency
« on: February 05, 2013, 08:52:19 am »
I have a similar question. What if I have hundreds of objects(in tile engine, for example)? Stroring every sprite in Tile class will need more memory, but on the other hand creating them on the fly may create some perfomance issues. What is the best way to do it?

Pages: 1 ... 38 39 [40]