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.

You're doing a lot wrong. I'm not even sure what you intended with that bit that gets activated when you press a key.

Here is the simplest 2d scrolling system I could muster up for you.

Graphics 800,600,32
SetBuffer BackBuffer()

Type Sprite 
	Field Image 
	Field XPos
	Field YPos
End Type

Dim Image(20)


; Create 20 random images to use for sprites cause we don't have any bitmaps to load.
For Loop = 0 To 19

	Image(Loop) = CreateImage(32, 32)
	
	SetBuffer ImageBuffer(Image(Loop))
	Color Rand(0,255), Rand(0,255), Rand(0,255)
	
	Shape = Rand(0, 1)

	Select Shape

		Case 0 
			Rect 0, 0, 32, 32, Rand(0, 1)

		Case 1
			Oval 0, 0, 32, 32, Rand(0, 1)

	End Select

Next


; Reset the graphics to draw to the backbuffer.  
; Don't need to do this if you load the images instead of create them manually.
SetBuffer BackBuffer()


; Create 2000 random sprites in the world.  
For Loop = 1 To 2000
	
	; Add a new sprite to the list of sprites.
	ThisSprite.Sprite = New Sprite
	
	; Pick a random image for this sprite.
	ThisSprite\Image = Image(Rand(0, 19))

	; Place the sprite at a random location in world space.
	ThisSprite\XPos = Rand(0, 10000)
	ThisSprite\YPos = Rand(0, 10000)
	
Next


; Set the initial position of the "camera".
Screen_X = 5000
Screen_Y = 5000


While Not KeyDown(1)

	Cls 

	; Use arrow keys to "scroll".	
	If KeyDown(203) Then Screen_X = Screen_X - 1
	If KeyDown(205) Then Screen_X = Screen_X + 1
	If KeyDown(200) Then Screen_Y = Screen_Y - 1
	If KeyDown(208) Then Screen_Y = Screen_Y + 1

	; Draw all objects in the world.
	For ThisSprite.Sprite = Each Sprite
		DrawImage ThisSprite\Image, ThisSprite\XPos-Screen_X, ThisSprite\YPos-Screen_Y
	Next
	
	Flip 

Wend