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

Allow Sprite to draw single image from spritesheet / tilemap #373

Open
straker opened this issue Aug 19, 2023 · 2 comments
Open

Allow Sprite to draw single image from spritesheet / tilemap #373

straker opened this issue Aug 19, 2023 · 2 comments
Labels
feature New feature or enhancement

Comments

@straker
Copy link
Owner

straker commented Aug 19, 2023

Someone recently asked what the best way was to use a Sprite to display a spritesheet that only contained individual sprites. I did something similar for my 2021 entry and used a tileatlas to map all the image locations and then a custom draw function to draw the image from the spritesheet.

It would be nice to implement the ability for a Sprite to be able to use a tilesheet like this instead of having to do it manually every time.

@straker straker added the feature New feature or enhancement label Aug 19, 2023
@straker straker changed the title Allow Sprite to draw single image from spritesheet / tilemap. Allow Sprite to draw single image from spritesheet / tilemap Sep 14, 2023
@sylfel
Copy link
Contributor

sylfel commented Oct 8, 2023

Hi straker,

Do you think this functionnality should be in Spritesheet class :

let spriteSheet = SpriteSheet({
    image: image,
    frameWidth: 72,
    frameHeight: 97,
  });

let sprite = spriteSheet.createSprite(15) // frame

or pass spriteSheet in Sprite constructor :

let spriteSheet = SpriteSheet({
    image: image,
    frameWidth: 72,
    frameHeight: 97,
  });

let sprite = Sprite({
    x: 300,
    y: 100,
    anchor: {x: 0.5, y: 0.5},

    // replace "image" parameter :
    spriteSheet: spriteSheet,
    frame: 15
  });

@straker
Copy link
Owner Author

straker commented Oct 8, 2023

Possibly. The sprite will at least need access to the spritesheet in order to draw from it. But it will also need to know the x/y (or row/col) of the start of the sprite image, and the width/height (or numRow/numCol) of the image. A spritemap can have sprites of different sizes and they don't necessarily have to align to any grid.

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

No branches or pull requests

2 participants