pancelor / p8x8

convert PICO-8 carts into picotron carts (some assembly required)
Other
23 stars 0 forks source link

drawing outside _draw in fullscreen mode #9

Open pancelor opened 8 months ago

pancelor commented 8 months ago

cart authors must do all drawing inside _draw -- don't do any during _update. if you do, p8x8's fullscreen mode will break

todo:


notes:

cherrybomb and #pony9k_2_0 both have issues with fullscreen mode -- I think cherrybomb probably uses a while ... flip() end fade-in loop, which I suspect is the issue. (I didn't think picotron could even handle those style of loops! maybe just not carts that have no _draw at all?)

I tried adding set_draw_target(fakecanvas) to the end of the fullscreen draw in pony9k_2_0 but it made things worse; very strange (and earlier on I added local fakecanvas = userdata("u8",128,128)

arrowonionbelly commented 8 months ago

hoi! So, drawing things outside of draw, how do I fix my game if I have different draw functions? Instead of _ENV would calling a function as a variable (like _drw=draw_start and then function _draw() _drw() ?)

pancelor commented 8 months ago

Using _ENV is fine, the problem is calling any draw functions inside _init or _update. I just took a closer look at your cart; there's a cls() in startscrn() and a draw_start() inside update_start() -- remove them and your fullscreen border works fine!

edit for clarity: comment out draw_start in p8code/2.lua:

function update_start()
    -- draw_start()

    if btnreleased
arrowonionbelly commented 8 months ago

ok so I took a look at the functions that ARE working, and what's interesting is in tab 1, I have functions like drwoutline(myspr), drwmyspr(), and grid() and those functions work perfectly fine even if they have things like spr( or line( which I thought would also be draw functions, correct me if I'm wrong

EDIT: Is the issue only if they're being called in init or update?

arrowonionbelly commented 8 months ago

NEVERMIND I GOT IT TO WORK!!!! AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA I took the steps you recommended, changed my rnd"x" to rnd(x) and then stuck my fullscreen graphics in a single sprite!!! this is amazing thank you so much for making this tool!!!!

pancelor commented 8 months ago

glad to hear it!! and thanks for the tip about rnd -- I didn't realize that had changed in picotron.

ah, I think we're miscommunicating over the word "inside" -- grid() is fine, it's being called "inside" draw. every line of code that runs is running "inside" of either _init, _update, or _draw. your _draw() calls draw_game() (via _ENV) which calls grid() which calls line(), and this call to line() is happening "inside" _draw, so it's fine

A different example:

function do_a()  do_b()  end
function do_b()  do_c()  end
function do_c()  spr(0,24,24)  end

function _update()
  do_a() -- this line calls `spr`, which is a problem
end
function _draw()
  do_a() -- this line calls `spr`, and that's fine
end

as to your other question about keeping up with p8x8 updates, I haven't updated the docs yet but I've sketched an outline here

I'm happy the tool's working for you now! best of luck finishing the game :)