Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Tile Map: read from file

Author
Message
Psycho Joker
20
Years of Service
User Offline
Joined: 13th Jul 2005
Location:
Posted: 19th Jun 2006 19:18 Edited at: 19th Jun 2006 22:12
I'm making a Metal Slug remake and need to know how to read a tile map from a ".txt" file. Can you read a document with comma's to differentiate the numbers? I can read the first string but not the whole file. This is the code I have to read from a ".txt" file. It reads the first string in the y direction.


After it reads the ".txt" file, the code then pastes the sprite onto the screen. Whenever I try to read the x value string it says image number illegal.

This is the tile map that I saved to a ".txt" file.
ConorH
23
Years of Service
User Offline
Joined: 5th Feb 2003
Location:
Posted: 21st Jun 2006 23:37
Make sure that your NumTilesY and X are both positive values or being what they are supposed to be. And also, you have to parse the string for commas. Look for a topic on "undocumented commands" or something similar, cos there's some token commands in there.

Out of interest, are you using Pizzamans tutorial?

Ps when I get home , Ill try and paste up a working example of what you need; I'm working on the same thing.

its my new rat tail dog!
Psycho Joker
20
Years of Service
User Offline
Joined: 13th Jul 2005
Location:
Posted: 22nd Jun 2006 06:10 Edited at: 22nd Jun 2006 06:13
Yup, I'm implementing Pizzaman's tutorial into my game. He did a great job at tile placement but I found a better way to call the collision to make it more into what I'm looking for in a 2d side scroller. Once I get the basics on how to load a tile map from a txt file, I'll make my own tile code. Can't wait to see the code. thanks!

This is what I got on how to load a tile map from a txt file. It only reads the first string though.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 23rd Jun 2006 09:16
assuming you know the width of the map (so we know what to define the array):

this'll get each number separated by a comma. Note that it overwrites the original string of data to keep things simple and quick.


Here's the code mixed with yours:



I suggest you add the map's dimensions to the beginning of the file.

FILE:


so the first thing you read are the 2 lines at the top to define the array.

read string 1, s$
NumOfTilesX = val(s$)
read string 1, s$
NumOfTilesY = val(s$)

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Psycho Joker
20
Years of Service
User Offline
Joined: 13th Jul 2005
Location:
Posted: 23rd Jun 2006 23:00 Edited at: 27th Jun 2006 05:28
Thanks a lot Phaelax. The code looks good for taking out the commas. Right now I get a message that says, "image number is illegal." I'll mess around with the code when I get back tonight. It should be easy to find out whats wrong.

This is the code that works perfect. Thanks again Phaelax!

Acolyte Entertainment
21
Years of Service
User Offline
Joined: 28th Dec 2004
Location: Oregon, US
Posted: 7th Aug 2006 18:42
Hey psycho. im creating a map editor, this code looks rather impressive.
may i ask if you are using DBP or DB. i had the same question and phaelex told me too come here.
When i try too run your code i get an error "You have hit a FUNCTION declaration mid-program!"
the code im using is:



any ideas?
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 7th Aug 2006 19:29
To fix that, you'll need to place an END after the close file 1

Acolyte Entertainment
21
Years of Service
User Offline
Joined: 28th Dec 2004
Location: Oregon, US
Posted: 7th Aug 2006 20:07
okay. its coming along. i did a little code test.



in the middle you see "print s$"

it only prints the first line of the data, there for when i try too read the data too load into my game it will only read the first line of data, which variable stores all of the numbers

Login to post a reply

Server time is: 2026-07-06 04:31:32
Your offset time is: 2026-07-06 04:31:32