How is this done?
Miscellaneous Forums/General Discussion/How is this done?
Ok, so you might remember my "Army Men II" thread awhile back. I decided to make a quick video showing how its played and how you can scroll across the entire level very quickly. I wanted to know this is all done since I doubt it uses tilemaps.
http://www.devdave.net/armymen2example.wmvThanks so much!
I believe it is buildt using tilemaps.
For small variations on terrain - small tiles containing variations on different themes.
For the ridges and shadows, big tiles - or tilegroups predefined in the editor.
Even Baldur's Gate used tilemaps, although they rendered one big image and cut it into many small ones.
This way you can cache in and out what you need at the moment to save memory and keep speed at a maximum.
Damn, I hate the concept of tilemaps and everything about them. I was hoping there was some other technique used here.
Whats wrong with tilemaps ?
You probably shouldn't hate them since you love the end result of using them.
I fail at understanding 2D. No matter how many code examples and tutorials I have looked at, tilemapping never made sense to me. I know the general idea on how it works, but the rest (like using arrays?) is too complex for my tiny brain.
I agree they feel ugly, but they can be the best choice...
For arrays, just think of it as a grid.
...And don't use PHP's arrays (wonderful though they are) as an example.
I still haven't quite gotten over them either, but when I create a multidimensional array like Tiles(16,64) I am actually doing something like plotting a grid which contains 1024 intersection points with 16x64 lines running along the sides.
When we reference a point on the array, like Tiles(10,50) we will get the tile at the intersection 10 tiles to the right and 50 tiles from the top.
I remember being mislead, while learning B3d, into believing that arrays were like Types in shorthand. They most definietly are not.
Hmm that actually makes sense Pickles. Actually I always had a clear idea of what arrays are since I first learned them in C++.
The biggest part that confuses me is how you scroll through the array according to your position.
Hi Dude! I know your pain when it comes to tilemaps. I pulled my hair out untill I figured out how they worked.
Here is a small tilemap editor to help you get started. Press space bar to change the tile. Left mouse button to place a tile.
'########################################
'### TileMap Editor Example for IKG #
'### Author - Amon #
'### Version 0.3 #
'### Date 21st/August/2006 #
'########################################
SuperStrict
Graphics 800,600,32,60
Global tiles:TImage = LoadAnimImage("tileset.png",32,32,0,7)
Global TileSize:Int = 32 ' The size of our tiles
Global MapWidth:Int = 800/TileSize 'The width of our Map Array. Divide the screenwidth by the tileSize to get max tiles on screens width
Global MapHeight:Int = 600/TileSize ' Same as Above but divide by Screen Height
Global MapArray:Int[MapWidth,MapHeight] 'Setup our TileMAp Array which holds the tiles.
Global MX:Int, MY:Int ' MouseX & MouseY
Global CurrentTile:Int = 0 ' Holds the current tile number
For Local xiter:Int = 0 To MapWidth-1
For Local yiter:Int = 0 To MapHeight-1
MapArray[xiter,yiter] = 0 ' fill our Map Array with a number to respresent a blank tile. I would have the first tile in the anim
Next ' as just a black square.
Next
While Not KeyHit(KEY_ESCAPE)
Cls
MX = MouseX()/TileSize*TileSize ' Doing this simple math (Dividing the mouse X&Y position by the size of our tile (32 and then
MY = MouseY()/TileSize*TileSize ' Multiplying again gives you a grid like movement for the mouse position.
ChangeTile()
PlaceTile()
DrawMap()
DrawImage tiles,MX,MY,CurrentTile
Flip
Wend
'#######################################
'# DrawMap Function #
'# Returns = None #
'# Draws our map to screen #
'#######################################
Function DrawMap()
For Local x:Int = 0 To MapWidth-1
For Local y:Int = 0 To MapHeight-1
DrawImage tiles,x*TileSize,y*TileSize,MapArray[x,y]
Next
Next
End Function
'######################################
'#Place Tile Function #
'#Returns = none #
'#Places our tiles on screen #
'######################################
Function PlaceTile()
If MouseDown(MOUSE_LEFT)
MapArray[ MouseX()/TileSize , MouseY()/TileSize ] = CurrentTile 'If you notice we are dividing the mouse positions by the
'tilesize INSIDE the map array. This gives us the correct
EndIf 'location within the array to place the tile.
End Function
'######################################
'#Change the current Tile #
'#Returns = None #
'#Changes the current tile #
'######################################
Function ChangeTile()
If KeyHit(KEY_SPACE)
CurrentTile:+1
EndIf
If CurrentTile >6 Then CurrentTile = 0
End Function
And the image to go with it is below.

