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

Mutable Sprites #106

Merged
merged 8 commits into from
Mar 24, 2022
Merged

Mutable Sprites #106

merged 8 commits into from
Mar 24, 2022

Conversation

edbentley
Copy link
Owner

This PR introduces Mutable Sprites, an alternative API to reduce the amount of GC to be collected.

Breaking changes:

  • Sprites: getInputs removed from cleanup method
  • Native Sprites
    • updateState removed
    • loop mutates state, not return it
    • parentX, parentY replaced with spriteToGameCoords
import { makeMutableSprite, t2 } from "@replay/core";
import { Player } from "./player";

export const Level = makeMutableSprite({
  init() {
    return { playerX: 0 };
  },

  loop({ state }) {
    state.playerX++;
  },

  render({ state }) {
    return [
      t2.circle(
        {
          radius: 20,
          color: "purple",
        },
        (thisProps) => {
          thisProps.x = state.playerX;
        }
      ),
      Player.Single(
        {
          rotation: 10,
          color: "red",
        },
        (thisProps) => {
          thisProps.x = state.playerX;
        }
      ),
    ];
  },
});

@edbentley edbentley merged commit 379c0e7 into master Mar 24, 2022
@edbentley edbentley deleted the mutable-sprite branch March 24, 2022 17:16
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.

None yet

1 participant