Problems when importing tile bitmaps?

Started by Mick Berg, November 10, 2005, 01:58:06 PM

Previous topic - Next topic

Mick Berg

Again, having spent hours trying to find out what my problem is, I'm coming to you for help. In the attached program there is no problem with the tiles that are drawn within the program, but when I import the tiles as a bitmap they get drawn all overe the screen. Again, what am I not understanding?
Thanks again, I hope these examples are of use to other beginners. The tile bitmap is attached.
SETFPS 50
;draw some tiles within the program
TileWidth=32
TileHeight=32
Number_of_tiles = 4
FOR lp=1 TO Number_of_tiles
    xpos=lp*tileWidth
    BOXC Xpos,0,Xpos+TileWidth,TileHeight,1,RNDRGB()
NEXT
TempImage=GETFREEIMAGE()
GETIMAGE TempImage,0,0,128,32
MyMap=GETFREEMAP()
CREATEMAP Mymap,1
MAKEMAPGFX MyMap,1,32,32,4,RGB(0,0,0)
DELETEIMAGE TempImage
CREATELEVEL MyMap,1,25,18
FOR lp=1 TO 23
   POKELEVELTILE MyMap,1,lp,10,2
NEXT lp
DRAWMAP MyMap,1,0,50
SETCURSOR 300,10: PRINT "PRESS ANY KEY TO SEE THE NEXT EXAMPLE"
SYNC
WAIT 1000
WAITKEY
;****************************NEXTSECTION***************************
CLS RGB(0,0,0)
;import some tiles
LOADIMAGE "PigTileGFX.bmp",1
DRAWIMAGE 1,32,0,1
TempImage=GETFREEIMAGE()
GETIMAGE TempImage,0,0,128,32
MyMap=GETFREEMAP()
CREATEMAP Mymap,1
MAKEMAPGFX MyMap,1,32,32,4,RGB(0,0,0)
DELETEIMAGE TempImage
CREATELEVEL MyMap,1,25,18
FOR lp=1 TO 23
   POKELEVELTILE MyMap,1,lp,10,2
NEXT lp
DRAWMAP MyMap,1,0,50
SETCURSOR 300,10: PRINT "WHY IS THE FIRST TILE DRAWN ALL OVER THE MAP?"
SYNC
WAIT 1000
WAITKEY

empty


kevin

#2
You haven't imported the correct block set. See bellow


PlayBASIC Code: [Select]
SetFPS 50
;draw some tiles within the program
TileWidth=32
TileHeight=32
Number_of_tiles = 4
For lp=1 To Number_of_tiles
xpos=lp*tileWidth
BoxC Xpos,0,Xpos+TileWidth,TileHeight,1,RndRGB()
Next
TempImage=GetFreeImage()
GetImage TempImage,0,0,128,32
MyMap=GetFreeMap()
CreateMap Mymap,1
MakeMapGFX MyMap,1,32,32,4,RGB(0,0,0)
DeleteImage TempImage
CreateLevel MyMap,1,25,18
For lp=1 To 23
PokeLevelTile MyMap,1,lp,10,2
Next lp
DrawMap MyMap,1,0,50
SetCursor 300,10: Print "PRESS ANY KEY TO SEE THE NEXT EXAMPLE"
Sync
Wait 1000
WaitKey
;****************************NEXTSECTION***************************
Cls RGB(0,0,0)
;import some tiles

;>> Here your loading the original block set as image #1. This block set has 4 tiles, then you paste to the screen with space for transparent tile at the start.

LoadImage "PigTileGFX.bmp",1
DrawImage 1,32,0,1

;>> now you grab a new (tempimage) from the screen. Which will create an image with 5 blocks on it. The one you want to use for the map.

TempImage=GetFreeImage()
GetImage TempImage,0,0,128,32

MyMap=GetFreeMap()
CreateMap Mymap,1

; >> But previously, you imported Image #1 (the original 4 block image) rather than then temp image you created. So all you needed to do is import the TempImage here, and it'll work as you'd expected.
MakeMapGFX MyMap,Tempimage,32,32,4,RGB(0,0,0)


DeleteImage TempImage
CreateLevel MyMap,1,25,18

For lp=1 To 23
PokeLevelTile MyMap,1,lp,10,2
Next lp

DrawMap MyMap,1,0,50
SetCursor 300,10: Print "WHY IS THE FIRST TILE DRAWN ALL OVER THE MAP?"
Sync

Wait 1000
WaitKey








Mick Berg

So am I to understand that the map is completely filled with the first tile, so the first tile has to be in the transparent colour? I didn't find anything like that in the documentation.
But thanks for explaining the problem, I can get on with building my first map now.

kevin

QuoteSo am I to understand that the map is completely filled with the first tile

 When a level is created in memory it's zero'd by default.  Just like if you create a 2D array, an image etc etc, it'll contain zero's initially.

 i.e
 Dim Map(5,5)
 For ylp=0 to 5
 For xlp=0 to 5
   print map(xlp,ylp)
 For xlp=0 to 5
 next ylp

So when you create a level it;s zero'd.  If you render this level, it'll draw whatever gfx block zero is..


Quote, so the first tile has to be in the transparent colour?

 No.

 By default levels are set to solid mode.  In this mode, the tiles are drawn with no transparency. So effectively every block is drawn. Whether it's clear or not.  

 However  if you enable transparency for the map.  Tiles will be drawn using the maps mask colour.  Also, you can nominate a transparent block.  This block is never drawn, and is generally block zero in your tile set.  But not always, hence the ability to set it your self.