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! / Question About Drawing Layers of Tiles

Author
Message
JHA
22
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 2nd Jun 2004 06:48 Edited at: 2nd Jun 2004 06:55
Hello All,

Inspired by X-Men, I am building my own Tile Editor for any type of 2D game, from RPGs to Platform scrollers and so on. Everything is going quite well, thanks to the help from people here in the forums, but I am a little stuck at the moment and need another pair of eyes, or 20.

I have attached my _MainScreen subroutine that draws the map everytime it is called from the Main Loop. It works as long as I am on layer one.

What I am trying to do, is have several layers of tiles that can co-exist in the same XY location. Higher layers use tiles with transparent portions to let the lower layers show through. For instance, if there is a grass tile on layer 1 and a tree tile on layer 2, then it will appear as though they are just a single merged tile.

As stated above, I can put any tiles I want on layer 1, but once I go to the next layer, the tile does not get drawn. If I go back to layer 1, then all is well again. I can still see all of the tiles on layer 1, I just can't draw new ones onto layer 2 or higher.

I'm not sure why it isn't working, so could someone take a look at my code and make suggestions?

The 'layer' variable is assigned in the Main Loop by pressing the 1, 2 or 3 keys. There is currently only 3 layers, but I may add more if I can think of a reason to do so. I am thinking that the 3rd layer will provide my collision detection scheme. I can assign certain tile locations as doorways, walls, locked doors, treasure chests and so on.

Thank you all in advance.

JHAustin
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 2nd Jun 2004 10:39 Edited at: 2nd Jun 2004 11:06
JHA,
First nice avatar. Is it related to their...
Console Hardware: 2600/5200/7800/XE/ (play groan soundtrack here...Lynx/Jaguar)?
Computers: 400/600/800/X/65XE/ST?
Software: Past/Current?
Arcade: ?

Just Curious. I ordered the retro T-Shirt from a 3rd party but never received it. Navy Blue/White Logo. Should have used PayPal.


Great description in post about the problem you are having, but reading though the limited attached source code, my bedt guees would be that the possible cause is:

You reset the topoffset to 0, but before moving to your next layer you don't reset the leftoffset to 0. So I believe your tiles are being drawn out of your screens view.

If this is not the problem I would need to see more of your code, preferrably all, but I can understand the hesitation in posting it. Other things it could be:
-numLayers not being set to = to 2 or 3. Mispelling or Miscase on the capital L.
-Something in your layer selection routine.

Let me know.

As a suggestion I would use five layers, four if DBC FPS drops.
Reasoning:

layer 1: Base terrain Tiles

layer 2: Tiles above base terrain but character can walk over. e.g high grass. Also great to use for easter egg passage ways. eg. character can walk on water tiles placed on this layer, or walk through walls on this layer

layer 3: This is the layer your charcter is drawn on. Any items that the player cannot walk over or under are also on this layer. eg. NPC's, Stumps, barriers oceans, mountains, walls, chests. In this way your collision is built into the map.

layer 4: Tiles your character can walk under. e.g. Bridges, overhangs, extending tree branches/leaves

layer 5: Atmospheric effects. eg. Clouds, Flying birds etc...

Something else of interest.
Lately I put the base terrain at level 0.
Then I use layer 1 as a fringing (hard coded transition layer). Simply stated rather than drawing grass to path, grass to stone, grass to water etc. I have a priority structure: Grass always hangs over stone, shoreline hangs over water etc.
Then after the base terrain tiles are placed I check the array for these cases, and place the correct fringe image to smooth out the tile transitions. Saves you an exponential ammount of drawing unecessary tiles.
5 layers 0-4. (You can still use 1-5 but it was easier for me to explain by changing just the one layer)

Hope that helps. If you need an example I can post my overly used dreadful 5layer RPG snippet "The Craft". haven't posted it in a few months.

Is it obvious from my long posts lately that my fiancee broke up with me.
Totally DBpro's fault by the way. You guys should really put a warning on the box. She hated games... and hated my programming even more and was repulsed by the forums. At least I'm actually coding agian.


JHA
22
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 2nd Jun 2004 20:30 Edited at: 2nd Jun 2004 20:36
Hello zenassem,

Thank you for posting. Unfortunately, I am at work right now so I cannot try your suggestions. I have an older copy of the program here but that PC is being worked on, so I don't have access to it, at the moment.

I like the way you plan out the layers. I will probably adopt that method, once I get all the layers working.

I will post all of the code, when I get home. I had planned on releasing the source at some point anyway, so it might as well be now. Obviously, I still have a ways to go, so it is still a bit primitive.

I think I found the Avatar as one of the standard options. For me, it represents the old Atari 2600. I played that thing to death back in the late 70's, early 80's. I did have an Atari 600 XL before moving to the Commodore 64, then the Amiga 500, before moving on to the PC in the early 90's. Computers have come a long way since then.

Thanks again for the suggestions. I'll post again later tonight. I am on the North-East coast of the USA. It's 12:30 PM. Lunch Time!!


[Edit]: Just noticed that you are in the same time zone. I am in Massachusetts, about 40 mile south of Boston.

