Skip to content

Nesting Sprite play/do calls does not work beyond the first block #232

@nogginly

Description

@nogginly

Hello.

I was trying to sequence a series of non-looping sprite animations and ran into this issue where nesting play calls does not work.

  sprite.play animation: jump do  # block1
    sprite.play animation: fall do   # block2
      sprite:play animation: idle 
    end
  end

Expected behaviour

The sprite should jump (6 frame animation), then fall (another 6 frame animation), and then idle (looping animation).

Actual behaviour

The sprite jumps, falls, but never idles, since "block1" gets called, but "block2" never does.

Root cause

The root cause is the order of these lines:

ruby2d/lib/ruby2d/sprite.rb

Lines 180 to 181 in dfcec33

if @done_proc then @done_proc.call end
@done_proc = nil

Possible fix

Re-ordering them and using a local variable (as follows, for example) should fix the problem:

            kept_done_proc = @done_proc
            @done_proc = nil
            if kept_done_proc then kept_done_proc.call end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions