I am drawing a selection box for a simple start of a strategy game now I have read through quite a few posts and documentation, and this is the solution I came up with:
Code: Select all
;IncludeFile "Init.pb"
IncludeFile "Screen3DRequester.pb"
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ClearColor = RGB(0,0,0) ;Our ClearScreen Color
bX = 0
bY = 0
bX0 = 0
bX1 = 0
bX2 = 0
bY0 = 0
bY1 = 0
bY2 = 0
SelFlag = 0
Screen3DRequester()
UsePNGImageDecoder()
;UseJPEGImageDecoder()
LoadSprite(0,"swordcursor2.png",#PB_Sprite_AlphaBlending)
CreateSprite(1,1024,768)
;LoadSprite(1,"media/back1.jpg")
ExitCondition.b = 0
While ExitCondition = 0
ClearScreen(ClearColor)
FPS = Engine3DFrameRate(#PB_Engine3D_Current)
ExamineMouse()
mX = MouseX()
mY = MouseY()
mC = MouseButton(#PB_MouseButton_Left)
CreateCamera(0, 0, 0, 100, 100)
CameraLookAt(0, 0, 0, 0)
RenderWorld()
DisplayTransparentSprite(0,mX,mY)
If mC = 0
SelFlag = 0
EndIf
If mC And SelFlag = 0
SelFlag = 1
bX = mX
bY = mY
EndIf
If mC And SelFlag = 1
bX2 = mX
bY2 = mY
If bX < bX2
bX0 = bX
bX1 = bX2
Else
bX0 = bX2
bX1 = bX
EndIf
If bY < bY2
bY0 = bY
bY1 = bY2
Else
bY0 = bY2
bY1 = bY
EndIf
;CreateSprite(1,1024,768) ;Drawing box quicker
StartDrawing(SpriteOutput(1)) ;|
Box(0,0,1024,768,ClearColor) ;|
DrawText(0,0,"FPS: "+Str(FPS)) ;|
LineXY(bX0,bY0,bX1,bY0,RGB(255,0,0)) ;|
LineXY(bX0,bY1,bX1,bY1,RGB(255,0,0)) ;|
LineXY(bX0,bY0,bX0,bY1,RGB(255,0,0)) ;|
LineXY(bX1,bY0,bX1,bY1,RGB(255,0,0)) ;|
StopDrawing() ;|
DisplaySprite(1,0,0) ;|
DisplayTransparentSprite(0,mX,mY) ;|
;|
;ElseIf IsSprite(1) |
;FreeSprite(1) ;<-------|
EndIf
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape)
ExitCondition = 1
EndIf
FlipBuffers()
Wend
End
If not, all is well, will keep reading through the forums and PB code archive.
Thanks.