Let me know if you have any problems or need something explained. :)
Wow, this looks great but a bit different then what I'm looking for. This is for making an editor. I need to learn how to make a game with a tilemap already made from an editor. Scrolling while moving, etc...
I'll still take a closer look over this tomorrow. Thanks.
Gman has a module (with full source) for Loading Mappy map.
http://www.gprogs.com/forum/viewforum.php?id=9And the Editor
http://www.tilemap.co.uk
I'm not sure whether this will actually help - I'm sure there must be a better way!! :)
When you place your character he stays in the middle of the screen and the background moves.
Graphics 800,600
SetBuffer BackBuffer()
;maptest.bmp simply has 2 tiles 64x64 - they're different to
;show their movement
Global world=LoadAnimImage("maptest.bmp",64,64,0,2)
; a tilemap of 20x20 has 400 elements
Dim mapx(400),mapy(400),mapimg(400)
;load the images to be a checkerboard effect
aa=0 : bb=0 : cc=0
For ll=0 To 19
bb=cc
For kk=0 To 19
mapimg(aa)=bb
aa=aa+1
bb=bb+1
If bb=2 Then bb=0
Next
cc=cc+1
If cc=2 Then cc=0
Next
;load the positions of the tiles into the grid
;so you start in the middle of the grid
xx=-192 : yy=-320 : aa=0
For ll=0 To 19
For kk=0 To 19
mapx(aa)=xx
mapy(aa)=yy
xx=xx+64
aa=aa+1
Next
xx=-192 : yy=yy+64
Next
Repeat
Cls
For ll=0 To 399
DrawBlock world,mapx(ll),mapy(ll),mapimg(ll)
Next
;scroll up
If KeyDown(208) Then
For ll=0 To 399
mapy(ll)=mapy(ll)-1
Next
EndIf
;scroll down
If KeyDown(200) Then
For ll=0 To 399
mapy(ll)=mapy(ll)+1
Next
EndIf
;scroll right
If KeyDown(203) Then
For ll=0 To 399
mapx(ll)=mapx(ll)+1
Next
EndIf
;scroll left
If KeyDown(205) Then
For ll=0 To 399
mapx(ll)=mapx(ll)-1
Next
EndIf
Flip
Until KeyDown(1)
End
Regards
um.. why move every tile? use the SetOrigin(x,y) command. That way you just load your tiles at their normal x/y coordinates. Then you can simply have a character that moves only their cooridnates.
psuedo code is something like
global player:MyPlayer = new MyPlayer
loadTiles()
while (running)
cls
update()
flip
wend
function loadTiles()
'load tiles how ever you want to load them.
' just set their corresponding x/y coordinates
' tip: it'd make it easier if you made a Tile an actual custom Type with x/y fields.
end function
function update()
xMove = 0
yMove = 0
' just listen for up and right arrow key hits
if keyhit(KEY_UP) then
yMove = - 5
end if
if keyhit(KEY_RIGHT) then
xMove = 5
end if
' move the player in that direction
player.move(xmove, ymove)
' now move the drawing origin in the opposite of that direction
' so you can still see the player, but the entire world/tiles
' will shift.
xorigin:int = 0
yorigin:int = 0
getOrigin(xorigin, yorigin)
xorigin:- xMove
yorigin:- yMove
setOrigin(xorigin,yorigin)
end function
type MyPlayer
field xPosition
field yPosition
method move(x,y)
xPosition:+ x
yPosition:+ y
end method
end type
the advantage? you don't have a nasty for loop moving every object in your game world by some small amount of pixels. With this method you have something of a very basic 2D 'camera' of sorts that you cam move around with setOrigin().
Thanks for that. It must be me but I didn't realise that Blitz 3D actually has a setOrigin() command. I can't find any mention of it in the docs. I certainly agree it's a much better method - but then I did say that I was sure there had to be a better way!! :)
Regards
Think I've found it - I assume it's the origin command in B3d - is it called setOrigin() in Blitzmax?
Regards
yes, I was mistaken. I misread your post thinking you were using blitzmax. setOrigin() is a blitzMax and blitzPlus command. But I imagine you could do the same with blitz3D for 2D purposes :).
I'm using BlitzMax.
hmmm is it tooo late to say WRONG FORUM?
Look at how the thread started out pal. My original intention was to just ask about the techniques used in the game.