cadin / panels

Build interactive comics for the Playdate console.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crank not working in cutscene

rubybrowncoat opened this issue · comments

I'm trying embedded Panels and while the dpad works normally (even if I'd like it to be a little faster, and I haven't found a setting to make it so) the crank just doesn't work at all.

I've been browsing the documentation looking for settings or comicData options but I might be just missing something obvious.

Crank

Do you mean that you're embedding a Panels comic in another game?

If so, you need to make sure that any crank-handling code in your main game isn't running while the comic is active.

There is an example project here:
https://github.com/cadin/panels-cutscene-example

As shown in that project, it's probably best practice to completely separate your game update and comic update codes:

-- MAIN UPDATE LOOP
-- here we use the `cutsceneIsPlaying` flag to determine
-- whether we should update the main game or Panels
function playdate.update()
    if cutsceneIsPlaying then
        Panels.update()
    else
        updateGame()
    end
end

That way it makes it easier to be sure you're not inadvertently calling getCrankChange() while the comic is running.

Scroll speed

There isn't a setting for this, but you can manually change it:

Go to line 46 in libraries/Panels/Panels.lua and change
local maxScrollVelocity = 8 to local maxScrollVelocity = 4 (or whatever value works for you)

Just remember that you made this change if you need to pull a newer version of the library.

Do you mean that you're embedding a Panels comic in another game?

Yes, with the startCutscene method. And then I'm calling Panels.update() inside the update method of a "scene" that I'm transitioning to beforehand.

I don't want to assume too much as I haven't looked into the guts of the library enough to make a determination one way or another, but wouldn't it be easier and more compatible to handle cranked through playdate.inputHandlers (for cutscenes only, I guess)?

I'm using inputHandlers in my game and clearing it before calling startCutscene, so maybe there's some conflict there I can't pinpoint between my inputHandlers and playdate.cranked. If there was some issue with the update function I would expect the dpad to be non-functional as well, but that is working fine, just the crank not registering, am I wrong in this assumption?

I suppose using inputHandlers for crank might make things easier for cutscenes. The cutscene feature was added as an afterthought, so I made the minimum amount of changes to get it working.

If you're able to share your game code (or an example that shows the issue) with me that would be helpful.

On that same repository I have made an additional branch showcasing another issue I've discovered, this time it's about a missing advance control on the last panel of the sequence. If you are feeling particularly adventurous, here it is:

https://github.com/rubybrowncoat/panels-bug-repro/tree/bug/missing-advance-conrol

I'll look into switching everything over to input handlers in the future. For now you should be able to just disable the input handlers for your game before starting the Panels comic:
Noble.Input.setHandler(nil)

Depending on how your game is set up your might want to save your input handlers and restore them when the comic finishes. Something like this should work:

function PanelsScreen:init()
    local handler = Noble.Input.getHandler()
    Noble.Input.setHandler(nil)
    
    Panels.startCutscene(comicData, function ()
        Noble.Input.setHandler(handler)
        Noble.currentScene():resume()
        popScreen()
    end)
end

Not exactly sure what's going on with the advance buttons in your second example.

It doesn't make sense that that only happens when it's running from a Noble scene. It smells like Noble is somehow interfering with update or updateTimers, but I don't see how that would be happening. I don't know how Noble works, so it's tricky to debug.

In any case, I have a patch that fixes it that I can push tomorrow if I can't find anything smarter.

Also, in your second example, you can briefly see the comic start to scroll back into frame as the Noble transition starts. This is caused by continuing to call Panels.update() after the comic is finished.

A quick fix in your example could be to keep track of cutscene_ended like you do for cutscene_started:

function PanelsScene:start()
    PanelsScene.super.start(self)
    
    Noble.Input.setHandler(nil)
    Panels.startCutscene(self.comic_data, function ()
        self.cutscene_ended = true
        Noble.transition(PlayScene, 1, Noble.TransitionType.DIP_TO_WHITE)
    end)

    self.cutscene_started = true
end

function PanelsScene:update()
    PanelsScene.super.update(self)

    if not self.cutscene_started or self.cutscene_ended then
        return
    end

    Panels.update()
end

I'll look into switching everything over to input handlers in the future. For now you should be able to just disable the input handlers for your game before starting the Panels comic: Noble.Input.setHandler(nil)

So yeah, I was already doing this in the "screen" example (the first one) it's just that I was doing it with an empty table Noble.Input.setHandler({}) and that, apparently, doesn't work. It does work with nil, I just changed that bit (the scene has a pause method that does that, and a resume method that reinstates the original handler) and voilà.

Silly me.

Hi, I tracked down the button issue to this bit in your main file:

-- timer fix
function playdate.timer:start()
    self._lastTime = nil
    self.paused = false
end

What is that doing? Is it necessary?
Removing that function fixes the issue.

There is an issue (at least there was one when I started adding that workaround) with timers, when you pause them and start them again after a while they go through all the "ticks" that happened while they were paused, which was an unexpected behavior.

Maybe this has been fixed in recent versions, I'm not sure. I'll give it a try, thanks!

Ok, I'm updating the Panels code to be more defensive so it shouldn't be an issue if it's still needed.

This should all be fixed now if you pull main.

  • You can use Panels.Settings.maxScrollSpeed to adjust d-pad scroll speed. (Make sure to set that before you call start() or startCutscene())

  • Panels cranking now uses an input handler, so it shouldn't conflict with your game input (no need to nil your input handlers before starting the comic).

  • Hidden advance control issue is fixed.

Thanks for your help!

Thanks for all the changes, 1.4 is working great! 🎉