News:

Function Finder  Find all the functions within source code files

Main Menu

How do you simulate layers in PB levels?

Started by servogod85, June 02, 2008, 07:54:29 AM

Previous topic - Next topic

servogod85

I want to know how "conceptually that is" are layers managed in, for example a platform game. To make things clear, In Mappy you can make different layers, like and onion, and according to the priority of the layer, the tiles on higher layers are drawn on top of lower layer tiles. In PlayBasic how does this occur. Lets say I create a map and loaded the tiles and i also created a level. Now how do I go along in my development by making my layers? For example, do i create a different level for each layer and draw them one on top of the other? Does PlayBasic have certain code sets in order to manage this type of problem? ???

kevin

#1
 
To manage scene depth i'd recommend having a good look at Camera/Scene commands.

Various PlayBASIC game examples/demos use them to control the draw order of the scene.  One example that comes to mind is the Xenon 2000 demo.  Which you can find on the home page.  (www.playbasic.com)

servogod85

Alright, i'll definitely take a look into that right now i just need to make a procedure that can interpret mappy maps exported in text form, i spent two days on it and i think tonight i'll make it work so that the PB compiler can eliminate all the empty space, commas, parathesis and convert the number strings in value and then assign it to the level, which will then be designed with the tiles...geez, what a job..i don't know if a program like that doesnt exist already, but in case it doesn't i'll be happy to put in on the forum.

thaaks

But isn't there already an slib to read mappy files? Which also transforms everything into PB world and map stuff?

servogod85

the fact is that my maps have more than one layer, exactly three, and pbasic doesnt seem to load it..it just gives a blank screen..but if i load a one layer map, it gives it to me..im stuck on that...do you seem to know why it does that or how to get around that?

servogod85

#5
Just to give you a better idea, i created the top with mappy, a mario style environment with my three layers, the bottom most layer has some clouds, the hills and a dark tree behind a bush, the second has the blue sky, and the highest has the ground, blocks, and the rest and pb didnt load it, it didnt give me an error but it just stood there with a black screen, while other times it gave me the error described by me in another thread, that is the following:

Fatal Error, Map #7 Does Not Exist

Error Number: (601) at Line (384)

*ThisLayer.PBLevel =NewLevel (*ThisLayer.PBMap,Width,Height)

Error Caused By: NewLevel.


The bottom map instead was loaded and worked perfectly, as you can see it has only on layer, the bricks and the ground.

thaaks

I just had a quick look at <playbasic>\slib\mappy.pba which is the library to deal with mappy maps.
It should be able to load maps with up to 10 layers.
You could switch the debug mode on (change line 40 from "Constant MappyDebugMode =False" to "Constant MappyDebugMode =True") and see what errors pop up while loading the map.
And of course you could upload your map to let others give it a try.
And of course you could compare your code to load and display your map with the projects in the Projects\Examples\Mappy directory.
Sorry if you already did this - then upload your map and let's have a look.

Hope that helps,
Tommy

servogod85

Thanks alot, no I haven't done that yet, I'm not sure if you guy will get upset since I can see if this seems a dumb question, what can I say .. I am a dumb programmer :'(, but here is the code, basicly i just pasted in one of the examples the map i made, the location that is:


/*
  *=-------------------------------------------------------------------=*
                    >> Simple Mappy LIBRARY EXTENSION <<
  *=-------------------------------------------------------------------=*
http://www.tilemap.co.uk/mappy.php
  *=-------------------------------------------------------------------=*

    This Mappy library provided as a simple way for PlayBasic users to
       import maps created with the mappy tile editing software

      It's important to note that not ALL mappy features are supported.       
  *=-------------------------------------------------------------------=*
*/

; Include the Mappy File Loader  (only support 2D maps)
   #Include "mappy.pba"


; Dimension The Mappy Type Variable to Hodl the information about
; any loaded maps
Dim Mappy As tMappy

Filename$="C:\Documents and Settings\Ambiente di lavoro\Documenti\Mappy Map Maker\MAPS\MarioStyle.FMP"

