Page 1 of 1

Windowed Screen Problems

Posted: Fri Mar 18, 2005 5:46 pm
by ShadowRunnaX
This is probably something stupid, but when I used a windowed screen for my 2D game, my mouse used to always stay on loading. I appear to have somehow overcome that problem, but now, whenever you press the keys, it doesnt do anything unless the mouse is being moved. Is this some weird bug or am I just very noobalicious?

Re: Windowed Screen Problems

Posted: Fri Mar 18, 2005 11:10 pm
by PB
Show us a working example so we can see what's happening. :)

Posted: Fri Mar 18, 2005 11:29 pm
by Paul
Sounds like you are missing the Delay() which is required for windowed screens in the event loop using WindowEvent().

There is a tutorial here for setting up a game using Windowed or Full Screen in PB...
http://www.reelmedia.org/pp/archive411/ ... reens.html

Posted: Sun Mar 20, 2005 8:11 pm
by ShadowRunnaX
Thanks for the response, but adding a delay did not actually solve my problem. I apologise if I'm being a pest, but I wanted to know how it worked in the Spartan RPG Engine which does not use any delays. Or maybe I'm just missing something else. I'll keep trying with the delay if I cannot find any alternate solution.

Posted: Sun Mar 20, 2005 8:54 pm
by Paul
As PB said, post your code which causes the problem and we can show you your mistake. ;)

Posted: Sun Mar 20, 2005 9:09 pm
by Fred
May be ReleaseMouse() could be a solution ?

Posted: Mon Mar 21, 2005 2:53 pm
by ShadowRunnaX
No, already tried the both. I didn't clean up the code, but here it is anyway:-

Code: Select all

If InitKeyboard() = 0 Or InitSprite() = 0
  MessageRequester("Error", "DirectX 7 unloadable", 0)
  End
EndIf

InitMouse()

XIncludeFile "project b map.pb"

Dim ground(58,40)
Dim move(58,40)
Dim drawnextscreen(30,20)
Dim movenextscreen(30,20)

