Skip to content

Sprites in Playground #34

@rezoner

Description

@rezoner

What would be your expectation regarding rendering sprites in Playground.
Preferably write example USAGE in real code.

TL;DR

The problem is that there are many solutions to render sprites/animations.

A sprite rendering would have to support these (or is this is not what you expect?):

  • texture atlas
  • fixed grid
  • scale, rotation, align
  • DURATION

I've put emphasis on DURATION because it implies having time delta somewhere - and that's where the thing gets nasty as this clearly leverage Playground beyond unobtrusive core architecture that deals with display and input only.

On top of that - it's really hard to achieve that with functional (rather than objective) approach without sacrificing readability - and I don't really want to go with objects because it's pushing playground towards tightly coupled engine (like Phaser).

That's the minimal form for a functional sprite rendering. It requires you to have a sprite defined somewhere earlier.

renderSprite(app.sprites.tank, x, y, delta);

app.sprites.tank = {
  image: "tank",
  frames: 16,
  width: 32,
  height: 32,
  alignX: 0.5,
  alignY: 0.5,
  duration: 0.4
};
  • What about loops?
  • What about events? (state finished) - useful for coupling with game logic

I really think that having your own sprite object is more convenient than functional approach - and for rendering you just use layer.drawRegion

So now I am thinking more about providing just two methods to extract frame from textureAtlas and fixed-size spritesheet - something like more advanced version of layer.drawRegion

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions