SFML community forums
Help => Graphics => Topic started 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
-
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.
-
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
-
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.
-
duh... how do i do this
-
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.