Button? zomg o rly? ya rly! :O

Blitz3D Forums/Blitz3D Beginners Area/Button? zomg o rly? ya rly! :O

does anyone know how you could click on an entity,picture,sprite, etc., to do an action?
txs

For 2d pictures, check to see if the mouse is greater than the x and y position and less than the x+width and y+height. Then if the mouse is within those boundaries, check to see if the mouse button is hit/down.

im trying to put a button into a 3d environment
unless you can make one area 2d and another 3d (which i doubt)

use CameraViewport to move the viewport somewhere else on the screen and put the 2d in the part where the camera is not at...

Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()

cam = CreateCamera()
MoveEntity cam, 0, 0, -15

;create sprite
sp = CreateSprite()
Color 64, 0, 0
Rect 0, 0, 64, 64
Color 255, 255, 255
Text 32, 16, "sprite", 1, 1
Text 32, 32, "TEST", 1, 1
tex = CreateTexture(64, 64)
CopyRect 0, 0, 64, 64, 0, 0, BackBuffer(), TextureBuffer(tex)
EntityTexture sp, tex
EntityBox sp, -1, -1, -1, 2, 2, 2
EntityPickMode sp, 3

;create image
img = CreateImage(64, 64)
Color 0, 64, 0
Rect 0, 0, 64, 64
Color 255, 255, 255
Text 32, 16, "image", 1, 1
Text 32, 32, "TEST2", 1, 1
GrabImage img, 0, 0

cube = CreateCube()
MoveEntity cube, 4, 4, 0
EntityPickMode cube, 2

Repeat

	RenderWorld()
	DrawBlock img, 100, 100

	If MouseDown(1)

		;check if sprite is clicked	
		CameraPick cam, MouseX(), MouseY()
		If PickedEntity() = sp Then
			Text 400, 50, "sprite!", 1, 1
		End If
		
		;check if cube is clicked
		If PickedEntity() = cube Then
			Text 400, 50, "cube!", 1, 1
		End If
		
		;check if image is clicked
		If RectsOverlap(MouseX(), MouseY(), 1, 1, 100, 100, 64, 64) Then
			Text 400, 50, "image!", 1, 1
		End If
			
	End If

	Flip
	
Until KeyHit(1)

End


hmm...i still dont understand how it works. why is it when i take out
;check if sprite is clicked
CameraPick cam, MouseX(), MouseY()
If PickedEntity() = sp Then
Text 400, 50, "sprite!", 1, 1
End If
the image still works?
i would understand if none of them worked, but the fact that the image is working and the cube isnt even though i didnt touch the cube blows me away

nvm, i figured it out! thx 4 the help!

...or maybe not.
i was trying to change the name cube to door, and make you click on a door to open it instead, but it wont work now (the door is made out of blitz3d)

is it sposed to do that?

Well, if I change 'cube' to 'door', it still works, so that can't be the problem:
Graphics3D 800, 600, 0, 2
SetBuffer BackBuffer()

cam = CreateCamera()
MoveEntity cam, 0, 0, -15

;create sprite
sp = CreateSprite()
Color 64, 0, 0
Rect 0, 0, 64, 64
Color 255, 255, 255
Text 32, 16, "sprite", 1, 1
Text 32, 32, "TEST", 1, 1
tex = CreateTexture(64, 64)
CopyRect 0, 0, 64, 64, 0, 0, BackBuffer(), TextureBuffer(tex)
EntityTexture sp, tex
EntityBox sp, -1, -1, -1, 2, 2, 2
EntityPickMode sp, 3

;create image
img = CreateImage(64, 64)
Color 0, 64, 0
Rect 0, 0, 64, 64
Color 255, 255, 255
Text 32, 16, "image", 1, 1
Text 32, 32, "TEST2", 1, 1
GrabImage img, 0, 0

door = CreateCube()
MoveEntity door, 4, 4, 0
EntityPickMode door, 2

Repeat

	RenderWorld()
	DrawBlock img, 100, 100

	If MouseDown(1)

		;check if sprite is clicked	
		CameraPick cam, MouseX(), MouseY()
		If PickedEntity() = sp Then
			Text 400, 50, "sprite!", 1, 1
		End If
		
		;check if cube is clicked
		If PickedEntity() = door Then
			Text 400, 50, "door!", 1, 1
		End If
		
		;check if image is clicked
		If RectsOverlap(MouseX(), MouseY(), 1, 1, 100, 100, 64, 64) Then
			Text 400, 50, "image!", 1, 1
		End If
			
	End If

	Flip
	
Until KeyHit(1)

End

So it would be something else.. maybe the object has children ? In that case, use this function to change the pickmode:
Function SetEntityPickMode(ent, pm)

	EntityPickMode ent, pm
	
	For i = 1 To CountChildren(ent)
		g = GetChild(ent, i)
		SetEntityPickMode g, pm
	Next
	
End Function

usage: SetEntityPickMode door, 2 instead of EntityPickMode door, 2