Hey guys,
Since I don't have enough experience (yet) with PB maybe somebody can help me:
Is it possible to draw a line with 1 sprite ?
Let me explain, with an example:
I have a square sprite (128x128).
I clip it in 128 sprites of each: 1px height & 128px width
Now I would like to draw a line with each sprite from X1,Y1 to X2,Y2
Is that possible or has somebody tried this ?
All help is welcome.
Regards,
DeXtr0
How to draw a line with a sprite
How to draw a line with a sprite
Proud member of dAWN (www.dawncreations.com)
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
Hello,
I made a little example for you.
Maybe its not the best solution. But it shows the principle.
Best regards
Wolf
I made a little example for you.
Maybe its not the best solution. But it shows the principle.
Code: Select all
; English forum:
; Author: Hroudtwolf
; Date: 25. November 2007
; OS: Windows, Linux, Mac
; Demo: Yes
Macro DoOrDie (_DO_ , _DIEWITH_)
If Not (_DO_)
MessageRequester ("Error" , _DIEWITH_)
End
EndIf
EndMacro
Declare DrawSpriteLine (lX1.l , lY1.l , lX2.l , lY2.l)
Define.l lEvent
Define.l lWndID
Define.POINT CornerX
DoOrDie (InitSprite () , "Couldn't initiate DirecX.")
lWndID = OpenWindow (#PB_Any , #PB_Ignore , #PB_Ignore , 800 , 600 , "Line with sprites example" , $CA0001)
DoOrDie (lWndID , "Not enough RAM available.")
DoOrDie (OpenWindowedScreen (WindowID (lWndID) , 0 , 0 , 800 , 600 , #False , 0 , 0) , "DirectX fullscreen not possible.")
Repeat
Repeat
lEvent = WindowEvent ()
Select lEvent
Case #PB_Event_CloseWindow
End
EndSelect
Until lEvent = #Null
ClearScreen ($590201)
DrawSpriteLine (100, 100 , 500 , 500)
DrawSpriteLine (600, 100 , 100 , 500)
FlipBuffers ()
Delay (1)
ForEver
Procedure DrawSpriteLine (lX1.l , lY1.l , lX2.l , lY2.l)
Protected lLineX .l = lX1
Protected lLineY .l = lY1
Protected lOpX .l = 0
Protected lOpY .l = 0
Static lDrawSpriteLine_SpriteID.l
If Not lDrawSpriteLine_SpriteID
lDrawSpriteLine_SpriteID = CreateSprite (#PB_Any , 2 , 2)
If StartDrawing (SpriteOutput (lDrawSpriteLine_SpriteID))
Box (0 , 0 , 2 , 2 , $FFFFFF)
StopDrawing ()
EndIf
EndIf
If lLineX > lX2 : lOpX = -1 : ElseIf lLineX < lX2 : lOpX = 1 : EndIf
If lLineY > lY2 : lOpY = -1 : ElseIf lLineY < lY2 : lOpY = 1 : EndIf
While lLineX <> lX2 And lLineY <> lY2
DisplaySprite (lDrawSpriteLine_SpriteID , lLineX , lLineY)
If Not (lLineX = lX2) : lLineX + lOpX : EndIf
If Not (lLineY = lY2) : lLineY + lOpY : EndIf
Wend
ProcedureReturn #Null
EndProcedure
Wolf
Whohooo cool Wolf,
Thanks you very much !
I'll check it out !
Regards,
DeX
Thanks you very much !
I'll check it out !
Regards,
DeX
Proud member of dAWN (www.dawncreations.com)