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

Author Topic: Game question  (Read 1813 times)

0 Members and 1 Guest are viewing this topic.

phear-

  • Jr. Member
  • **
  • Posts: 64
    • MSN Messenger - LOApokalypse@hotmail.com
    • View Profile
    • http://gtproductions.org
Game question
« on: September 06, 2009, 04:53:51 pm »
How do people handle backgrounds in games? I'm making an RTS and I need to work on getting the map into the game. Is it possible to make a sprite like 3000x3000 and have the image (thats 300x300) be repeated like tiles inside of it? Right now im doing everything manually and I can't figure out how else i'm going to do it...

Code: [Select]

/////////////////////////////////////////////////
/// Place sprite positions (background)
Background[0].SetPosition(0.f, 0.f);
Background[1].SetPosition(300.f, 0.f);
Background[2].SetPosition(600.f, 0.f);
Background[3].SetPosition(900.f, 0.f);
Background[4].SetPosition(0.f, 300.f);
Background[5].SetPosition(0.f, 600.f);
Background[6].SetPosition(0.f, 900.f);
Background[7].SetPosition(300.f, 300.f);
Background[8].SetPosition(600.f, 600.f);
Background[9].SetPosition(900.f, 900.f);
Background[10].SetPosition(600.f, 300.f);
Background[11].SetPosition(900.f, 300.f);
Background[12].SetPosition(900.f, 600.f);
Background[13].SetPosition(300.f, 600.f);
Background[14].SetPosition(300.f, 900.f);
Background[15].SetPosition(600.f, 900.f);
/////////////////////////////////////////////////


Any helps/tips/suggestions would be great :)
Eugene Alfonso
GTP | Twitter

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Game question
« Reply #1 on: September 06, 2009, 05:02:22 pm »
Use loops ;)

Code: [Select]
for (int x = 0; x < 10; ++x)
    for (int y = 0; y < 10; ++y)
        Background[x + y * 10].SetPosition(x * 300.f, y * 300.f);


Then you can replace 10 and 300 with variables calculated from a config file or from the map dimensions.
Laurent Gomila - SFML developer

phear-

  • Jr. Member
  • **
  • Posts: 64
    • MSN Messenger - LOApokalypse@hotmail.com
    • View Profile
    • http://gtproductions.org
Game question
« Reply #2 on: September 06, 2009, 07:20:52 pm »
Ah yeah I thought about that :P It's a good idea and gets the job done but I was just wondering if there were any other ways people might use to draw background sprites. Thank you Laurent :)
Eugene Alfonso
GTP | Twitter