JHAustin
JHA
22
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 2nd Jun 2004 20:48 Edited at: 2nd Jun 2004 20:51
Hello again zenassem,

Quote: "You reset the topoffset to 0, but before moving to your next layer you don't reset the leftoffset to 0. So I believe your tiles are being drawn out of your screens view."


Looking through your post again, I think you hit the nail on the head. Thinking through the logic, that would certainly explain the behavior I'm seeing.

I'll let you know if that was it or not. I don't think the problem is in the layer selection routine. That seems to be working fine. I will check the spelling and case sensitive issue though.

BTW - I am using DBPro.

Thanks again
JHAustin
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 2nd Jun 2004 21:17
JHA,

Yeah, post back and let me know if that fixes it.

Some Historical Rambling of my Geekdom
I still have the original VCS atari 2600 with the wood grain decor. Still play Adventure, Missile command, And my first basic language cartridge. Programming on the 2600 with a numeric keypad and joystick was painstakingly ammusing.

My first computer was the 600XL. It had a cassette drive. Unfortunately, unlike commodore's cassette recorders abilty to search for directories, the Atari recorder required you to remember the time counter on the tape. Caused a lot of problems if you forgot to reset the counter to 0. Or when the tape strecthed. Eventually I found some code in Compute! magazine that allowed me to create and search for directories.

The next year I purchased a 1050 5 1/4 Floppy drive. Unfortunately, the 600xl couldn't access disk drives without a mod. I moved up to the Atari 65XE. I spent alot of time with that and the commodore 64 that my uncle was getting rid of. When I found Simon's basic I began exclusively using the commodore. I currently have both the 65XE, & 64/128 hooked up.

Eventually I found out about Assembly Language and located FASSEM (Assembler-Dissaembler) by Merlin Software. Coupled with Computes! "Machine Language for Beginners" I felt ever so powerful.

Then I saw the Commodore Amiga and Atari ST. Game Over!
The games for the Amiga still look good.

I always wished that I could mix some of Atari Basic's graphic commands (player/missile) with commodores flexability and smooth syntax. Atari had good features, too bad it was too cumbersome to get use of them. Assembly evened the score a bit.


JHA
22
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 3rd Jun 2004 05:05
Hey zenassem,

As suspected, that was it !! Its working great now. I also had to add the ,1 to my Paste Image line to enable the transparency, but that only took me about 2 seconds to figure out.

Its funny, growing up, I was the only one I knew that was into computers. Sure, everyone played games, but I couldn't find anyone to bounce ideas off of, because I already knew more than them. Looking at your Historical Geekdom Ramblings, it is amazing how similar our paths have been as well as others here on the forums.

Well, thanks once more.

JHAustin
JHA
22
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 7th Jun 2004 00:53
Hello zenassem,

Quote: "If you need an example I can post my overly used dreadful 5layer RPG snippet "The Craft". "


Would you mind posting this code?

I do have all 5 layers working, but I'm sure I could learn a thing or two from your code.

Thanks again for your help.

JHA
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 10th Jun 2004 21:33
JHA,

Sorry, I was away from the forums for the past couple of days to actually work on some code. These forums can sometimes suck up a lot of time if one's not careful. I will post the code tonight.

I'll also post links to the images that I use for the tiles/sprites
It's fairly simplistic. It's basically:

- A 5 Layer map that's read in from data statements (with the collision built in like I spoke about above)
- Moveable sprite character 4 Frames animation per direction (N,S,E,W).
- A interior bounding rectangle. (So that the character moves across the screen to a limit, at which point the character animates in-place, while the tile-world scrolls underneath)
- Checks for random encounter with monster.
- If encounter is true it Shifts to a battle screen (ala. Origianl Final Fantasy)
- A VERY simple Attack routine.

Like I said I will post later, let me know if it helps at all.

~Zen


JHA
22
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 11th Jun 2004 21:04 Edited at: 11th Jun 2004 21:05
zenassem,

Excellent!

I'm looking forward to it.

I know what you mean about the forums. I sometimes intend to code, but end up reading through all the posts that I missed. By the time I'm finished, it's time for bed.

All this knowledge with no time to implement it!! I can get rather frustrated with myself, when that happens.

Thanks again. I really appreciate the help.

JHA
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 11th Jun 2004 22:37 Edited at: 11th Jun 2004 22:38
JHA,

Sorry, I didn't post last night. I myself wound up tired amd fell asleep early. I'm at work now, but will try to post it tonight. I have some sidework that I need to take care of after I get off but I hope to be home around 6:30-700pm US est. I'll try to post it before 900pm. I have to fix an issue with the DBpro code, but I believe I know how to resolve it. I'll probably post the original DBC code, and then make edits to the post, so keep an eye out for it.

~zen


JHA
22
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 12th Jun 2004 16:27
Hey Zen,

No problem. Whenever you get the chance. I can appreciate a busy schedule.

JHA
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 16th Jun 2004 00:14 Edited at: 16th Jun 2004 00:18
JHA,

