do not block the update function with "sleep"
don't draw objects in the update function.
You can use the screen.setScale
function to change the scale
The screen.setTranslate
function can be used to appear to move objects on the screen.
See what it looks like using these functions and how much less counting there is when drawing each element.
init = function()
guiScale=1
xOffset=0
yOffset=0
oldXOffset=0
oldYOffset=0
sprite = sprites[ "sprite"]
wait = 0
oldMouseX=0
oldMouseY=0
screenHalfX = screen.width / 2
screenHalfY = screen.width / 2
end
update = function()
mouse_x = xOffset + mouse.x / guiScale
mouse_y = yOffset + mouse.y / guiScale
do
mouseZoom()
end
if guiScale<0.4 then
guiScale=0.4
end
if guiScale>3 then
guiScale=3
end
mouseDrag()
end
draw = function()
screen.setScale( guiScale , guiScale )
screen.setTranslation( - xOffset * guiScale , -yOffset * guiScale )
screen.clear("black")
createButton("pinkbox", 0, 0, "window.open(\"https://www.google.com\")")
createButton("pinkbox", 70, 0, "window.open(\"https://www.google.com\")")
createButton("pinkbox", 0, 70, "window.open(\"https://www.google.com\")")
screen.drawRound( mouse_x, mouse_y, 10 , 10 )
screen.drawLine( 0, 0, 200, 0)
screen.drawLine( 0, 0, 0, 200 )
screen.drawText( "mouse("+floor(mouse_x)+","+flor(mouse_y)+")", -180, 80, 30)
screen.drawText( "mouse("+floor(mouse.x)+","+flor(mouse.y)+")", -180, 60, 30)
screen.drawText( "scale("+(guiScale)+")", -180, 40, 30)
end
createButton = function(sprite, posX, posY, site)
screen.setColor( "white" )
screen.drawRect( posX, posY, 60, 60 )
screen.drawSprite( "icon", posX, posY, 60, 60 )
if mouse_x<(30+posX) and mouse_x>(-30+posX) and
mouse_y<(30+posY) and mouse_y>(-30+posY) then //and mouse.press and mouse.left then
// system.javascript(site)
screen.setColor( "red" )
end
screen.drawRect( posX, posY, 60, 60 )
screen.drawRect( mouse_x, mouse_y, 10, 10 )
end
mouseZoom = function()
zoomChange=0.50
local now = system.time()
if wait < system.time() then
if ( mouse.wheel==1 ) then
if guiScale<3 then
wait =system.time() + 5
guiScale=guiScale*1+zoomChange
oldMouseX=oldMouseX / guiScale
oldMouseY=oldMouseY / guiScale
end
else
if mouse.wheel == -1 then
if guiScale>0.4 then
guiScale=guiScale*1-zoomChange
oldMouseX=oldMouseX / guiScale
oldMouseY=oldMouseY / guiScale
end
end
end
end
end
mouseDrag = function()
if mouse.right then
xOffset=(xOffset + oldMouseX - mouse_x )
yOffset=(yOffset + oldMouseY - mouse_y )
print(oldMouseX)
print("mouse.x = " + mouse.x)
print(oldXOffset)
print("xOffset = " + xOffset + " yOffset = " + yOffset )
print()
end
if mouse.right and mouse.release then
oldXOffset=xOffset
oldYOffset=yOffset
oldMouseX=mouse_x
oldMouseY=mouse_y
end
end