Print "Loading File:";Filename$
Sync

; Load the Mappy File in
Result=LoadMappy(Mappy.tMappy,Filename$)


; create a camera,  This camera will attach it self to the screen
; by default
CreateCamera 1
CameraCls 1,Off
Do
; Tell PB to Start capture GFX item to the scene buffer
CaptureToScene
; Clear the buffer
ClsScene

; draw this map in to the scene at Offset Xpos 0,ypos 0, zpos
DrawMappyLayer Mappy.TMappy,1,%0001,0,0,0

; draw the section of the world the camera sees
DrawCamera 1

; Poll the arrow keys and move the camera is a key is pressed
If DownKey() Then MoveCamera 1,0,2
If UpKey() Then MoveCamera 1,0,-2
If LeftKey() Then MoveCamera 1,-2,0
If RightKey() Then MoveCamera 1,2,0

; Show the Basic info about the Map
Gosub Show_Map_info

Centertext GetScreenWidth()/2,getScreenHeight()/2,"Testing Loading a 24Bit Mappy File"

; Refresh the Screen for the viewer can see it
Sync
Loop





Show_Map_info:

If SpaceKey()
SetCursor 0,0
; Display Map File info
Print "PP Map:"+Str$(Mappy.PBmap)
Print Mappy.Authorname$
Print Mappy.File.Version
Print Mappy.File.Revision
Print Mappy.File.size
Print Mappy.Layer.Width ; Width
Print Mappy.Layer.Height ; Height
Print Mappy.Layer.First ; First Layer
Print Mappy.Block.width
Print Mappy.Block.height
EndIf
Return


And here is the Map *.fmp format , i inserted the tileset also just in case.

thaaks

Just fiddled a bit around with it. Didn't succeed.
I think it's the layer stuff in mappy.pba that's not working properly...
I converted your map to format 0.5 - no success.
I assumed that the order of the layers is wrong (your front layer is 0, the background layer is 1 and the tree/hill layer is 2 - this seems to be wrong anyway). I would order them like this : 0 = background, 1 = trees/hills, 2 = foreground. So I deleted the front layer and created a new one to get the proper layer order - still no success.
I then switched on the debug mode for mappy.pba and started the program (which is mainly the original sample code as you already mentioned) and it halted inside the debugger with the same error message servogod85 already mentioned.
I loaded all sample maps from the projects\examples\mappy\testmaps directory. There's just one other multi layer (indeed two layers, PROJA.FMP) map which also doesn't load successfully.

I give up here  :-\

Kevin, do you have some more ideas? Is it worth digging into mappy.pba to try to fix it?

servogod85

Well thanks I feel much better knowing that something was weird. The order in theory is wrong and I though the same thing but for some strange reason it is mappy that worked correctly putting the layers in that specific way. Without using mappy would you have an alternitive way of getting what i am trying to do? if so could you at least schematically explain me ho to do so? :) ITHANK YOU AGAIN for you help, it has been three days of non stop head-ache.

thaaks

Hi servogod85,
just load the project under projects\Games\Platform_Game_Example_Update.

This will load a two layer map from two simple text files. It contains collision, jumping and all that. Pretty straightforward.

Raise your hand if you have problems understanding that code  ;)

servogod85

I'll get in to that tomorrow morning first thing, right after i do my Math exam, i took a quick look at it, looks very simple and its with the text file, i think that will be the way to go, but i am gonna make the code to get at least a mappy map in exported in text to be loadable through playbasic i am already halfway there, might even be useful for others :)

kevin

QuoteKevin, do you have some more ideas? Is it worth digging into mappy.pba to try to fix it?

Without looking at it,  i've a feeling it's related a typed pointer bug in 1.63.  But that's just a guess.

servogod85

#13
If i create a map with three layers, load each layer seperately and of course specify the transparent block, then if i draw the map, will PB draw me all three levels one on top of the other and give me the layer effect ?

kevin

#14
 If I've understood the question correctly, then the answer is Yes.