How is this done?

Miscellaneous Forums/General Discussion/How is this done?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

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().