Blitting tiles with arrays OOP and 'LoadAnimImage'

BlitzMax Forums/BlitzMax Beginners Area/Blitting tiles with arrays OOP and 'LoadAnimImage'

Nightsight(Posted 2008) [#1]
This is what is supposed to happen: Blit 10 tiles (based on the order in 'MapData', one after the other.

This is what's happen: It will blit the last chosen tile 10 times, one after another. So it ends up showing tile number 10 ten times.

It does update all the coordinates, and if run in debug it also runs through every selected tile. But still decides to only blit the last tile selected in the cycle (after ten cycles). It will wait till after the last cycle before it blitz anything on screen.

Any ideas?

Part of program:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Type TTile Extends TGameObject
	Function Create:TTile (Image:TImage,xstart:Int,ystart:Int)
        Local obj:TTile =New TTile 
        CreateObject(obj,Image,xstart,ystart)
 	Return obj
    End Function

    Method UpdateSelf()
	If GameState<>PLAY Then Return
	Frame = ChosenTile     'ChosenTile is a Global
	EndMethod
	
EndType
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function CreateTiles()

Local ChosenTilePosX:Int = -16
Local ChosenTilePosY:Int = 16
Local TileCounter:Int
Local LowNumber:Int
Local HighNumber:Int

'DebugStop
LowNumber = 1
HighNumber = LowNumber + 1

Local MapData [] = [0,1,2,3,13,13,13,13,14,15,2,2,2,16,17]

For Local LoopTheTiles:Int = 1 To 10

Local SelectedTile:Int [] = MapData [LowNumber..HighNumber]
For ChosenTile  = EachIn SelectedTile

ChosenTilePosX :+32
LowNumber:+1
HighNumber:+1

'If ChosenTilePosX > Width Then 		
'ChosenTilePosX = 16 
'ChosenTilePosY :+32
'EndIf

TTile.Create(LoadAnimImage("incbin::Gfx/Tiles/BlueWallTiles_32x32x256.png", 32, 32, 0, 95),ChosenTilePosX ,ChosenTilePosY ) 
Next
Next
EndFunction



GfK(Posted 2008) [#2]
Code isn't complete so its difficult to say, but I have a feeling that you're adding 10 instances of the same object to your list, rather than creating a new object each time and adding that.


Nightsight(Posted 2008) [#3]
- Gfk,

I think it must be something like that, I'm just not sure why it will update the coordinates for the tiles then (since it don't just blit all of the tiles at the same place). The ChosenTile value is updated with the correct tile number. But in the end it just uses the last value in ChosenTile for all of the tiles...


tonyg(Posted 2008) [#4]
You'll really need to post some runnable or more complete code which shows the problem. It could be 101 possible things.


Nightsight(Posted 2008) [#5]
Will post something which run later...