News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Im trying to get this to work! (Drawing A Block Map)

Started by baggey, August 15, 2012, 08:35:50 AM

Previous topic - Next topic

baggey

CREATING MY SCREEN GUI TO HOLD MY SPECTRUM EMULATOR USER INTERFACE

Basically i have a jpg of 32x256 containing 32x32 jpg tiles, of a graphical menu image

So:-

I want to load this image.
Then using two for...next loop's in steps of 32. horizontally and vertically go through the loaded image by grabbing 32x32 sections. Placing them in to array "tiles(0)= image grabbed!"
easy really! But not finding the code easy to implement! ???

now using a data array i can build the image of the screen gui. ie, a 1 would display a top_left_corner, a 0 would display a top, a 2 would display top_right_corner and so on to all 16 tiles are stored.

Now the idea is to build a graphical interface of 800x576 which is 25 tiles horizontally and 18 tiles vertically.
build the image.
stretch it to the surface.
sync to display!

so were am i going wrong!!!!!!!!

Thanks in advance baggey



PlayBASIC Code: [Select]
function initiate_gui_menu()

;Load"menu_tiles.jpg"
menu_tiles=loadnewimage ("menu_tiles.jpg")
;Create array of 16 32*32 tile images
dim gui_tile(16)
index=0

;rendertoimage menu_tiles
for y = 0 to GetImageWidth(menu_tiles) step 32
for x = 0 to getimageheight(menu_tiles) step 32
; Get a Free Image ready for use.
;tile=newImage()
; Get a part of the Image from the menu_tiles image
GetImage menu_tiles,x,y,x+32,y+32
;now put this 32*32 image into gui_tile( index)
gui_tile(index)=tile
;increment index by one
index++
next x
next y

; row 0 of menu
for i=0 to 4
rendertoimage screen_gui
img_num = readdata()
drawimage gui_tile(i),i*32,0,2
next

; row 1 of menu
;for i=0 to 25
; rendertoimage screen_gui
;img_num = readdata()
; drawimage gui_tile(i),i*32,1*32,2
;next

sync
;Tiled_data
data 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2
data 3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4

waitkey

endfunction


Jesus was only famous because of his dad

baggey

