It is currently Wed May 22, 2013 12:34 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Mad Mouse Disease (it shakes and moves!)
PostPosted: Sat Oct 04, 2008 10:16 am 
Offline
Addict
Addict
User avatar

Joined: Tue Jan 02, 2007 8:16 pm
Posts: 4328
Location: Cypress TX
OK so I have had a spot of trouble in my new game... {SIGH} and I had done ALL the coding myself up to near the finished project! Not bad for 4 days work!

Anyway I am using Screen in Window which has been improved greatly by Trand, SRod and Demivac and quite a few others!

Problem is on the edge of the screen... mouse flickers badly. In my game it flickers badly AND decides to move up to the upper RIGHT corner... in this example it just flickers...

not quite the same but close

Code:
; Rook Zimbabwe

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
    MessageRequester("Error", "DirectX 7+ Fail!", 0)
    End
EndIf

Enumeration
    #Window_0
EndEnumeration

Enumeration
    #Button_0
    #Frame3D_0
EndEnumeration

#TILE = 1
#MOUSETILE = 2
#MOUSE = 0
#LeftOffset = 10
#TopOffset  = 15
#MouseScreenW = 128
#MouseScreenH = 128
#ScreenW    = 192
#ScreenH    = 192
#MaxWIDE = 3
#MaxHIGH = 3

Structure VisualDesignerGadgets
    Gadget.l
    EventFunction.l
EndStructure

DataSection
Image1:
    IncludeBinary  "mouse01.bmp"
Image2:
    IncludeBinary  "tile01.bmp"
Image3:
    IncludeBinary  "board01.bmp"
EndDataSection

Global NewList EventProcedures.VisualDesignerGadgets()
Global Dim LAYER(2,2) ; a 3X3 array
Global ax ; hold actual mousex in screen
Global ay
Global SPX = 64; size of sprites
Global SPY = 64
Global OLDX ; last position in array of changed tile
Global OLDY
;-

;-
Procedure DoScreenDisplay(inscreen)
    ; Display your screen stuff
    ; LAYER(OLDX,OLDY) = #TILE
    If inscreen
        ExamineMouse()
        ax = MouseX() / SPX  ;these show coordinates of tile in map
        ay = MouseY() / SPY
        LAYER(ax,ay) = #MOUSETILE
        OLDX = ax
        OLDY = ay
    EndIf
   
EndProcedure

Procedure RefillBoard()
    For x =  0 To 2
        For y = 0 To 2
            LAYER(x,y) = #TILE ; set LAYER to background tiles image
        Next
    Next
EndProcedure
;-
Procedure Button_0_Event(Window, Event, Gadget, Type)
    Debug "#Button_0"
EndProcedure

;-
Procedure RegisterGadgetEvent(Gadget, *Function)
   
    If IsGadget(Gadget)
        AddElement(EventProcedures())
        EventProcedures()\Gadget        = Gadget
        EventProcedures()\EventFunction = *Function
    EndIf
   
EndProcedure

Procedure CallEventFunction(Window, Event, Gadget, Type)
   
    ForEach EventProcedures()
        If EventProcedures()\Gadget = Gadget
            CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
            LastElement(EventProcedures())
        EndIf
    Next
   
EndProcedure

