Ooops
October 28, 2021, 16:01:10

Author Topic: Disappearing Mouse Pointer  (Read 521 times)

Offline science_boy

  • Jr. Member
  • **
  • Posts: 6
Disappearing Mouse Pointer
« on: May 23, 2021, 17:28:43 »
Hello-

I am working on an educational project for students, and I am using a program which is a modified version of this flocking game:

https://www.syntaxbomb.com/index.php/topic,1247.0.html

I am running the program at Graphics 1920,1080,32 in order to display the game full screen, and keep students from accessing the start menu, taskbar, ect. while playing. My problem is that when I set the game to run full screen we can no longer see the mouse cursor. When the game is in windowed mode we can see the cursor just fine.

Is there a simple way to use the Windows mouse cursor in full-screen? If not, how can I make a simple mouse pointer visible when in full-screen. I am a novice, and I have spent several hours reading and trying different solutions, but I cannot seem to find the right answer for this problem.

Thank you!

- Science_boy

Offline GW

  • Full Member
  • ***
  • Posts: 222
Re: Disappearing Mouse Pointer
« Reply #1 on: May 23, 2021, 18:56:41 »
Your using Blitzmax?
Are you using the commands HideMouse or ShowMouse ?
The mouse is not normally hidden in a full screen window.
You can always draw what you want at the mouse position.  Drawoval( mousex(), mousey(), 20,20)

Offline science_boy

  • Jr. Member
  • **
  • Posts: 6
Re: Disappearing Mouse Pointer
« Reply #2 on: May 23, 2021, 21:09:21 »
Yes. I am using BlitzMax. ShowMouse() was one of the first things I tried. Only when I go fullscreen do I lose the mouse pointer. I can still click in the game, but I can't see the pointer.
This is the full code to the game as it is now.

