replit / kaboom

💥 JavaScript game library
https://kaboomjs.com
MIT License
2.66k stars 225 forks source link

Tileset support? #4

Open zachcowell opened 3 years ago

zachcowell commented 3 years ago

Is there support for tilesets? I would like to create levels using a single tileset image and pass in indices of tile objects (instead of separate sprite images individually).

Great project btw! Very simple and fun to play with

slmjkdbtl commented 3 years ago

Not yet but definitely, I'll look into this next week!

slmjkdbtl commented 3 years ago

so right now the tileset related supports are:

  1. you can slice images into frames by sliceX and sliceY field in loadSprite()
    
    // slice the image into 12 x 3 = 36 frames with equal sizes
    loadSprite("tileset", "path_to_image.png", {
    sliceX: 12,
    sliceY: 3,
    });

// later in code...

add([ sprite("tileset", { frame: 12, }), ]);


2. manually pass in a `quad` field to `sprite()` component conf (just introduced to master in https://github.com/replit/kaboom/commit/e480fb5bf5c252b36e7325e79f83dc9c2f8d8c38)

```js
// will only draw the rectangle area of x: 0, y: 0, w: 0.2, h: 0.2 of the image
add([
    sprite("tileset", { quad: quad(0, 0, 0.2, 0.2), }),
]);

i don't have a lot of experience using tilemaps, curious to know if you have any ideal API in mind for a code-only solution

blurymind commented 3 years ago

does the slicer also support gaps between images? Sometimes free tilesets have:

Another exciting one to get would be animated tiles :)

they are fantastic for quick prototyping and gamejams btw. This capability will make kaboom the bomb on gamejam imo