2D cameras

Blitz3D Forums/Blitz3D Beginners Area/2D cameras

blade007(Posted 2008) [#1]
I had an idea to use GrabImage as a camera effect so I can make a sidescroller. The only problem is that for some reason, GrabImage only captures things in your field of sight :(

Is there anyway to fix this?


Matty(Posted 2008) [#2]
Just use a camera with an orthographic projection, why the need to use grabimage?


Ross C(Posted 2008) [#3]
Or, if you want a certain part of the screen to be 3d, use the cameraviewport command. Not sure what your after though, you'll need to explain further.


blade007(Posted 2008) [#4]
well im trying to make a side scroller, but the camera won't display past the screenboarder.

Graphics 800,600,32,2
SeedRnd MilliSecs()
SetBuffer BackBuffer()

Global fullscreen = CreateImage(GraphicsWidth(),GraphicsHeight())
Global camerax,cameray,cameravx,cameravy,cameramove

Type dot
	Field x,y
End Type

For loop = 1 To 50
	dot.dot = New dot
	dot\x = Rand(0,GraphicsWidth())
	dot\y = Rand(0,GraphicsHeight())
Next


While Not KeyDown(1)
;draw the screen borders
	Line 0,0,GraphicsWidth(),0
	Line 0,0,0,GraphicsHeight()
	Line GraphicsWidth()-1,0,GraphicsWidth()-1,GraphicsHeight()-1
	Line 0,GraphicsHeight()-1,GraphicsWidth()-1,GraphicsHeight()-1
	For dot.dot = Each dot
		Plot dot\x,dot\y
	Next
	
	x = x + MouseXSpeed()
	y = y + MouseYSpeed()
	
	If y < 0   Then y = 0
	If y > 600 Then y = 600
	If x < 0   Then x = 0
	If x > 800 Then x = 800	
	updatecamera(x,y)
	
	Flip
	Cls
Wend

Function updatecamera(x,y)
			GrabImage(fullscreen,camerax,cameray)
			Cls
			DrawImage(fullscreen,0,0)
			; move the camera to the player
			If x-400 > camerax+100 Then camerax = camerax + 2 : cameravx = cameravx + 1
			If y-500 > cameray+40 Then cameray = cameray + 2 : cameravy = cameravy + 1
			If x-400 < camerax-100 Then camerax = camerax - 2 : cameravx = cameravx - 1
			If y-500 < cameray-40 Then cameray = cameray - 2 : cameravy = cameravy - 1
			; jumps the camera if it is too far
			If x-400 > camerax+340 Then camerax = camerax + 4 : cameravx = cameravx + 3 
			If y-500 > cameray+140 Then cameray = cameray + 4 : cameravy = cameravy + 3
			If x-400 < camerax-340 Then camerax = camerax - 4 : cameravx = cameravx - 3
			If y-500 < cameray-140 Then cameray = cameray - 4 : cameravy = cameravy - 3
			
			If cameramove = False Then cameravx = 0 : cameravy = 0
			camerax = camerax + cameravx ;update the camera's velocity
			cameray = cameray + cameravy
			
			cameramove = False
End Function