Code: [Select]
    SuperStrict
    SeedRnd MilliSecs()
     
    AppTitle$ = "Boids! Individual animals following simple rules manifest complex group behaviors."

    Global obstacleList:TList = New TList
     
    '-----------------------------------------------------------------------------------------------------------------------------------------------'
    '-----------------------------------------------------------------------------------------------------------------------------------------------'
    '-----------------------------------------------------------------------------------------------------------------------------------------------'
    Graphics 1920,1080,32
   
     
 
    SetBlend ALPHABLEND
     
     
    TBoid.Create(200) '---------------------------------------------------------------------- number of boids to create
                                                                                                                                                                                    ' see ine the TBoid type to customize boids behaviours
     
    SetClsColor 0,0,0
     
    While Not KeyHit(KEY_ESCAPE) And Not AppTerminate()
            Cls
           
            If MouseHit(1)
                ' Add this to limit the number of obstacles on screnn to 5
                Local MaximumObjects:Int = 5
                If CountList(obstacleList) >= MaximumObjects
                     ListRemove(obstacleList, obstacleList.First())
                EndIf
           
                TObstacle.Create(MouseX(),MouseY())
            EndIf
     
            ' Remove this line of code to remove the Right Mouse Button functionality.
            'If MouseHit(2) Then TObstacle.Remove()
           
            TObstacle.DrawAll()
           
            TBoid.UpdateAll()
            TBoid.DrawAll()
           
            Flip
    Wend
     
    TBoid.RemoveAll()
    TObstacle.RemoveAll()
     
    End
     
    '-----------------------------------------------------------------------------------------------------------------------------------------------'
    Type TObstacle
     
            Field x:Int,y:Int
            Field radius:Int
                   
            Function Create(x:Int,y:Int)
                    ' Add this to limit the number of obstacles on screnn to 5
                    Local MaximumObjects:Int = 5
                                    If CountList(obstacleList) >= MaximumObjects
                                       ListRemove(obstacleList, obstacleList.First())
                                    EndIf
                                   
                    Local ob:TObstacle = New TObstacle
                    ob.x = x
                    ob.y = y
                    ob.radius = 80
                    ListAddLast obstacleList,ob
            End Function
           
    ' The Remove() Function is no longer required.
    '        Function Remove()
    '                For Local ob:TObstacle = EachIn obstacleList
    '                        If Sqr( (ob.x-MouseX())*(ob.x-MouseX()) + (ob.y-MouseY())*(ob.y-MouseY()) ) < ob.radius
    '                                ListRemove obstacleList,ob
    '                                Exit
    '                        EndIf
    '                Next 
    '        End Function
           
            Function RemoveAll()
                    For Local ob:TObstacle = EachIn obstacleList
                            ListRemove obstacleList,ob
                    Next 
            End Function
           
            Function DrawAll()
                    SetColor 250,250,250
                    For Local ob:TObstacle = EachIn obstacleList
                            DrawOval ob.x-ob.radius,ob.y-ob.radius,ob.radius*2,ob.radius*2
                    Next 
            End Function
           
    End Type
     
    '-----------------------------------------------------------------------------------------------------------------------------------------------'
    Type TBoid
           
            Global boidList:TList = CreateList()
            Global friendList:TList = CreateList()
           
            Global speed:Float = 3 '--------------------------------------------------------------------------------------------- boids speed
            Global smoothTurn:Float = 25 '--------------------------------------------------------------------------------------- limits boids turn angle
            Global radius:Float = 25 '------------------------------------------------------------------------------------------- boids draw size
     
            '############################################################################################################################################
            Global friendRadius:Float = 75 '----------------------------------------------- each boid will interact with other boids within this distance
            Global friendDistance:Float = 30 '------------------------------------------------------------------------- collision distance beetween boids
           
            Global cohesionFactor:Float = 100 '--------------------------------------------- the lower this value, the strongest boids will pack together
            Global alignSpeed:Float = 2 '--------------------------------------- the lower this value, the better boids will stay aligned with each other
           
            Global obstacleMargin:Float = 30 ' ----------------------------------------------- the lower this value, the farest boids will avoid obstacles
            '############################################################################################################################################
           
            Global friendSQRradius:Float = friendRadius*friendRadius
            Global friendSQRdistance:Float = friendDistance*friendDistance
           
           
            Field x:Float,y:Float
            Field vx:Float,vy:Float
            Field angle:Float
            Field red:Int,green:Int,blue:Int
           
            Method Update()
                    GetFriends()
                    If CountList(friendList) > 0
                            vx = 0
                            vy = 0
                            Cohesion()
                            Obstacle()
                            Distance()
                            Align()
                    Else
                            'Erratic() ' see Erratic() Method below
                            Obstacle()
                    EndIf
                   
                    Move()
            End Method
           
            Method Cohesion()
                    Local centerX:Float
                    Local centerY:Float
                    For Local friend:TBoid = EachIn friendList
                            centerX = centerX + friend.x
                            centerY = centerY + friend.y
                    Next
                    centerX = centerX / CountList(friendList)
                    centerY = centerY / CountList(friendList)
                    vx = vx + (centerX-x) / cohesionFactor
                    vy = vy + (centerY-y) / cohesionFactor
            End Method
           
            Method Distance()
                    For Local friend:TBoid = EachIn friendList
                            Local diffX:Float = x-friend.x
                            Local diffY:Float = y-friend.y
                            Local sqrDistance:Float = diffX*diffX + diffY*diffY
                            If diffX*diffX + diffY*diffY < friendSQRdistance                     
                                    vx = vx - ( friend.x - x ) / Sqr(sqrDistance)
                                    vy = vy - ( friend.y - y ) / Sqr(sqrDistance)
                            EndIf
                    Next
            End Method
           
            Method Obstacle()
                    For Local ob:TObstacle = EachIn obstacleList
                            Local diffX:Float = x-ob.x
                            Local diffY:Float = y-ob.y
                            Local sqrDistance:Float = diffX*diffX + diffY*diffY
                            If diffX*diffX + diffY*diffY < ob.radius*ob.radius*ob.radius/obstacleMargin
                                    vx = vx - ( ob.x - x ) / Sqr(sqrDistance)
                                    vy = vy - ( ob.y - y ) / Sqr(sqrDistance)
                            EndIf
                    Next
            End Method
     
            Method Align()
                    Local sumVx:Float
                    Local sumVy:Float
                    For Local friend:TBoid = EachIn friendList
                            sumVx = sumVx + friend.vx
                            sumVy = sumVy + friend.vy
                    Next
                    sumVx = sumVx / CountList(friendList)
                    sumVy = sumVy / CountList(friendList)
                    vx = vx + ( sumVx - vx ) / alignSpeed
                    vy = vy + ( sumVy - vy ) / alignSpeed
            End Method
           
            Method GetFriends()
                    ClearList(friendList)
                    For Local friend:TBoid = EachIn boidList
                            Local diffX:Float = x-friend.x
                            Local diffY:Float = y-friend.y
                            If diffX*diffX + diffY*diffY < friendSQRradius
                                    If friend <> Self Then ListAddLast friendList,friend
                            EndIf
                    Next 
            End Method
           
            Method Erratic()
                    ' here we can make a special behaviour when a boid doesn't have any neighbour to intereact with <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    ' for the moment nothing happens when a boid is alone so it goes in a straight path
                    ' but an erratic movement to search for neighbours would be better
            End Method
           
            Method Move() 
                    x = x + vx
                    y = y + vy
                    angle = SmoothRotate(x,y,angle,x+vx,y+vy,smoothTurn)
                    x = x + Cos(angle) * speed
                    y = y + Sin(angle) * speed
                    If x < 0 Then x = x + GraphicsWidth()
                    If x > GraphicsWidth() Then x = x - GraphicsWidth()
                    If y < 0 Then y = y + GraphicsHeight()
                    If y > GraphicsHeight() Then y = y - GraphicsHeight()
            End Method
           
            Method Draw()
                    SetColor red,green,blue
                    Local x1:Float = x+Cos(angle)*radius
                    Local y1:Float = y+Sin(angle)*radius
                    Local x2:Float = x+Cos(angle+150)*radius
                    Local y2:Float = y+Sin(angle+150)*radius
                    Local x3:Float = x+Cos(angle-150)*radius
                    Local y3:Float = y+Sin(angle-150)*radius     
                    Local tri:Float[]=[x1,y1,x2,y2,x3,y3]
                    DrawPoly tri
            End Method
           
            Function Create(count:Int)
                    For Local i:Int = 1 To count
                            Local boid:TBoid = New TBoid
                            boid.x = Rand(GraphicsWidth())
                            boid.y = Rand(GraphicsHeight())
                            boid.angle = Rnd(360)
                            boid.red = Rand(50,255)
                            boid.green = Rand(50,255)
                            boid.blue = Rand(50,255)
                            ListAddLast boidList,boid
                    Next
            EndFunction
           
            Function UpdateAll()
                    For Local boid:TBoid = EachIn boidList
                            boid.Update()
                    Next
            End Function
           
            Function DrawAll()
                    For Local boid:TBoid = EachIn boidList
                            boid.Draw()
                    Next 
            End Function
           
            Function RemoveAll()
                    For Local boid:TBoid = EachIn boidList
                            ListRemove boidList,boid
                    Next 
            End Function
           
    End Type
     
    '-----------------------------------------------------------------------------------------------------------------------------------------------'
    '-----------------------------------------------------------------------------------------------------------------------------------------------'
    Function SmoothRotate:Float(sourceX:Float,sourceY:Float,sourceAngle:Float,destX:Float,destY:Float,smooth:Float)
            ' Thanks to BlackSp1der on BB forums for this piece of code ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Local targetAngle:Float = ATan2(sourceY-destY,sourceX-destX)
            Local tempAngle:Float = targetAngle - Sgn(targetAngle-sourceAngle) * 360
            If Abs(targetAngle-sourceAngle) > Abs(tempAngle-sourceAngle) Then targetAngle = tempAngle
            If sourceAngle <> targetAngle Then sourceAngle = sourceAngle - Sgn(targetAngle-sourceAngle) * (180-Abs(targetAngle-sourceAngle)) / (1+smooth)
            If sourceAngle => 360 Then sourceAngle = sourceAngle - 360 Else If sourceAngle < 0 Then sourceAngle = sourceAngle + 360
            Return sourceAngle
    End Function
 


