SFML community forums

Help => Graphics => Topic started by: nevets_19 on March 17, 2011, 06:22:54 am

Title: How Can i Draw a Map??
Post by: nevets_19 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
Title: How Can i Draw a Map??
Post by: Tank 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.
Title: How Can i Draw a Map??
Post by: nevets_19 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
Title: How Can i Draw a Map??
Post by: devlin 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.
Title: How Can i Draw a Map??
Post by: nevets_19 on March 18, 2011, 12:05:16 pm
duh... how do i do this
Title: How Can i Draw a Map??
Post by: Gibgezr 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
Top = (map
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.