#1
This is my final bit of code  :-[

[pbcode]function initiate_gui_menu()
   
   ;Load"menu_tiles.jpg"
   menu_tiles=loadnewimage ("menu_tiles.jpg")
   ;Create array of 16 32*32 tile images
   dim gui_tile(16)
   index=0
      
      ;rendertoimage menu_tiles
      for y = 0 to GetImageWidth(menu_tiles) step 32
         for x = 0 to getimageheight(menu_tiles) step 32
            ; Get a Free Image ready for use.
             tile=getfreeImage()
            ; Get a part of the Image from the menu_tiles image
            GetImage menu_tiles,x,y,x+32,y+32
            ;now put this 32*32 image into gui_tile( index)
            gui_tile(index)=tile
            ;increment index by one
            index++
         next x
      next y   
      
   ; row 0 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,0,2
   next i
   
   ; row 1 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,1*32,2
   next i

   ; row 2 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,2*32,2
   next i
   
   ; row 3 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,3*32,2
   next i
   
   ; row 4 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,4*32,2
   next i

   ; row 5 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,5*32,2
   next i   
   
   ; row 6 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,6*32,2
   next i
   
   ; row 7 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,7*32,2
   next i
   
   ; row 8 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,8*32,2
   next i
   
   ; row 9 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,9*32,2
   next i

   ; row 10 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,10*32,2
   next i

   ; row 11 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,11*32,2
   next i

   ; row 12 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,12*32,2
   next i   
   
   ; row 13 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,13*32,2
   next i

   ; row 14 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,14*32,2
   next i

   ; row 15 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,15*32,2
   next i

   ; row 16 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,16*32,2
   next i

   ; row 17 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,17*32,2
   next i

   ; row 18 of menu
   for i=0 to 25
      img_num = readdata()
      drawimage gui_tile(i),i*32,18*32,2
   next i

   sync
   ;Tiled_data
   ;Note these numbers may noy represent the correct tile layout !
   data 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2
   data 3,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 3,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,4
   data 6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,8
   waitkey

endfunction
[/pbcode]
Jesus was only famous because of his dad

kevin


  There's a number errors in it, but i'll give you a hint. 

  GetImage menu_tiles,x,y,x+32,y+32


baggey

#3
Well heres the latest effort. Im getting the tiles loading and working with the different tiles stored in the tile(index) array!
And im managing to get some sort off display going! This is only for GRAPHICAL INTERFACE for my speccy emulator.

I know its some thing to do with the loop iterations! going out of step, so to speak!

But im just starting to go around in circle's  ???

My latest code
PlayBASIC Code: [Select]
function initiate_gui_menu()

;Load"menu_tiles.jpg"
menu_tiles=loadnewfximage ("menu_tiles.jpg")
;Create array of 16 32*32 tile images
Tile=newfximage(31,31)
;tile=loadnewfximage ("cross_bar.jpg")
dim gui_tile(50)
for i=0 to 50
gui_tile(i)=tile
next i

index=0

;rendertoimage menu_tiles
rendertoimage menu_tiles
SeedbufferRead=Point(0,0)
lockbuffer
for x = 0 to GetImageWidth(menu_tiles) step 32
;index=0
for y = 0 to getimageheight(menu_tiles) step 32
;Get a Free Image ready for use.
newtile=getfreeImage()
;Get a part of the Image from the menu_tiles image
GetImage newtile,x+1,y+1,x+32,y+32
;now put this 32*32 image into gui_tile( index)
gui_tile(index)=newtile
;increment index by one
index=index+1
;print index
;unlockbuffer
;sync
next y
next x
unlockbuffer
;sync


;rendertoscreen
rendertoimage screen_gui
SeedbufferRead=Point(0,0)
lockbuffer
col=32
; Restore data position to 0
Restore 0
; row 0 of menu
for i=0 to 25
img_num = readdata()
drawimage gui_tile(img_num),i*32,0*col,0
next i

; row 1 of menu
for i=0 to 25
img_num = readdata()
drawimage gui_tile(img_num),i*31,1*col,0
next i

; row 2 of menu
for i=0 to 25
img_num = readdata()
drawimage gui_tile(img_num),i*31,2*col,0
next i

; row 3 of menu
for i=0 to 25
img_num = readdata()
drawimage gui_tile(img_num),i*31,3*col,0
next i

; row 4 of menu
for i=0 to 25
img_num = readdata()
drawimage gui_tile(img_num),i*31,4*col,0
next i

; row 5 of menu
for i=0 to 25
img_num = readdata()
drawimage gui_tile(img_num),i*31,5*col,0
next i

; row 6 of menu
for i=0 to 25
img_num = readdata()
drawimage gui_tile(img_num),i*31,6*col,0
next i

; row 7 of menu
for i=0 to 25
img_num = readdata()
drawimage gui_tile(img_num),i*31,7*col,0
next i

; row 8 of menu
for i=0 to 25
img_num = readdata()
drawimage gui_tile(img_num),i*31,8*col,0
next i

; row 9 of menu
for i=0 to 24
img_num = readdata()
drawimage gui_tile(img_num),i*31,9*col,0
next i

; row 10 of menu
for i=0 to 24
img_num = readdata()
drawimage gui_tile(img_num),i*31,10*col,0
next i

; row 11 of menu
for i=0 to 24
img_num = readdata()
drawimage gui_tile(img_num),i*31,11*col,0
next i

; row 12 of menu
for i=0 to 24
img_num = readdata()
drawimage gui_tile(img_num),i*31,12*col,0
next i

; row 13 of menu
for i=0 to 24
img_num = readdata()
drawimage gui_tile(img_num),i*31,13*col,0
next i

; row 14 of menu
for i=0 to 24
img_num = readdata()
drawimage gui_tile(img_num),i*31,14*col,0
next i

; row 15 of menu
for i=0 to 24
img_num = readdata()
drawimage gui_tile(img_num),i*31,15*col,0
next i

; row 16 of menu
for i=0 to 24
img_num = readdata()
drawimage gui_tile(img_num),i*31,16*col,0
next i

; row 17 of menu
for i=0 to 24
Login required to view complete source code


Here is the tile map im working with

Jesus was only famous because of his dad

kevin

#4
  Here's a couple of variations.   The first is cutting up the images into blocks, which then splodges them out in a map form.  Then second one is using maps.
 
PlayBASIC Code: [Select]
    Screen=Load_GUI_Menu()

drawimage Screen,0,0,false

sync
waitkey


Psub Load_GUI_Menu()

// Get the current render surface
oldsurface=getsurface()

// load the blocks in as FX
menu_tiles=loadnewFximage ("E:\Downloads\menu_tiles.png")

// Grab the blocks
rendertoIMage Menu_Tiles
Dim Blocks(50)
For ylp =0 to GetSurfaceHeight()-1 step 32
For xlp =0 to GetSurfaceWidth()-1 step 32
Blocks(Index)=GetFreeImage()
GetImage Blocks(Index),xlp,ylp,xlp+32,ylp+32
index++
next
next

// define the map as string
R$ = "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"


// create the screen image
Screen=NewIMage(32*25, 32*20,2)

// Draw this map out as an image
rendertoimage Screen


// dim our tiles array
Dim TempTiles(0)

// split the string into this 1D integer array
count=SplitToArray(r$,",",TempTiles(),0)

// copy them into the level
Index=0
For ylp=0 to 20
For xlp=0 to 24
ThisBlock =Blocks(TempTiles(index))
if GetIMageStatus(ThisBlock)
drawimage ThisBlock,xlp*32,ylp*32,false
#print ThisBLock
endif
Index++
next
next

// restore the previous render surface
rendertoimage oldsurface

For lp =0 to GetArrayElements(Blocks())
if GetIMageStatus(Blocks(lp))
deleteIMage Blocks(lp)
endif
next

// free the temp resources
deleteimage menu_tiles
undim Blocks()
undim TempTiles()

EndPsub Screen






or by using maps

PlayBASIC Code: [Select]
    Screen=Load_GUI_Menu()


drawimage Screen,10,10,false

sync
waitkey


Psub Load_GUI_Menu()

// Get the current render surface
oldsurface=getsurface()

// load the blocks in as FX
menu_tiles=loadnewFximage ("E:\Downloads\menu_tiles.png")

// Spwan a new map
ThisMap=NewMap(10)

// import the Menu tiles into map blocks
MakeMapGFX ThisMap,Menu_Tiles,32,32,30,aRgb(0,0,0,0),2

// create a child level of this map
ThisLevel=NewLevel(ThisMap, 25, 20)

// define the map as string
R$ = "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"
R$ += "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,"

// dim our tiles array
Dim TempTiles(0)

// split the string into this 1D integer array
count=SplitToArray(r$,",",TempTiles(),0)

// copy them into the level
For ylp=0 to 19
For xlp=0 to 24
POkeLevelTile ThisMap,Thislevel,Xlp,Ylp,TempTiles(index)
Index++
next
next

// create the screen image
Screen=NewIMage(32*25, 32*20,2)

// Draw this map out as an image
rendertoimage Screen
DrawMap ThisMap,ThisLevel,0,0


// restore the previous render surface
rendertoimage oldsurface


// free the temp resources
deleteMap ThisMap
deleteimage menu_tiles
undim TempTiles()

EndPsub Screen