Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Looking for suggestion dealing with 2 layer map and keeping good speed  (Read 1760 times)

0 Members and 1 Guest are viewing this topic.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Hello.
Currently i am making 2d top down game.
I made a map using sf::VertexArray, each tile in layer 1 is a tile and it cant be blank so sf::VertexArray is perfect.
Now on layer2 its gonna be used to draw (Trees, bush, Rock)
And then i need enemies/npc movable units as Sprites, my reason posting is that i want to get speed = to VertexArray but also save space if possible, what is optimal solution?

Map syntax
sizeOfMapX sizeOfMapY
Layer1:Layer2

At layer 1: 0-Infinite = tile texture ID;
at layer 2: 0 = nothing, 1-infinite = something

example:
{5 5
1:0 1:0 1:1 1:0 1:1
1:0 1:1 1:0 1:1 1:1
1:1 1:1 1:1 1:0 1:1
1:0 1:0 1:1 1:1 1:0
1:0 1:1 1:0 1:1 1:1 }
So the layer 2 can have full screen of layer 2 or absolutely nothing.

To recap:
Layer 1 = sf::VertexArray because the map cant have empty spots so its perfect.
Layer 2 = Making sf::Sprite for each tile?(I am affraid this is gonna take allot off performace when in rocky place where the whole screen is gonna have layer 2 and drawing (32width x24height, 32width x32height tiles proves to drain much when using sf::Sprites)
Layer 3 = sf::Sprite for sure because it needs to be pixel perfect

Current layer 1 image^^
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
What's the problem with vertex arrays with holes? Just create quads where you have tiles.
Laurent Gomila - SFML developer

netrick

  • Full Member
  • ***
  • Posts: 174
    • View Profile
In vertex array you can have empty places! You can even have a several quads at the same position. I suggest you to use one vertex array per tileset (no matter if the tileset is used by just one or 5 layers). I use this approach for drawing map with several layers and also objects as well and I get hundreds of FPS. (I make a new vertex array every frame from visible tiles, it's faster for bigger maps but slower for very small ones).

Vertex array can be pixel perfect as well. Also, if you create a vertex array only from visible tiles then memory isn't a problem (my whole app uses 40mb when rendering 1000 x 1000 tiles multi-layer map and it's amazing performance).

To sum up:
Vertex array is the key for your problem, just learn how it exactly works and how to manage it in your code.
« Last Edit: July 26, 2013, 02:55:38 pm by netrick »

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
I just read your first line and am typing this replay while thinking to my self.
(Having bad day, not thinking str8, apologize and admit you are an idiot);
Well i am very sorry.
Somehow i missed the fact that each vertex has a position and texture position.
And in the plane/plain i don't have to position each 4 vertices near each other.

What i am trying to say i can make a layer 2 just by adding elements at the end of the Vertex array.
Because my map is loaded in sizes of 11x11 tiles witch are 32x32pixels width and height.
Therefore i can just make sf::VertexArray for each partition of map and always draw it whole having a great performance...


BTW::This thread is totally pointless and serves no purpose, id ask you to delete or not if you hate wasting the time.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0