Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove _layerOrder and just store sprites in-order #210

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

adroitwhiz
Copy link
Collaborator

Depends on #207.

This gets rid of the clones hierarchy and _layerOrder property, and stores every rendered target (sprite, stage, or clone) in one array kept in layer order. Clones now refer directly to the "original" sprite instead of their parent.

While this does require some more management of that array, it means we don't have to:

  • Maintain the _layerOrder property
  • Construct and sort a bunch of new arrays every time we want to loop through all the rendered targets (slow)
  • Traverse upwards through the clone hierarchy to find the "original" sprite

Starting triggers is also done in top-down order now (reverse layer order), which matches how Scratch does it.

This matches how Scratch behaves, and means we don't have to mess around
with _layerOrder anymore.
This matches how Scratch does it.
@PullJosh
Copy link
Collaborator

Nice! Glad to see compatibility improvements and simpler code.

I've been meeting with some of the good folks working on Patch, a "Python Scratch" that serves a similar purpose as Leopard but for Python rather than JavaScript. They are updating their codebase to use Leopard as their underlying VM rather than their forked version of scratch-vm. (scratch-vm was quite messy to integrate with and Leopard is much simpler.)

If they want to provide a "live" editor experience like Scratch, where sprites perpetually "exist" even when no scripts are running, and the instances appear on the stage immediately when creating or modifying sprites in the editor, it would be nice if they could add/remove sprites to/from a running project. We currently disallow that, mostly as a historical decision. As far as I recall, the reasoning for disallowing it was basically we don't know if the behavior will work correctly and nobody would ever want to do that anyway.

I'm wondering, now that you've just been digging into this code, if you have any sense of how difficult it would be to enable adding/deleting sprites (which are not necessarily clones) while a project is running.

@adroitwhiz
Copy link
Collaborator Author

adroitwhiz commented Jul 17, 2024

I don't think it would be that difficult. In fact, this PR adds addSprite and removeSprite methods that could probably be used as-is.

EDIT: Although removeSprite doesn't currently handle removing all of a sprite's clones, as it is currently only used for removing individual clones themselves. That would probably not be too difficult to add, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants