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

Author Topic: Level making how?  (Read 1491 times)

0 Members and 1 Guest are viewing this topic.

theonekamisama

  • Newbie
  • *
  • Posts: 8
    • View Profile
Level making how?
« on: April 21, 2017, 09:22:33 am »
i've been reading up , and if i'm not wrong a single image generated, is much better than generating each image tile by tile

That being said....
say
String a="\

_____________________"
;

//run the loop
{
if (if a[i][j]=="_")
w.draw(tile);
}

I've never actualy done this, or commented code on a forum.
But i've seen this work on others. And i wanna ask, is there a better way to do this? like less messy

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Level making how?
« Reply #1 on: April 21, 2017, 01:44:05 pm »
There are lots of different ways to save and parse a level. What you probably don't want to do is have x static if statements that determine what to draw, instead you might want to have an additional file that defines all the tile string characters and what image and texture rect zo use.
Additionally you want to build a vertex array and not directly call draw. This allows you to not having to parse the level every frame and drastically improves performance.

Not the best example, but here's how I did it for a game jam: https://github.com/eXpl0it3r/Synth-Guitar/blob/master/bin/res/level01.json
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/