It is currently Mon Dec 11, 2017 1:27 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Testing moving a circle
PostPosted: Sun Oct 15, 2017 2:42 am 
Offline
Addict
Addict
User avatar

Joined: Fri Apr 25, 2003 7:06 pm
Posts: 2212
Location: Argentina
I never do anything related to games before. I want to move the circle but something went wrong !

See and cry

Code:
#ScreenWidth  = 800  ; Feel free to change this to see the pixel filling speed !
#ScreenHeight = 600

If InitSprite() = 0 Or InitKeyboard()=0
  MessageRequester("Error","DirectX 7+ is needed.",0)
EndIf




If OpenScreen(#ScreenWidth, #ScreenHeight, 32, "")
 
  Repeat
   
    wave+6
    x+2
    If wave > 320 : wave = 0 : EndIf
   
    If StartDrawing(ScreenOutput())
          Circle(x, 100, 30, RGBA(100, 255, 100, 10))
      StopDrawing()
    EndIf
   
    ExamineKeyboard()
   
    FlipBuffers()
   
  Until KeyboardPushed(#PB_Key_Escape)
 
Else
  MessageRequester("Error","Can't open the screen !",0)
EndIf

End



Any help are apprecited.
Also i do not know how to use delay or something similar. I want to move the circle according to specific times AND also move it to the position where i put the mouse and give a click.
Also, alpha do nothing :P

Can anybody can give me a simple example please?

Thanks in advance !! :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Testing moving a circle
PostPosted: Sun Oct 15, 2017 4:49 am 
Offline
Addict
Addict
User avatar

Joined: Mon Oct 26, 2015 2:55 am
Posts: 890
Location: Ukraine
Just missed ClearScreen() ^^

Code:
#ScreenWidth  = 800  ; Feel free to change this to see the pixel filling speed !
#ScreenHeight = 600

If InitSprite() = 0 Or InitKeyboard()=0
  MessageRequester("Error","DirectX 7+ is needed.",0)
EndIf



If OpenScreen(#ScreenWidth, #ScreenHeight, 32, "")
 
  Repeat
    ; epilectic attack
    ClearScreen(RGB(Random(255), Random(255), Random(255)))
   
    wave+6
    x+2
    If wave > 320 : wave = 0 : EndIf
   
    If StartDrawing(ScreenOutput())
          Circle(x, 100, 30, RGBA(100, 255, 100, 10))
      StopDrawing()
    EndIf
   
    ExamineKeyboard()
   
    FlipBuffers()
   
  Until KeyboardPushed(#PB_Key_Escape)
 
Else
  MessageRequester("Error","Can't open the screen !",0)
EndIf

End

_________________
Time beyond time

Like a copyleft notify: all the source code created by me and posted on Purebasic official forums is free to use and modification in all possible (and several impossible) ways for anyone, without asking my permission


Top
 Profile  
Reply with quote  
 Post subject: Re: Testing moving a circle
PostPosted: Sun Oct 15, 2017 8:30 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 202
Location: Côtes d'Azur, France
Quote:
; Feel free to change this to see the pixel filling speed ! <== ???

Not sure what you want to achieve here... But this is my understanding of what you asked...

Code:
EnableExplicit
#ScreenWidth  = 800
#ScreenHeight = 600
#grey=$3C3c3c
Define x.i=0
Define y.i=100
Define timer.d=0
Define time_gap.d=200 ;every 200ms change circle coordonates
If InitSprite() = 0 Or InitKeyboard()=0 Or InitMouse()=0:MessageRequester("Error","DirectX 7+ is needed.",0):end:EndIf
If OpenScreen(#ScreenWidth, #ScreenHeight, 32, "")=0:MessageRequester("Error","Can't open the screen !",0):End:EndIf

Repeat
   FlipBuffers()
   ClearScreen(#grey)
   ExamineKeyboard()
   ExamineMouse()
   ;on left clic change x,y of the circle
   If MouseButton(#PB_MouseButton_Left):x=MouseX():y=MouseY():EndIf
   
   ;every 200ms increment circle x coordonate by 2
   If timer<ElapsedMilliseconds():x+2:timer=ElapsedMilliseconds()+time_gap:EndIf
   
   If StartDrawing(ScreenOutput())
      Circle(x, y, 30, RGBA(100, 255, 100, 10))
      Circle(MouseX(),MouseY(),2,RGBA(255,0,0,0)) ;display mouse position with a little red dot
      StopDrawing()
   EndIf

Until KeyboardPushed(#PB_Key_Escape)
End

_________________
There are 2 methods to program bugless.
But only the third works fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: Testing moving a circle
PostPosted: Sun Oct 15, 2017 7:47 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Apr 25, 2003 7:06 pm
Posts: 2212
Location: Argentina
Fig wrote:
Quote:
; Feel free to change this to see the pixel filling speed ! <== ???

Not sure what you want to achieve here... But this is my understanding of what you asked...

Code:
EnableExplicit
#ScreenWidth  = 800
#ScreenHeight = 600
#grey=$3C3c3c
Define x.i=0
Define y.i=100
Define timer.d=0
Define time_gap.d=200 ;every 200ms change circle coordonates
If InitSprite() = 0 Or InitKeyboard()=0 Or InitMouse()=0:MessageRequester("Error","DirectX 7+ is needed.",0):end:EndIf
If OpenScreen(#ScreenWidth, #ScreenHeight, 32, "")=0:MessageRequester("Error","Can't open the screen !",0):End:EndIf

Repeat
   FlipBuffers()
   ClearScreen(#grey)
   ExamineKeyboard()
   ExamineMouse()
   ;on left clic change x,y of the circle
   If MouseButton(#PB_MouseButton_Left):x=MouseX():y=MouseY():EndIf
   
   ;every 200ms increment circle x coordonate by 2
   If timer<ElapsedMilliseconds():x+2:timer=ElapsedMilliseconds()+time_gap:EndIf
   
   If StartDrawing(ScreenOutput())
      Circle(x, y, 30, RGBA(100, 255, 100, 10))
      Circle(MouseX(),MouseY(),2,RGBA(255,0,0,0)) ;display mouse position with a little red dot
      StopDrawing()
   EndIf

Until KeyboardPushed(#PB_Key_Escape)
End


Hi,

Thanks for your explanation and examples !!

One additional question. The moving circle is not nice. Is there a way to draw it with a best definition, etc or should i need to use a bitmap?

In case i need a bitmap, how to add it to this examples?

Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: Testing moving a circle
PostPosted: Sun Oct 15, 2017 8:06 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Apr 25, 2003 7:06 pm
Posts: 2212
Location: Argentina
If displaying a PNG with alpha, how to achieve it?

Or if drawing with RGBA how to get reults, in the example i don't see any result with RGBA


Last edited by ricardo on Sun Oct 15, 2017 8:29 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Testing moving a circle
PostPosted: Sun Oct 15, 2017 8:16 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 134
ricardo wrote:
If displaying a PNG with alpha, how to achieve it?

U can use Sprites -> Helpfile "2D Games"

Code:
;UsePNGImageDecoder()
;Sprite = CatchSprite(#PB_All,?BUFFER,#PB_Sprite_AlphaBlending)
;DisplayTransparentSprite(Sprite,X,Y)


Top
 Profile  
Reply with quote  
 Post subject: Re: Testing moving a circle
PostPosted: Mon Oct 16, 2017 1:52 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Apr 25, 2003 7:06 pm
Posts: 2212
Location: Argentina
Hi,

If i want to draw the circle with high quality? Because its not showing smooth, but with very noticeable square definition in the curves.


Top
 Profile  
Reply with quote  
 Post subject: Re: Testing moving a circle
PostPosted: Mon Oct 16, 2017 3:38 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 202
Location: Côtes d'Azur, France
I guess you are looking for antialiased circles. ̶P̶b̶ ̶d̶o̶e̶s̶n̶'̶t̶ ̶p̶r̶o̶v̶i̶d̶e̶ ̶t̶h̶a̶t̶ ̶k̶i̶n̶d̶ ̶o̶f̶ ̶c̶i̶r̶c̶l̶e̶ ̶b̶y̶ ̶d̶e̶f̶a̶u̶l̶t̶,̶ ̶s̶o̶r̶r̶y̶.̶
You can draw your own circle by using Bressenham algo but if you are a beginer, it's out of your reach for now.

If you want a better circle definition, increment your resolution to decent values. (800x600 is not enough)
1280x768 or even more if your screen can display it.

Code:
EnableExplicit
#ScreenWidth  = 1280
#ScreenHeight = 768
#grey=$3C3c3c
Define x.i=0
Define y.i=100
Define timer.d=0
Define time_gap.d=200 ;every 200ms change circle coordonates
Define alpha.a=128    ;alpha chanel
Define inc_alpha.b=1
Define i.i,larg.i
If InitSprite() = 0 Or InitKeyboard()=0 Or InitMouse()=0:MessageRequester("Error","DirectX 7+ is needed.",0):End:EndIf
If OpenScreen(#ScreenWidth, #ScreenHeight, 32, "")=0:MessageRequester("Error","Can't open the screen !",0):End:EndIf
;create a new sprite BACKGROUND
CreateSprite(0,#ScreenWidth,#ScreenHeight)
StartDrawing(SpriteOutput(0))
For i=1 To 100
   larg=Random(100,40)
   Box(Random(#ScreenHeight),Random(#ScreenWidth),larg,larg,Random($ffffff))
Next i     
StopDrawing()
;create a new sprite CIRCLE
CreateSprite(1,64,64)
StartDrawing(SpriteOutput(1))
Circle(32,32,31,RGB(100,255,100))
StopDrawing()
;create a new sprite MOUSE
CreateSprite(2,16,16)
StartDrawing(SpriteOutput(2))
Circle(8,8,7,RGB(255,0,0))
StopDrawing()

Repeat
   FlipBuffers()
   ClearScreen(#grey)
   ExamineKeyboard()
   ExamineMouse()
   ;on left clic change x,y of the circle
   If MouseButton(#PB_MouseButton_Left):x=MouseX():y=MouseY():EndIf
   
   ;every 200ms increment circle x coordonate by 2
   If timer<ElapsedMilliseconds():x+2:timer=ElapsedMilliseconds()+time_gap:EndIf
   ;display background
   DisplaySprite(0,0,0)
   ;display sprite Circle with alphachanel
   DisplayTransparentSprite(1,x,y,Alpha)
   Alpha+inc_alpha
   If alpha=255 Or alpha=0:inc_alpha=-inc_alpha:EndIf
   ;display mouse
   DisplayTransparentSprite(2,MouseX(),MouseY())
Until KeyboardPushed(#PB_Key_Escape)
End

_________________
There are 2 methods to program bugless.
But only the third works fine.


Last edited by Fig on Mon Oct 16, 2017 7:05 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Testing moving a circle
PostPosted: Mon Oct 16, 2017 4:17 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1464
Location: Uttoxeter, UK
Wouldn't the VectorDrawing Library produce a satisfactory anti aliased circle?

Code:
  If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 200)

    If StartVectorDrawing(CanvasVectorOutput(0))

      ; partial circle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      AddPathCircle(100, 100, 75)
      FillPath()
      ; partial circle with lines to the center
      MovePathCursor(300, 100)
      AddPathCircle(300, 100, 75, 0, 235, #PB_Path_Connected)
      ClosePath()
     
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(10)
   
      StopVectorDrawing()
    EndIf
   
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: Testing moving a circle
PostPosted: Mon Oct 16, 2017 6:59 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 202
Location: Côtes d'Azur, France
Nice :D

_________________
There are 2 methods to program bugless.
But only the third works fine.


Top
 Profile  
Reply with quote  
 Post subject: Re: Testing moving a circle
PostPosted: Thu Oct 19, 2017 4:56 pm 
Offline
Addict
Addict
User avatar

Joined: Fri Apr 25, 2003 7:06 pm
Posts: 2212
Location: Argentina
davido wrote:
Wouldn't the VectorDrawing Library produce a satisfactory anti aliased circle?

Code:
  If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 200)

    If StartVectorDrawing(CanvasVectorOutput(0))

      ; partial circle
      VectorSourceColor(RGBA(255, 0, 0, 255))
      AddPathCircle(100, 100, 75)
      FillPath()
      ; partial circle with lines to the center
      MovePathCursor(300, 100)
      AddPathCircle(300, 100, 75, 0, 235, #PB_Path_Connected)
      ClosePath()
     
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(10)
   
      StopVectorDrawing()
    EndIf
   
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf



But can be used in a game or animated 2D?


Top
 Profile  
Reply with quote  
 Post subject: Re: Testing moving a circle
PostPosted: Thu Oct 19, 2017 6:07 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1464
Location: Uttoxeter, UK
@ricardo ,
There have been some demos of 2d animation. Please take a look at the one below by eddy:
http://www.purebasic.fr/english/viewtopic.php?p=489402#p489402

I don't think that there is any hardware acceleration for the Vector Library so the animation may not be smooth enough for fast games.

_________________
DE AA EB


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye