The problem
Have you ever run into the issue of Picotron becoming very slow with a lot of applications open?
This is because Picotron still runs your _update() and _draw() functions, even when the window is not in focus. I figured I could save some CPU usage (and cut down on lag in the process) by checking if the application is actually in focus and if the mouse is on the window.
For this I created a simple application to demonstrate how it's done. Feel free to copy this if you like!
The sample
To start, I created a simple application to draw the current mouse X and Y positions to the screen. Here's the code:
function _init()
mouse_x = 0
mouse_y = 0
window {
title = "pause when not in focus example",
width = 350,
height = 150
}
end
function _update()
mx, my, _, __, ___, ____ = mouse()
mouse_x = mx
mouse_y = my
end
function _draw()
cls()
print("X: " .. mouse_x .. " Y: " .. mouse_y)
[ [size=16][color=#ffaabb] [ Continue Reading.. ] [/color][/size] ](/bbs/?pid=187280#p) |

Santaban
Santa is busy delivering presents, when he reached a big building. The ducting is a mess. Help Santa move the present to their correct locations!
Controls
Arrow keys: Move
O: Undo
Enter: Open menu
Advent calendar
This cart is part of the 2025 advent calendar. This is the logo sprite (thanks @Doriencey)
|
[16x16] |





4 comments