It is currently Tue Dec 10, 2019 9:02 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Pure Basic FPS
PostPosted: Sun Oct 13, 2019 10:36 am 
Offline
User
User

Joined: Sat Apr 13, 2019 12:17 pm
Posts: 45
Hi this may seem like a stupid question but how do you change the fps in pure basic .


Top
 Profile  
Reply with quote  
 Post subject: Re: Pure Basic FPS
PostPosted: Sun Oct 13, 2019 11:04 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2053
Location: Germany
There is the function SetFrameRate(...), but this burns the CPU power.

It is best to calculate the waiting time between the frames yourself

Update: Sub one millisecond for own calculation... better result
Code:

Procedure FrameDelay(Frames)
  Static last_time
  Protected time, max_time, diff_time
 
  max_time = 1000 / Frames
  time = ElapsedMilliseconds()
  diff_time = max_time - time + last_time - 1
  last_time = time
  If diff_time > 0 And diff_time <= max_time
    Delay(diff_time)
  EndIf

EndProcedure

If InitSprite() = 0
  MessageRequester("Error", "Can't open screen & sprite environment!", 0)
  End
EndIf

If OpenWindow(0, 0, 0, 220, 160, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(0, 170, 135, 45, 20, "Quit")
 
  If OpenWindowedScreen(WindowID(0), 0, 0, 160, 160)
  ;If OpenWindowedScreen(WindowID(0), 0, 0, 160, 160, 0, 0, 0, #PB_Screen_NoSynchronization)
    CreateSprite(0, 20, 20)
    If StartDrawing(SpriteOutput(0))
      Box(0, 0, 20, 20, RGB(255, 0, 155))
      Box(5, 5, 10, 10, RGB(155, 0, 255))
      StopDrawing()
    EndIf
  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
    End
  EndIf
EndIf

;SetFrameRate(30)

direction = 2
Repeat
  ; It's very important to process all the events remaining in the queue at each frame
  ;
  Repeat
    Event = WindowEvent()
   
    Select Event
      Case #PB_Event_Gadget
        If EventGadget() = 0
          End
        EndIf
       
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until Event = 0
 
  FlipBuffers()
  ClearScreen(RGB(0, 0, 0))
  DisplaySprite(0, x, x)
  x + direction
  If x > 140 : direction = -2 : EndIf
  If x < 0   : direction =  2 : EndIf
  FrameDelay(20)
ForEver

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Last edited by mk-soft on Sun Oct 13, 2019 11:47 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Pure Basic FPS
PostPosted: Sun Oct 13, 2019 11:10 am 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4449
Location: Germany
Hm ... difficult to say.

If you use the screen procedure with #PB_Screen_WaitSynchronization, FlipBuffer() synchronizes with the
screen refreshrate. You can select this with the choosen video mode (see refreshrate at OpenScreen()).

But if your calculations took longer than one refresh time (or you use a Delay()) then you skip frames of the screenresolution.

If you want higher refreshrates, you can use #PB_Screen_NoSynchronization, but this can/will result in flickering.

SetFramneRate is only possible for a WindowedScreen, since there is no refreshrate of the video mode.


Top
 Profile  
Reply with quote  
 Post subject: Re: Pure Basic FPS
PostPosted: Sun Oct 13, 2019 1:01 pm 
Offline
User
User

Joined: Sat Apr 13, 2019 12:17 pm
Posts: 45
Thanks for the info I think I read that the framerate is set initially to 60 fps . I am using a slow computer and just wanted to see what it was doing . typically when using 3D in AGK2 I get about 20 fps and was wanting to know what It was doing with Pure Basic . What I had been doing was setting it to 20 fps second so the programs I write on a slower machine run at the same speed as a much faster machine if that makes sense. Thanks for reading .


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 22 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