Load all the tiles in a folder with different names

Advanced game related topics
User avatar
Fractalorangejuice
User
User
Posts: 14
Joined: Thu Jun 18, 2009 6:14 am
Location: Berlin,Germany

Load all the tiles in a folder with different names

Post by Fractalorangejuice »

Hello.. I'm new to posting here. I've been reading this forum for a while now but I wanted to make sure I had a question worth asking before I wasted anyone's time.

I have a fairly strong graphics/music background but when it comes to coding I find my brain to be a bit of a blunt object so I apologize in advance for being a little slow to grasp certain concepts.

This is going to be for a 2d tile editor for a HD remake of an old game.
I'm using sprite3d with alpha blending
I don't know that all these steps are necessary, it's just my current understanding of how it can work. If there is a better way you have my full attention.

What would be an efficient way to create a load tile loop that:
1) loads tiles(with completely different names but in animated but numbered sequences)(all png) from a subfolder. Only files with numbers in their names will used be for animated tiles. (I'm guessing some kind of pointer system to track the last file and Isfile() to check if it exists)
2) uses the filename of the tile to create a variable name for the sprite and gives it a number #PB_Any I guess and then save that to a (linked list? using a structure)
3) sets up both the LoadSprite and CreateSprite3d in the loop
and pastes them to a bitplane which is then displayed or perhaps saved as a series of larger sprites onscreen which then have their images swapped out as the map is moved.

I want it to be as quick as it can be but I also don't want to give up my beloved alpha blending because of all the layering and custom fx possibilities. I've been looking at neotoma's HGE Wrapper which looks awesome but it's a little beyond me just yet. As I fairly recently left Dark Basic for this(a real programming language).(sorry , but for all it's simplicity there were some just stupid workarounds in that syntax, the exes were huge and they were so painfully slow)

I'd like to create a tile editor and then use that to load the animation frames and tiles and then save a data file of the various settings such as tiles.xxx which I guess is the best solution since all this doesn't really 'need' to be automated. I still need to learn how to create files to load and save from and know what actually is saved in them.

Here is some of what I have been playing around with so far

Code: Select all

For count=1 To 495
     image.s = Right(Str(count),3)+".PNG"
     image.s = "tiles/tile"+image.s
     LoadSprite(100+count,image.s,#PB_Sprite_AlphaBlending | #PB_Sprite_Texture) : CreateSprite3D(100+count,100+count)
Next
This of course works only as long as the numbers are in sequence.

I know this is a bit all over the place, I'm sure I'll come back later and clarify this when I've had my coffee. :)

And no I'm not one of those idiots asking for you to write my program for me. I'm a completely different kind of idiot. ;)

Any productive/constructive advice you can give me would be appreciated.
Also I'm in Berlin, Germany so if anyone is in town and willing I would love to buy you coffee and pick your brain. I'd be glad to put together some graphics/sfx/music in exchange for some help if anyone has time.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

Hi there, welcome to the forums! :)

load all your sprites in advance, before starting the mainloop.
it is your game directory, your content directory, so you have full control over the filenames in it.
if you want your tiles to be named "tile001" up to "tile495", just do so.

yes, a for-loop with a Str() is a good way to loopload tiles.
you can also use RSet( Str(n), 3, "0" ) to include leading zeros.

better use #PB_Any for loading sprites.
you can build a LList with simple Types, too.
for a TileSet, an Array would be the better choice:

Code: Select all

Structure Tile
  Spr2D.i
  Spr3D.i
EndStructure

Dim Tiles.Tile(495)

For count=1 To 495
     image$ = "tiles/tile" + RSet(Str(count),3,"0")+".PNG"
     Tiles(count)\Spr2D = LoadSprite( #PB_Any, image$, #PB_Sprite_AlphaBlending | #PB_Sprite_Texture)
     Tiles(count)\Spr3D = CreateSprite3D( #PB_Any, Tiles(count)\Spr2D )
Next
for the MapEngine, build a 2D-Array to store the tilenumbers of your entire Map.
you can use a Struct there to store several Layers and stationary Objects.

tiny MapEngine example:
http://www.purebasic.fr/german/viewtopi ... 634#116634
oh... and have a nice day.
User avatar
Fractalorangejuice
User
User
Posts: 14
Joined: Thu Jun 18, 2009 6:14 am
Location: Berlin,Germany

Post by Fractalorangejuice »

Vielen Dank Herr Gaman ;) Das war sehr freundlich

I looked at your code from the other post and it works beautifully. There is one thing about it I'm having trouble understanding.

Code: Select all

;***********************************
;*** Tile Engine
  For SY=0 To 38
    For SX = 0 To 50
      DisplaySprite(100+Map(MapX+SX,MapY+SY), 16*SX - FineX , 16*SY - FineY )
    Next
  Next
;*********************************** 
How are you executing DisplaySprite outside of a startdrawing() - stop drawing() block? Does it have something to do with StartDrawing(SpriteOutput)?

Normally I work in windowed mode and maybe there is something different about full screen here that I'm missing.Also I've never drawn directly to sprites.

This is how I usually set things up (minus loops/structures/setups..)

Code: Select all

screenX       = 1024      ;screen resolution horizontal
screenY       = 768       ;screen resolution vertical

InitSprite()
InitSprite3D()
Sprite3DQuality(1)
InitKeyboard()
InitMouse()
UsePNGImageDecoder()
InitSound()
UseOGGSoundDecoder()
mainwindow.l = OpenWindow(1,0,0,screenX,screenY,"Test project",#PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
OpenWindowedScreen(mainwindow,0,0,screenX,screenY,0,0,0)
SetFrameRate(60)

Repeat
StartDrawing(WindowOutput(1)) : DrawingMode(#PB_2DDrawing_Transparent)
 Start3D()
 DisplaySprite3D(spritenumber,positionx,positiony,255)
 Stop3D()
 StopDrawing()
 FlipBuffers(1)
 ClearScreen(RGB(255, 255, 255))
 If KeyboardPushed(#PB_Key_Escape) : exit = 1 : EndIf 
Until exit = 1
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

;) aber sicher doch

DisplaySprite must be outside Start/StopDrawing

drawing blocks are for drawing commands like Box or Line: 2DDrawingLib

for DisplaySprite3D you need a Start/Stop3D block, no drawing allowed here, either.
your code with 3D inside Drawing should produce an error....

in the x-y-loops you quoted, I display Sprites on a Screen. would be exactly the same for sprites on a windowed screen.
oh... and have a nice day.
User avatar
Fractalorangejuice
User
User
Posts: 14
Joined: Thu Jun 18, 2009 6:14 am
Location: Berlin,Germany

Post by Fractalorangejuice »

I see.. I've been doing something insane.. :shock: :oops:
So I don't need to reinitialize the window after the initial setup.

Code: Select all

mainwindow.l = OpenWindow(1,0,0,screenX,screenY,"Test project",#PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
OpenWindowedScreen(mainwindow,0,0,screenX,screenY,0,0,0)
SetFrameRate(60)

Repeat
 Start3D()
 DisplaySprite3D(spritenumber,positionx,positiony,255)
 Stop3D()
 FlipBuffers(1)
 ClearScreen(RGB(255, 255, 255))
Until KeyboardPushed(#PB_Key_Escape)
Wow. I know I probably should have known this, but that is just so much garbage I can remove from my code.. Thank you!!

Oh look.. my program is running faster. :D
Ich bin ein glücklicher Mann heute!
Post Reply