Sprite generation MUST be after openscreen ?

Just starting out? Need help? Post your questions and find answers here.
plouf
Posts: 194
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Sprite generation MUST be after openscreen ?

Post by plouf »

Hi

during some test i notice that if you have create sprites BEFORE open a screem or windwoed screen, screen does not open at all
all sprite initializations must take place AFTER openscreen and then they work

if this is the case i believe it should be noted clearer in doc's
Christos
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Sprite generation MUST be after openscreen ?

Post by Peter »

Code or it didn't happen.
plouf
Posts: 194
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: Sprite generation MUST be after openscreen ?

Post by plouf »

if you mean about sample code, does it happens otherwise to ANYONE else ?!

anyway here is the sample from docs from "openwindowsscreen"
just change opnenwindowedscreen to the other commented area

Code: Select all

  OpenWindow(0, 20, 20, 840, 640, "A screen in a window...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
; OpenWindowedScreen(WindowID(0), 20, 20, 800, 600)  
  
  Procedure RenderFrame()
    Static x, y
    
    ClearScreen(RGB(0, 0, 0))
    
    x+1
    DisplaySprite(0, x, 30)
    
    FlipBuffers() ; continue the rendering
  EndProcedure
  
  ; Register the render event so FlipBuffers() will trigger the associated procedure
  BindEvent(#PB_Event_RenderFrame, @RenderFrame())
  
  CreateSprite(0, 64, 64)
  If StartDrawing(SpriteOutput(0))
    Circle(32, 32, 25, RGB(255, 0, 0)) ; Red circle
    StopDrawing()
  EndIf
  
OpenWindowedScreen(WindowID(0), 20, 20, 800, 600)  
  
  FlipBuffers() ; trigger the rendering
Christos
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Sprite generation MUST be after openscreen ?

Post by Peter »

plouf wrote:if you mean about sample code, does it happens otherwise to ANYONE else ?!
no, I meant that it is always easier for those who want to help if they have a code that can be used to trace the problem.

confirmed.

If there is no opened window screen, StopDrawing (stopDrawingCallback) throws an error because spider.screen.renderer is null.
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Sprite generation MUST be after openscreen ?

Post by Fred »

Yes, you need a screen, like in PureBasic
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Sprite generation MUST be after openscreen ?

Post by Peter »

Fred wrote:Yes, you need a screen, like in PureBasic
OK, I'm not very familiar with the Screen- and 2DDrawing- things, so I didn't know that.

But wouldn't it be a good idea to get a message if the screen was not initialised?
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Sprite generation MUST be after openscreen ?

Post by Fred »

Unfortunately, there is no runtime debugger yet in spiderbasic, so it's possible to do without doing it in the real command (which I would like to avoid)
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: Sprite generation MUST be after openscreen ?

Post by Peter »

Fred wrote:Unfortunately, there is no runtime debugger yet in spiderbasic, so it's possible to do without doing it in the real command (which I would like to avoid)
How about a debug output for JavaScript errors (as in this case)? I think that many SpiderBasic programmers don't know (or don't think about) that they should open the Developer Console when an error occurs that they can't explain.

Code: Select all

! window.onerror = function(message, source, lineno, colno, error) {
!   spider.debug.Print("JavaScript-Error!");
!   spider.debug.Print(message);
!   spider.debug.Print("(See developer console for more information)");
!   // spider.debug.Print(source);
!   // spider.debug.Print("Line: " + lineno + "; Col: " + colno);
!   // spider.debug.Print(error);
! }
plouf
Posts: 194
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: Sprite generation MUST be after openscreen ?

Post by plouf »

firstly MUST be mention in doc's this is crucial imho

then, i dont know if it possible, but cant the compiler during "compiling" have in mind that if it sees sprite commands before a openscreen throw a "warning" ?!?
Christos
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Sprite generation MUST be after openscreen ?

Post by Fred »

Good idea about the onerror(). I will update the doc as well.
Post Reply