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

Author Topic: How Can i Draw a Map??  (Read 3474 times)

0 Members and 1 Guest are viewing this topic.

nevets_19

  • Newbie
  • *
  • Posts: 43
    • View Profile
How Can i Draw a Map??
« on: March 17, 2011, 06:22:54 am »
Hello i have been trying to make a zelda like game in sfml and i want to know if there is an easier way to make multiple objects and still be able to use them for collisions, e.g. make a image named tree and a sprite named tree and draw a long line of trees instead of making like 10 sprites called tree1, tree2, tree3, etc.

thanks

also does anone know a good easy way to make maps in sfml

thanks for your help

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
How Can i Draw a Map??
« Reply #1 on: March 17, 2011, 09:27:47 am »
Creating/rendering 10 sprites is just fine. Sprites don't take much memory, so you better create 10 of them instead moving one sprite around, which ist just more complicated to do.

Since SFML ist not a game development framework, it can't "make" maps. ;) How easy it is depends on your knowledge, but something like a 2D map should be possible even for a beginner.

Basically you have an array of mapdata, a bunch of images and a fixed amount of sprites that display the proper images regarding to the current mapdata.

nevets_19

  • Newbie
  • *
  • Posts: 43
    • View Profile
How Can i Draw a Map??
« Reply #2 on: March 17, 2011, 09:59:01 am »
ok thank you, i was wondering if you could do it like in game maker, you make one tree object and you can use it everywhere rather than making many

devlin

  • Full Member
  • ***
  • Posts: 128
    • View Profile
How Can i Draw a Map??
« Reply #3 on: March 17, 2011, 02:40:07 pm »
Yes, you could use the same subrect from the same image on either multiple sprites - or having a lookup-table and draw the same sprite several times at different positions.

nevets_19

  • Newbie
  • *
  • Posts: 43
    • View Profile
How Can i Draw a Map??
« Reply #4 on: March 18, 2011, 12:05:16 pm »
duh... how do i do this

Gibgezr

  • Newbie
  • *
  • Posts: 33
    • View Profile
How Can i Draw a Map??
« Reply #5 on: March 18, 2011, 03:07:01 pm »
Make a 2d map array that stores tile_numbers. Set the subrect of the tile_sheet sprite by doing math on the tile_number stored in the array for that map cell location, like:

Left = (map
  • [y].tile_num % tiles_across_tilesheet)*tile_width;

Top = (map
  • [y].tile_num / tiles_across_tilesheet)*tile_height;

Width = tile_width;
Height = tile_height;

Draw the sprite at the x,y coordinates for that tile. Do all of the above in some code that does a double for loop, drawing all the tiles on the screen.

 

anything