Jump to content

Problem of custom cursor


jingzhi

Recommended Posts

I am trying to make a custom cursor:

function drawCursor(status) 
    if status == true then 
        showCursor(true) 
        setCursorAlpha(0) 
        Rx,Ry = guiGetScreenSize() 
        addEventHandler("onClientPreRender",root, 
        function() 
        local cursorX,cursorY = getCursorPosition() 
        posX = math.floor(cursorX * Rx) 
        posY = math.floor(cursorY * Ry) 
        dxDrawImage(posX,posY,32,32,"cursor.png",_,_,_,_,true) 
        end) 
    elseif status == false then 
        removeEventHandler("onClientPreRender",root, 
        function() 
        local cursorX,cursorY = getCursorPosition() 
        posX = math.floor(cursorX * Rx) 
        posY = math.floor(cursorY * Ry) 
        dxDrawImage(posX,posY,32,32,"cursor.png",_,_,_,_,true) 
        end) 
        showCursor(false) 
    end 
end 
  

It works, but there is some bug:

1. The cursor is always behind the all the GUI

2. After I hide the cursor using removeEventHandler, it keeps showing error every frame:

:9: attempt to perform arithmetic on local "cursorX" (a boolean value)

which i think means the removeEventHandler didn't stop the arithmetic action, and I don't know why

Please help if you know the problem, thank you very much! :)

Link to comment
Rx,Ry = guiGetScreenSize ( ); 
  
function renderCursor ( ) 
    local cursorX,cursorY = getCursorPosition( ) 
    posX = math.floor(cursorX * Rx) 
    posY = math.floor(cursorY * Ry) 
    dxDrawImage(posX,posY,32,32,"cursor.png",0,0,0,tocolor(255,255,255,255),true) 
end 
  
function drawCursor(status) 
    if status then 
        showCursor(true) 
        setCursorAlpha(0) 
        addEventHandler("onClientPreRender",root,renderCursor) 
    else 
        removeEventHandler("onClientPreRender",root,renderCursor) 
        showCursor(false) 
    end 
end 

Edited by Guest
Link to comment
Rx,Ry = guiGetScreenSize ( ); 
  
function renderCursor ( ) 
    local cursorX,cursorY = getCursorPosition( ) 
    posX = math.floor(cursorX * Rx) 
    posY = math.floor(cursorY * Ry) 
    dxDrawImage(posX,posY,32,32,"cursor.png",0,0,0,tocolor(255,255,255,255),true) 
end 
  
function drawCursor(status) 
    if status then 
        showCursor(true) 
        setCursorAlpha(0) 
        addEventHandler("onClientPreRender",root,renderCursor) 
    else then 
        removeEventHandler("onClientPreRender",root,renderCursor) 
        showCursor(false) 
    end 
end 

You wrote 'then' at line 15.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...