kutuluk / js13k-2d Goto Github PK
View Code? Open in Web Editor NEWA 2kb webgl 2d sprite renderer, designed for Js13kGames
Home Page: https://kutuluk.github.io/js13k-2d
License: MIT License
A 2kb webgl 2d sprite renderer, designed for Js13kGames
Home Page: https://kutuluk.github.io/js13k-2d
License: MIT License
What is the point of using plain integers for representing some if not all of the used OpenGL constants such as GL_TEXTURE_WRAP_S ?
Example: https://github.com/kutuluk/js13k-2d/blob/master/src/renderer.js#L123
I don't know much about WebGL, but if there's a chance that they might not be defined on some weird browsers or something, I think the right thing to do would maybe be to inject the values manually to the gl object in that case?
Using plain integers like that is very confusing.
I see there is a scale property, but can I directly specify the size?
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
}
Why are all the existing error checks commented out at the moment?
Example: https://github.com/kutuluk/js13k-2d/blob/master/src/renderer.js#L37
If an error occurs with for example OpenGL, I think it should be treated somehow by the lib so that the user of the library can catch it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.