Help me, about 2D x,y

Blitz3D Forums/Blitz3D Beginners Area/Help me, about 2D x,y

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.

In a nutshell then, Kaisuo, what you need is OFFSET coordinates. An OFFSET is a value which will alter the co-ordinates of an object in order to draw it onscreen. So, taking your example, if you had an object at 5000, 5000 you would offset that by subtracting the offset values from the x and y co-ordinates. Here is a more practical example:
; Define our objects

Global OFFSET_X = 0		; Set to zero (it is by default anyway)
Global OFFSET_Y = 0

Global MAN_X = 5000		; Set the co-ordinates of our character
Global MAN_Y = 5000

Repeat
	If KeyDown(KEY_UP) MAN_Y = MAN_Y - SPEED
	If KeyDown(KEY_DOWN) MAN_Y = MAN_Y + SPEED
	If KeyDown(KEY_LEFT) MAN_X = MAN_X - SPEED
	If KeyDown(KEY_RIGHT) MAN_X = MAN_X + SPEED

	; Draw the area of the background which is onscreen
	DrawBlockRect mybackground, 0, 0, OFFSET_X, OFFSET_Y, GraphicsWidth(), GraphicsHeight()

	; If the character is onscreen then draw him

	TEST_X = MAN_X - OFFSET_X
	If TEST_X < GraphicsWidth() And TEST_X > -ImageWidth( MAN_IMAGE )
		TEST_Y = MAN_Y - OFFSET_Y
		If TEST_Y < GraphicsHeight() And TEST_Y > -ImageHeight(MAN_IMAGE)
			DrawImage MAN_IMAGE, TEST_X, TEST_Y
		EndIf
	EndIf

	Flip

Until KeyHit(1)
Notice that the values OFFSET_X are subtracted from the characters X and Y coordinates when checking to see if he is onscreen. In this example, the cursor keys would move the character but not scroll the map. To achieve this, you could set the keys to change the OFFSET_X and OFFSET_Y values instead.