Here goes a double sorry. It took me longer than expected to clean up the differencces with DB & DBpro. I wound up cutting out my simple battle code. The problem was it was disconnected from the main loop. I will add that code later if you care to see it. For now it flashes to the battle screen and then back.

Here's a screenshot of the simple tile-world



The code is in the [Source] button below.
I'll post links to the images shortly. So that you can test it out.
I know that the code isn't great, but I wrote this when i was first playing with DBC.


JHA
22
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 17th Jun 2004 03:30
Hi Zen,

Thanks for the code. It is very interesting. I think I will learn allot from it.

No problem with the images. Whenever you have time.

The battling code would be nice too, even if it doesn't work quite right. I'm sure I could grab the concept behind it. I am an accomplished programmer in the world of VB, VB.NET and others, so it shouldn't be a problem.

Thanks again, for all your help.

JHA
Rknight
22
Years of Service
User Offline
Joined: 25th Sep 2003
Location: NJ
Posted: 17th Jun 2004 04:48
I like the levels. Looking forwards as well to the images to test out that code.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 17th Jun 2004 17:46
Ok here are the images that are needed. You will also need to rem out the midifile loads. if you were curious, the midi's are final fantasy music.

I looked at the source I posted and I realized that the mapdata was a test where all images were on the same level. You can edit the map data by hand to make changes. I will post a better example of the code as I am cleaning it up and working the battle engine back in.




JHA
22
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 19th Jun 2004 22:19
Hi Zen,

Thanks for the code and images. I've only now been able to look at it. I really appreciate your willingness to share this.

Please believe that I am not ungrateful. I am just pointing out what I've seen: It looks like the "chltmov" routine is missing. Also, the character doesn't seem to move correctly when I press the arrowkeys. Pressing the left arrow does nothing, since the chltmov routine ismissing. I put a dummy version of it in there to prevent an error. Pressing the right arrow immediately sends me into the battle screen, which then pops back to the main screen, as you said it would. Pressing the down arrow moves the character left. I get an illegal image number error on line 464, when pressing the up arrow. (This line is "SPRITE CurrSpr,PLocX,PLocY,anim", in my IDE.)

I could probably figure it out, but I thought I would mention it to you any way.

Other than this, it seems very cool. I will learn allot from it.

Thanks again
JHA
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 19th Jun 2004 22:49
JHA,

Thanks for pointing that out. I am looking though the code right now and I'll fix it. It was probably a result of me pulling pieces out. I'll repost a basic working example in a few minutes. I rushed it because I felt bad I didn't get to it right away. I also noticed something else. When I wrote this code, I didn't realize that when pasting images you also need to specify the transparency flag. This can come into play when you have tiles like items that don't take up the full square of the tile, and have transparent elements. I'll fix that as well.

I've learned alot since first writing this code (and the fact that it was originally in DBC), so I am in the process of rewriting it and cleaning up alot of the unecessary stuff, and bad coding practices. As you'll see in another post here, the sprite frames should only be incremented once per loop. When I wrote this code I didn't understand how to effectively accomplish this. So I had the sprite cycyle through all three frames of animation for every key press in one loop cycle. This is not ideal. I should have the one sync in the main loop, and the animation should only increment 1 frame per game-loop cycle. By breaking it up the way I did here, I am seriously forcing a bottleneck in the program and hard-coding a FPS reduction. I'll fix that as well.

So my first post will be the same code with some fixes that you mentioned. Later I will post a complete re-write with the knowledge that I now have, and include a simple battle-system.

~zen


zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 20th Jun 2004 01:00 Edited at: 20th Jun 2004 01:10
Ok,

[EDIT]I just noticed that the source button is cutting out some of the code. I just looked and sure enough it chopped out stuff for the move right. Why is it doing that? arghhhh!!!

Just go to the code snippet in the next Post.




So far I fixed the movement and collision/map code. I also rem'd out
the frame limiter code, and the checkencounter code for now. The map
is now using the layers properly.

Problems with the frames and animation
Warning! Long-winded, In-depth explantion



So I will have to rewrite the movement, timing, syncing logic for
DBpro. For now just lower the sync rate to slow the character down. I
will fix it properly today. The same issues effected the battle code.


Sorry this 1st basic fix took longer than expected. To fix the maps, I
used search and replace feature in the editor. during one of my
replaces the scope must have been set for the entire code and I saved
before I realized it. All 3's in my code changed to 0's and it was too
late to undo. .


So I had to go through the code trying to spot where 0's should have
been 3's. I found most of them, at least enough for the basic fix to
work.


The first fix is in the source button below


I'll post again later with a complete rewrite that will include all of
the code, and work with DBpro.


~zen


zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 20th Jun 2004 01:11
Here is the code Unchopped...




JHA
22
Years of Service
User Offline
Joined: 30th Dec 2003
Location: Massachusetts, USA
Posted: 23rd Jun 2004 05:17
Hey Zen,

That's it!! Thanks man!

It works beautifully now.

I can't tell you how much I appreciate this. I can't wait until I'm the guru and can help others.

JHA

Login to post a reply

Server time is: 2026-06-09 13:56:10
Your offset time is: 2026-06-09 13:56:10