Procedure Open_Window_0()
   
    If OpenWindow(#Window_0, 0, 0, 400, 280, "TurboTURDo",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
        If CreateGadgetList(WindowID(#Window_0))
            Frame3DGadget(#Frame3D_0, 6, 0, 202, 213, "TIC TAC TURDO")
            ButtonGadget(#Button_0, 275, 15, 120, 35, "THIS IS A BUTTON")
            RegisterGadgetEvent(#Button_0, @Button_0_Event())
           
        EndIf
    EndIf
EndProcedure

Open_Window_0()

OpenWindowedScreen(WindowID(#Window_0),10,15,192,192,0,0,0)

CatchSprite(#MOUSE, ?Image1,#PB_Sprite_Memory)
CatchSprite(#TILE, ?Image2,0)
CatchSprite(#MOUSETILE, ?image3,0)

RefillBoard()

Repeat
    ClearScreen(0)
    UpdateWindow_(WindowID(#Window_0))
   
    If inscreen
        If MouseX() > #MouseScreenH+62  Or MouseY() > #MouseScreenW+62 Or MouseX() < 1 Or MouseY() < 1         
            inscreen = #False
            ReleaseMouse(1)
        EndIf
    Else
        Event  = WaitWindowEvent()
        Gadget = EventGadget()
        Type   = EventType()
        Window = EventWindow()
       
        Select Event
        Case #PB_Event_Gadget
            CallEventFunction(Window, Event, Gadget, Type)
           
        EndSelect
       
        mx = WindowMouseX(0)
        my = WindowMouseY(0)
        If mx < #ScreenH+#TopOffset And mx > #TopOffset And my > #LeftOffset And my < #LeftOffset+#ScreenW
            ReleaseMouse(0)
            MouseLocate(mx-#LeftOffset,my-#TopOffset)
            inscreen = #True
        EndIf
    EndIf
   
    DoScreenDisplay(inscreen)
   
    YYY = 0
    For y = 0 To 2
        XXX = 0
        For x = 0 To 2
            DisplaySprite(LAYER(x,y),XXX , YYY)
            XXX + SPX
        Next
        YYY + SPY
    Next
    ExamineMouse()
   
    DisplayTransparentSprite(#MOUSE,MouseX(),MouseY())
   
    FlipBuffers()
    refillboard()
   
   
Until Event = #PB_Event_CloseWindow

End



BMPS are at: http://www.bluemesapc.com/Downloads/turboturd0.zip

_________________
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 04, 2008 10:33 am 
Offline
Always Here
Always Here
User avatar

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7304
Location: Norway
It would help a lot of you told us what behaviour you want.

_________________
Woa, I set up a web server.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 04, 2008 1:51 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Mar 19, 2006 1:57 pm
Posts: 4835
Location: Germany
without reading your code completely...

I guess you Free the Mouse when it reaches the outer rim of the screen,
and you bind it in again when it's over the screen?
I think you take back-and-forth decisions in your code.
you should define explicit conditions for your Mousepointer to be inside/outside the screen.

have a look at these codes and let you be inspired...

http://www.purebasic.fr/english/viewtopic.php?t=25082

_________________
oh... and have a nice day.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 04, 2008 6:36 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Jan 02, 2007 8:16 pm
Posts: 4328
Location: Cypress TX
@Kaeru: I see that. I do think the issue id a focus issue, but I haven't figured out how to check JUST the focus in the windowed screen I create... I have tried it by conditional IF/THEN statements...

The problem occourss if the mouse is at 0,Y or X,576 in my program (my real program) at that moment... because of the redraw of the board so I can light up the target square... it goes a little insane.

It could also be a variable issue. I could be passing something BAD. And I thought I was so careful to use only specific variable names!!! :oops:

@Trond: I want it to NOT move the mouse in to the UPPER RIGHT corner if the mouse is at 0,Y or X,576!

_________________
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 11, 2008 12:19 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 2399
Location: Utah, USA
@Rook: I know you are probably already past this shakey mouse thing but it seemed silly not to post the correction for it. Here are some minor changes in your code that remove the flickers. :wink:

I adjusted the constants for the size of the MouseScreen since they held the wrong values anyway. I also adjusted the comparisons that check when the mouse is moving from the window to the screen and vice-versa. Lastly, I put in a check to display the mouse pointer only when the mouse was in the screen area.

Code:
; Rook Zimbabwe

If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
  MessageRequester("Error", "DirectX 7+ Fail!", 0)
  End
EndIf

Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Button_0
  #Frame3D_0
EndEnumeration

#TILE = 1
#MOUSETILE = 2
#MOUSE = 0
#LeftOffset = 10
#TopOffset  = 15
#MouseScreenW = 192
#MouseScreenH = 192
#ScreenW    = 192
#ScreenH    = 192
#MaxWIDE = 3
#MaxHIGH = 3

Structure VisualDesignerGadgets
  gadget.l
  EventFunction.l
EndStructure

DataSection
  Image1:
  IncludeBinary  "mouse01.bmp"
  Image2:
  IncludeBinary  "tile01.bmp"
  Image3:
  IncludeBinary  "board01.bmp"
EndDataSection

Global NewList EventProcedures.VisualDesignerGadgets()
Global Dim LAYER(2,2) ; a 3X3 array
Global ax ; hold actual mousex in screen
Global ay
Global SPX = 64; size of sprites
Global SPY = 64
Global OLDX ; last position in array of changed tile
Global OLDY
;-

;-
Procedure DoScreenDisplay(inscreen)
  ; Display your screen stuff
  ; LAYER(OLDX,OLDY) = #TILE
  If inscreen
    ExamineMouse()
    ax = MouseX() / SPX  ;these show coordinates of tile in map
    ay = MouseY() / SPY
    LAYER(ax,ay) = #MOUSETILE
    OLDX = ax
    OLDY = ay
  EndIf
 
EndProcedure

Procedure RefillBoard()
  For x =  0 To 2
    For y = 0 To 2
      LAYER(x,y) = #TILE ; set LAYER to background tiles image
    Next
  Next
EndProcedure
;-
Procedure Button_0_Event(Window, event, gadget, type)
  Debug "#Button_0"
EndProcedure

;-
Procedure RegisterGadgetEvent(gadget, *Function)
 
  If IsGadget(gadget)
    AddElement(EventProcedures())
    EventProcedures()\gadget        = gadget
    EventProcedures()\EventFunction = *Function
  EndIf
 
EndProcedure

Procedure CallEventFunction(Window, event, gadget, type)
 
  ForEach EventProcedures()
    If EventProcedures()\gadget = gadget
      CallFunctionFast(EventProcedures()\EventFunction, Window, event, gadget, type)
      LastElement(EventProcedures())
    EndIf
  Next
 
EndProcedure

Procedure Open_Window_0()
 
  If OpenWindow(#Window_0, 0, 0, 400, 280, "TurboTURDo",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      Frame3DGadget(#Frame3D_0, 6, 0, 202, 213, "TIC TAC TURDO")
      ButtonGadget(#Button_0, 275, 15, 120, 35, "THIS IS A BUTTON")
      RegisterGadgetEvent(#Button_0, @Button_0_Event())
    EndIf
  EndIf
EndProcedure

Open_Window_0()

OpenWindowedScreen(WindowID(#Window_0),10,15,192,192,0,0,0)

CatchSprite(#MOUSE, ?Image1,#PB_Sprite_Memory)
CatchSprite(#TILE, ?Image2,0)
CatchSprite(#MOUSETILE, ?Image3,0)

RefillBoard()
 
Repeat
  ClearScreen(0)
UpdateWindow_(WindowID(#Window_0))
 
  If inscreen
    If MouseX() < 1 Or MouseY() < 1  Or MouseX() > #MouseScreenW - 2  Or MouseY() > #MouseScreenH - 2  ;
      inscreen = #False
      ReleaseMouse(1)
    EndIf
  Else
    event  = WaitWindowEvent()
    gadget = EventGadget()
    type   = EventType()
    Window = EventWindow()
   
    Select event
      Case #PB_Event_Gadget
        CallEventFunction(Window, event, gadget, type)
       
    EndSelect
   
    mx = WindowMouseX(0)
    my = WindowMouseY(0)
   
    If mx > #LeftOffset And mx < #LeftOffset+#ScreenW - 1 And my > #TopOffset And my < #ScreenH+#TopOffset - 1 ;
      ReleaseMouse(0)
      MouseLocate(mx-#LeftOffset,my-#TopOffset)
      inscreen = #True
    EndIf
  EndIf
 
  DoScreenDisplay(inscreen)
 
  YYY = 0
  For y = 0 To 2
    XXX = 0
    For x = 0 To 2
      DisplaySprite(LAYER(x,y),XXX , YYY)
      XXX + SPX
    Next
    YYY + SPY
  Next
  ExamineMouse()
 
  If inscreen        ; <== only show pointer if in the screen area
    DisplayTransparentSprite(#MOUSE,MouseX(),MouseY())
  EndIf
   
  FlipBuffers()
  RefillBoard()
 
 
Until event = #PB_Event_CloseWindow

End

_________________
Image


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

All times are UTC + 1 hour


Who is online

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