OpenWindow(0,300,300,640,480, #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget, "Something")

OpenWindowedScreen(WindowID(),10,10,600, 480, 1,10,10)

  posx = 100
  posy = 100
  objx = -100
  objy = -100
  
speed=1
right=2
left=10
up=18
down=26

For l=1 To 33
LoadSprite(l,"data/sprites/"+Str(l)+".bmp")
Next
  
      For t= 1 To 33
    TransparentSpriteColor(t,255,255,255)
    Next

LoadSprite(38,"groundL.bmp",0)
LoadSprite(39,"groundR.bmp",0)
LoadSprite(40,"groundU.bmp",0)
LoadSprite(41,"groundD.bmp",0)
LoadSprite(42,"groundUL.bmp",0)
LoadSprite(43,"groundUR.bmp",0)
LoadSprite(44,"groundDL.bmp",0)
LoadSprite(45,"groundDR.bmp",0)

LoadSprite(35,"ground2.bmp",0)
LoadSprite(37,"grass.bmp",0)

For t=1 To 9
LoadSprite(t+47,"mudgrass"+Str(t)+".bmp",0)
Next t

For t=1 To 4
LoadSprite(56+t,"tree"+Str(t)+".bmp",0)
TransparentSpriteColor(56+t,255,0,255)
Next t

LoadSprite(61,"data/box.bmp",0)
TransparentSpriteColor(61,255,0,255)

LoadSprite(46,"data/house1.bmp",0)
LoadSprite(47,"data/house2.bmp",0)

beginning:

a=1

Restore level1
For y=1 To 40
For x=1 To 58
Read ground(x,y)    
Next
Next

For ay=1 To 40
For ax=1 To 58
Read move(ax,ay)
Next
Next

For y=1 To 20
For x=1 To 30
Read drawnextscreen(x,y)    
Next
Next

For ay=1 To 20
For ax=1 To 30
Read movenextscreen(ax,ay)
Next
Next

SetFrameRate(60)
SetRefreshRate(60)

ReleaseMouse(1)

  Repeat
  
  WindowEvent()
        
  Delay(1)
       
    ExamineScreenModes()

    ExamineKeyboard()
    
    If KeyboardPushed(#PB_Key_Left):move=1
    ElseIf KeyboardPushed(#PB_Key_Right):move=2 
    ElseIf KeyboardPushed(#PB_Key_Up):move=3
    ElseIf KeyboardPushed(#PB_Key_Down):move=4
    ElseIf KeyboardPushed(#PB_Key_D):move=5
    EndIf
    If KeyboardPushed(#PB_Key_Leftshift) Or KeyboardPushed(#PB_Key_RightShift):speed=2:Else:speed=1:EndIf
    
    If KeyboardReleased(#PB_Key_Escape)  :  Quit=1  :  EndIf
        
    Select move
    
    Case 0
    a=1
    
    Case 1
    If check<>1 And check<>6 And check<>7
    xco-8
    If posx<180
    objx=objx+8*speed
    Else
    posx-8*speed
    EndIf
    EndIf
    left=left+1
    Delay(100/speed)
    If left>17 : left=10 : EndIf

    a=left
    move=0
    
    Case 2
    If check<>2 And check<>5 And check<>8 And check<>10
    xco+8
    If posx>300
    objx=objx-8*speed
    Else
    posx+8*speed
    EndIf
    Else
    EndIf
    If check=10
    Goto nextscreen
    EndIf
    right=right+1
    Delay(100/speed)
    If right>9 : right=2 : EndIf

    a=right
    move=0
    
    Case 3
    If check<>3 And check<>7 And check<>8 And check<>9
    yco-8
    If posy<180
    objy=objy+10*speed
    Else
    posy-10*speed
    EndIf
    Else
    If check=9
    a=up
    Delay(20)
    move=0
    Goto inhouse
    EndIf
    EndIf
    up=up+1
    Delay(100/speed)
    If up>33 : up=26 : EndIf

    a=up
    move=0
  
    Case 4
    If check<>4 And check<>5 And check<>6
    yco+8
    If posy>340
    objy=objy-10*speed
    Else
    posy+10*speed
    EndIf
    EndIf
    down=down+1
    Delay(100/speed)
    If down>25 : down=18 : EndIf

    a=down
    move=0
    
    Case 5
      If SpritePixelCollision(a,posx,posy,61,700+objx,300+objy)
      collected=1
     EndIf
       
EndSelect

ClearScreen(0,0,0)

For y=1 To 39                                   
For x=1 To 58
bl=ground(x,y)
DisplayTransparentSprite(bl,x*30+objx,y*30+objy)
Next
Next

ax.l=(posx-objx)/30
ay.l=(posy-objy)/30
check.l=move(ax,ay)

     DisplayTransparentSprite(a, posx, posy)
     
     If collected=0
     DisplayTransparentSprite(61,700+objx,300+objy)
     EndIf
                  
  For x=1 To 58
  y=40
    bl=ground(x,y)
    DisplaySprite(bl,x*30+objx,40*30+objy)
    Next

             StartDrawing(ScreenOutput())
       
        Locate(200,200)
        DrawText(text$)
        Locate(10,10)
        DrawingMode(1)
        FrontColor(255,255,255)
        DrawText("X Co-ordinate: "+Str(xco)+"  Y Co-ordinate: "+Str(yco))
        StopDrawing()

EventID.l=WaitWindowEvent()
        
FlipBuffers()
         
Until EventID=#PB_Event_CloseWindow Or Quit=1

If it's something blatant, please just tell me. The map file ain't important, it just has the datasection bit.
Thanks in advance.

Posted: Mon Mar 21, 2005 5:22 pm
by Paul
You gave no link to images so I can't test but by quickly looking you have 2 event checks in your main loop, one of which is WaitWindowEvent. (you don't want to use since it will pause your loop waiting for events)

Your event loop should start something like this, which will prevent CPU hog and execute loop continuously.

It is bad coding to use GOTO to jump out of a Select/Case.
Also not sure why you are using Delay in your Select/Case since it will cause jerkyness... entire loop will pause until delay is finished. If it's for speed control there are much better ways to do this ;)

Good luck.


Code: Select all

Repeat 
  EventID=WindowEvent()
  If EventID
    If EventID=#PB_Event_CloseWindow
      Quit=1
    EndIf
    Else
    Delay(1)
  EndIf
  
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Left):move=1
    ElseIf KeyboardPushed(#PB_Key_Right):move=2
    ElseIf KeyboardPushed(#PB_Key_Up):move=3
    ElseIf KeyboardPushed(#PB_Key_Down):move=4
    ElseIf KeyboardPushed(#PB_Key_D):move=5
  EndIf
  If KeyboardPushed(#PB_Key_LeftShift) Or KeyboardPushed(#PB_Key_RightShift):speed=2:Else:speed=1:EndIf
  If KeyboardReleased(#PB_Key_Escape)  :  Quit=1  :  EndIf
 
 
  Select move 
    Case 0
      a=1
   
    Case 1
      If check<>1 And check<>6 And check<>7
        xco-8
        If posx<180
          objx=objx+8*speed
          Else
          posx-8*speed
        EndIf
      EndIf
      left=left+1
      Delay(100/speed)
      If left>17 : left=10 : EndIf
      a=left
      move=0
   
    Case 2
      If check<>2 And check<>5 And check<>8 And check<>10
        xco+8
        If posx>300
          objx=objx-8*speed
          Else
          posx+8*speed
        EndIf
        Else
        ;?????????
      EndIf
      If check=10
        Goto nextscreen
      EndIf
      right=right+1
      Delay(100/speed)
      If right>9 : right=2 : EndIf
      a=right
      move=0
   
    Case 3
      If check<>3 And check<>7 And check<>8 And check<>9
        yco-8
        If posy<180
          objy=objy+10*speed
          Else
          posy-10*speed
        EndIf
        Else
        If check=9
          a=up
          Delay(20)
          move=0
          Goto inhouse
        EndIf
      EndIf
      up=up+1
      Delay(100/speed)
      If up>33 : up=26 : EndIf
      a=up
      move=0
 
    Case 4
      If check<>4 And check<>5 And check<>6
        yco+8
        If posy>340
          objy=objy-10*speed
          Else
          posy+10*speed
        EndIf
      EndIf
      down=down+1
      Delay(100/speed)
      If down>25 : down=18 : EndIf 
      a=down
      move=0
   
    Case 5
      If SpritePixelCollision(a,posx,posy,61,700+objx,300+objy)
        collected=1
      EndIf
       
  EndSelect

  ClearScreen(0,0,0)
  For y=1 To 39                                   
    For x=1 To 58
      bl=ground(x,y)
      DisplayTransparentSprite(bl,x*30+objx,y*30+objy)
    Next
  Next

  ax.l=(posx-objx)/30
  ay.l=(posy-objy)/30
  check.l=move(ax,ay)

  DisplayTransparentSprite(a, posx, posy)
     
  If collected=0
    DisplayTransparentSprite(61,700+objx,300+objy)
  EndIf
                 
  For x=1 To 58
    y=40
    bl=ground(x,y)
    DisplaySprite(bl,x*30+objx,40*30+objy)
  Next

  StartDrawing(ScreenOutput()) 
    Locate(200,200)
    DrawText(text$)
    Locate(10,10)
    DrawingMode(1)
    FrontColor(255,255,255)
    DrawText("X Co-ordinate: "+Str(xco)+"  Y Co-ordinate: "+Str(yco))
  StopDrawing()
       
  FlipBuffers() 
Until Quit

Posted: Mon Mar 21, 2005 5:51 pm
by dagcrack
edit: I had to post at the same time than Paul, saying the same exact thing.

:shock: What a ... !

What I was saying is that yes, you should include all the files of your project if you want someone to help you more in-deep .... Or provide code that needs no external files.

I commented down all the sprite usage and compiled ok, just changed the windowevent() command as it shoudlnt be used like that. About your movement problem, its just there ! sit down, clean your code and you will find the big errors you made. (if we give you the finished game so you can compile it, that wont let you learn :P )

Later as you said, I found a dirty code!, and bad usage of commands as well.
Don't tell me you're working in an RPG :lol:

Posted: Tue Mar 22, 2005 10:22 am
by ShadowRunnaX
:) Thank you, it works. That really bugged me for time, 'cos I never used to use windowed screens. And embarrasingly enough, it is meant to be an RPG.

I hadn't worked on this code for like a month, and as soon as I came back to it, I flopped.

Thanks again to everyone who helped.