Having trouble with tilesheets

Game development specific discussions.
Post Reply
f0rgotten
Posts: 7
Joined: Dec 12, 2018 23:55

Having trouble with tilesheets

Post by f0rgotten »

So I'm working on something like a combination of the NES game "Conflict," SimCity and an RTS, with procedurally generated details.

I've some general code in place over a few different files to generate random maps, simulate (roughly) population dynamics and the like. I'm at the point where I would like to phase out the variously colored "8"s in my maps that denote different terrain types for some generic tilesheet graphics, but since pretty much everything that I have done so far has been text based I am having some trouble conceiving how to make the transition from printing out the contents of my 'city' array to mapping those contents to a picture.

Is it easier/better to have discrete graphics loaded and placed in the location desired or is there a way to use an existing spritesheet to capture the tile in question? I have figured out how to place pictures on the screen but not how to make a picture from one segment of another picture, which is what I would rather do as then I could more easily simulate general building/societal evolution. Algorithms are much more my strong point over graphics, lol!
Tourist Trap
Posts: 2958
Joined: Jun 02, 2015 16:24

Re: Having trouble with tilesheets

Post by Tourist Trap »

Hello,

I can't personally help you much myself, but I would recommend you to read the posts from BasicCoder2, it's full of tiled game that you may find of interest for your project as I understand it.
Example:
viewtopic.php?f=15&t=26759&p=248100&hilit=tile#p248100
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Having trouble with tilesheets

Post by badidea »

Not sure I understand the question, but I you give each image an ID and fill you world map array with these ID, you have the basics. Alternatively, the map uses pointers to images, but this probably leads to a larger memory size of the array.
Some example I made:
* https://freebasic.net/forum/viewtopic.php?f=15&t=24464
* viewtopic.php?f=7&t=21153#p187554
Second example uses 2 layers.

For file loading performance, 1 file containing multiple sprites is better.
In any case, each image needs to be loaded only once from file.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Having trouble with tilesheets

Post by grindstone »

If your problem is how to get an image section from an existing image, this can be done quite easy:

Code: Select all

ScreenRes 640,480,32
Dim As Any Ptr sourcepic = ImageCreate(200, 200) 'buffer for source picture
Dim As Any Ptr grabpic = ImageCreate(100, 100) 'buffer for image section

'replace "marmot.bmp" with an existing .bmp picture with a size of at least 200 x 200 pixels
BLoad ("marmot.bmp", sourcepic) 'load picture
Put (0, 0), sourcepic 'print source picture to screen
Get sourcepic,(20, 20) - (120, 120), grabpic 'grab image section
Put (300, 50), grabpic 'print image section to screen

Sleep

ImageDestroy(sourcepic)
ImageDestroy(grabpic)
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Having trouble with tilesheets

Post by leopardpm »

Forgotten,
Show some of your code - your map display routine in particular... it is very easy to change from whatever you currently have to a tile-based graphical map.

Just think of your current ascii display as each character being a graphic.... which is what they really are anyways.
Post Reply