How do I get 3D in front of 2D?

Blitz3D Forums/Blitz3D Programming/How do I get 3D in front of 2D?

AlexZ(Posted 2003) [#1]
Here is what I want to do:

1st Layer, 3D - Life bars, score, etc
2nd Layer, 2D - Characters
3rd Layer, 3D - Background stuff

I want to make a side scroller. Anyways, how do I set this up? I can't get the first layer to appear on top of the second, 2D always appears in front of any 3D graphics. Is this possible? Thank you.


jhocking(Posted 2003) [#2]
Don't use 2D commands like DrawImage for the 2D characters. Instead draw 2D images in the 3D scene. You can use sprite but I suggest something like Sprite Control (if you can't find that by searching the forums hopefully someone can link to it.)


Jeppe Nielsen(Posted 2003) [#3]
use:

CameraClsMode camera,0,1

And remember to have a Cls at the start of your loop, to clear the screen, as RenderWorld wont do that now.


AlexZ(Posted 2003) [#4]
Here is a code that I have. Now, I want the sprite box to be rendered between the red sphere and yellow cube. Red Sphere is closer to the camera, then the sprite in the middle, then the yellow box. Can someone look at the code, and update it to make that work? Thanks.

I do want to use Blitz2D commands though.

P.S. Use arrow keys to move the sprite between the 3d objects.

Graphics3D 800,600,32

gvCamera = CreateCamera()
gvIsDone = 0



lvCube = CreateCube()
EntityColor lvCube,255,255,0
MoveEntity lvCube,1,0,8
EntityFX lvCube,1

lvSphere = CreateSphere()
EntityColor lvSphere,128,0,64
MoveEntity lvSphere,-1,0,4
EntityFX lvSphere,1

lvTexture = CreateTexture(64,64)
SeedRnd MilliSecs()
SetBuffer TextureBuffer(lvTexture)
For x=0 To 63
	For y=0 To 63
		Color Rand(0,255),Rand(0,255),Rand(0,255)
		Plot x,y
	Next
Next

lvSprite = CreateImage(50,50)
SetBuffer ImageBuffer(lvSprite)
For x=0 To 49
	For y=0 To 49
		Color Rand(0,100),Rand(0,255),Rand(0,255)
		Plot x,y
	Next
Next

EntityTexture lvCube,lvTexture
EntityTexture lvSphere,lvTexture


imgX = 0
imgY = 300

CameraClsMode gvCamera,0,1

SetBuffer BackBuffer()
While gvIsDone = 0

	Cls

	DrawImage lvSprite,imgX,imgY


	UpdateWorld
	RenderWorld


	TurnEntity lvCube,0,0.1,0
	TurnEntity lvSphere,0,-0.1,0
		

	If KeyDown(205) Then imgX = imgX + 2
	If KeyDown(203) Then imgX = imgX - 2
	
	If KeyHit(1) Then gvIsDone = 1
	Flip
Wend



Difference(Posted 2003) [#5]
While gvIsDone = 0

	TurnEntity lvCube,0,0.1,0
	TurnEntity lvSphere,0,-0.1,0

	
	HideEntity lvSphere
	ShowEntity lvCube
	

	UpdateWorld
	
	CameraClsMode gvCamera,True,True
	RenderWorld


	DrawImage lvSprite,imgX,imgY


	HideEntity lvCube
	ShowEntity lvSphere

	CameraClsMode gvCamera,False,True
	RenderWorld
		

	If KeyDown(205) Then imgX = imgX + 2
	If KeyDown(203) Then imgX = imgX - 2
	
	If KeyHit(1) Then gvIsDone = 1
	Flip
Wend



Billamu(Posted 2003) [#6]
If you turn the image into a 3d sprite you can apply Entityorder to it.


AlexZ(Posted 2003) [#7]
Peter, many many thanks. =)