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

Texture size must always be power of 2 #4

Open
trszdev opened this issue Feb 12, 2019 · 2 comments
Open

Texture size must always be power of 2 #4

trszdev opened this issue Feb 12, 2019 · 2 comments

Comments

@trszdev
Copy link

trszdev commented Feb 12, 2019

Code sample:

    import Renderer from 'js13k-2d'

    const scene = Renderer(canvas, { alpha: true })

    scene.background(0, 1, 0, 0.2)
    const atlas = scene.texture(createImageTexture(img), 0)
    const frame = atlas.frame(Renderer.Point(), atlas.size, Renderer.Point(0.5, 0.5))
    const sprites = []
    for (let i = 0; i < 0; i++) {
      const sprite = Renderer.Sprite(frame)
      sprite.rotation = Math.random() * 2 * Math.PI
      sprite.tint = Math.random() * 0xff0000
      scene.add(sprite)
      sprites.push(sprite)
    }
    scene.resize()
    scene.render()

Actual img size is (125px, 81px), so I need to use helper function createImageTexture

const createImageTexture = (img) => {
  const canvas = document.createElement('canvas')
  canvas.width = 1 << Math.ceil(Math.log2(img.width)) // eslint-disable-line
  canvas.height = 1 << Math.ceil(Math.log2(img.height)) // eslint-disable-line
  canvas.getContext('2d').drawImage(img, 0, 0)

  return canvas
}
@trszdev
Copy link
Author

trszdev commented Feb 12, 2019

and the actual image
selected_tile

@kutuluk
Copy link
Owner

kutuluk commented Feb 13, 2019

In the next release there will be dynamic atlases and the problem will be solved.

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

No branches or pull requests

2 participants