I did try your Drawoval suggestion, but it didn't seem to do anything for me. It is very possible that I was putting it in the wrong place/way. Everything I am doing when it comes to code is total experimentation, so any help is welcome. Thanks!

science_boy

Offline GW

  • Full Member
  • ***
  • Posts: 222
Re: Disappearing Mouse Pointer
« Reply #3 on: May 23, 2021, 21:28:32 »
I can see the OS pointer on my computer.

Here is a quick ghetto mouse pointer you can draw.
Put this bit of code right before the Flip statement
Code: [Select]
            SetColor 255,0,0
            Local _mx#=MouseX()
            Local _my#=MouseY()
            DrawPoly([_mx,_my,_mx-10,_my+20, ..
                            _mx,_my,_mx+10,_my+20, ..
                            _mx-10,_my+20,_mx+10,_my+20, ..
                            _mx-10,_my+20,_mx+10,_my+20])
            DrawLine(_mx,_my+20,_mx,_my+30)                           
            SetColor 255,255,255

Take some time to go though some of the examples that come with Blitzmax. They will show better ways draw a proper mouse cursor.

Offline science_boy

  • Jr. Member
  • **
  • Posts: 6
Re: Disappearing Mouse Pointer
« Reply #4 on: May 23, 2021, 21:39:56 »
Thanks, I'll give it a try. I am using two monitors, and when I move the pointer from left to right I can see it on my right screen, but it seems to go behind the game when I go back. I appreciate your response, and I will give it a test. Thanks again!  :)

science_boy

Offline Skaven

  • Jr. Member
  • **
  • Posts: 25
Re: Disappearing Mouse Pointer
« Reply #5 on: May 24, 2021, 15:15:34 »
make sure you are using blitzmax ng and not old blitzmax legacy that has not been supported for many years

Offline science_boy

  • Jr. Member
  • **
  • Posts: 6
Re: Disappearing Mouse Pointer
« Reply #6 on: May 26, 2021, 15:33:41 »
Thanks Skaven. I can see the custom pointer using the code you provided. I can use this to create something to my liking. Thanks a lot!  :)

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal