Probably a silly question, but I can't seem to work it out.
I have a slow function - it takes more than 1/30 of second to execute but needs to be done in the _draw() function. This makes my code slow and unresponsive and it's clearly not the way to do it.
So what I want to do is the following:
- run my slow function once in the _init() (drawing a bunch of stuff to the screen)
- capture the screen to extended memory
- in my _draw() function do repeated copies back to the screen
This works ... BUT ... when I run my slow function it shows on the screen (briefly, during _init() ). Probably because it overruns the 1/30 second _draw update time. I would rather suspend draw updates during _init().
So is there a way to suspend screen refreshing for a bit and then switch it back on?
@kimiyoribaka thanks! That is what I tried first, but it doesn't work (I think that whenever _init() runs longer than 1/30 second, PICO8 decides to do a screen update outside _draw ?)
But I'm looking into setting the sprite memeory as drawable, do my stuff there, store it in extended memory and do a reload to get my sprites back. Should work, right?
@freds72 that's true - there's ways to circumvent calling _draw. But that doesn't stop PICO8 from doing a screen refresh I think. Any drawing to the screen in _init will still be shown. Even if _draw is doing nothing (or even missing from your code alltogether).
But I will investigate this a little further. Thanks for the comments so far!
yes, there are blits happening no matter what...
using the sprite sheet should work if you don't need pre-defined sprites.
you could also redefine the screen palette to blacks while you're initializing (pal(...,1)), just reset it at the end of _init()
you can also use holdframe():
function _init() holdframe() print("wot") while not btnp(4) do end end function _draw() ?"done" end
Actually I think @ultrabrite has it, @Miez. You just want the screen to stop appearing even though you are still drawing to it, even =IF= it's exceeded the 1/30th of a second timeout. That would make use of the seldom known function,
:: Undocumented functions -- From http://pico-8.wikia.com/wiki/Category:Undocumented_API holdframe() forces display not to update until flip() is called
I don’t really understand that last line: there are no updates during init (_init runs once, then _update and _draw are called in the game loop). if you have long calculations to run before the game can start, then you could run them in a title screen or loading screen (with a function called from _update, or even using coroutines which are functions that can be paused and resumed with their local state intact), with _draw showing some simple loading bar and text!
@merwok - I think I didn't explain clearly. _init could perhaps do with a parameter to have SCREEN updates on or off during it's execution. It could be argued that screen updates should only be done in the _draw function, but that's clearly not the case.
It's no problem, only in very weird cases (such as mine, where I require an image to be made procedurally and stored without it showing on screen as it's being made).
@dw817 thx so much for
holdframe()!!! I wasn't aware that page existed in the wiki and that function is exactly what I needed!
I'm making use of the new
poke(0x5f55, 0) to do some work on the spritesheet during init, either at the root level before
_init() is defined, or actually in
_init(). The former will never flip to the screen, which makes sense; but the latter will, which also makes sense but might not be desired as in mine and OP's case. @zep, Sorry to tag/bother you with this, but since you're the only one who can answer, is
holdframe() relatively safe from future deprecation? If not the function itself, will there always be some way or another to prevent a screen refresh, like setting a value in RAM?
@ridgekuhn you may be interested in this lovely article written by @replaycoding.
It is where I found the
holdframe() command - and there are many other secrets revealed not yet listed in standard Pico-8 help files and documents.
Come one, learn all.
[Please log in to post a comment]