npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gl-basic-tile-map

v0.0.0

Published

Draws 2D tile maps using WebGL

Downloads

7

Readme

gl-basic-tile-map

Simple 2D tile map renderer in WebGL.

Example

var shell = require("gl-now")()
var ndarray = require("ndarray")
var tileMap = require("isabella-texture-pack")
var createTexture = require("gl-texture2d")
var glm = require("gl-matrix")
var createTileMap = require("gl-basic-tile-map")
var mat3 = glm.mat3

var tiles = ndarray(new Uint8Array(128*128*2), [128,128,2])
var cameraPosition = [0,0]
var cameraScale = 0.01
var tileMap

shell.on("gl-init", function() {
  var gl = shell.gl
  
  var tileSheet = createTexture(gl, tileMap)
  tileMap = createTileMap(gl, tileSheet, tiles, [16,16])
  
  //Randomize all the tiles every second
  setInterval(function() {
    for(var i=0; i<128; ++i) {
      for(var j=0; j<128; ++j) {
        tiles.set(i, j, 0, (Math.random()*16)|0)
        tiles.set(i, j, 1, (Math.random()*16)|0)
      }
    }
    tileMap.update(tiles)
  }, 1000)
})

shell.on("gl-render", function() {
  var view = [cameraScale, 0, 0,
              0, cameraScale, 0,
              cameraPosition[0], cameraPosition[1], 1]
  tileMap.draw(view)
})

shell.on("tick", function() {
  if(shell.wasDown("mouse-1")) {
    cameraPosition[0] += (shell.mouseX - shell.prevMouseX) / shell.width
    cameraPosition[1] -= (shell.mouseY - shell.prevMouseY) / shell.height
  }
  if(shell.scroll[1]) {
    cameraScale *= Math.exp(shell.scroll[1] / shell.height)
  }
})

Try it out now in your browser

Install

npm install gl-basic-tile-map

API

Constructor

var createTileMap = require("gl-basic-tile-map")

var tileMap = createTileMap(gl, tileSheet, tileData, tileShape)

Creates a tile map object.

  • gl is a handle to a WebGL context
  • tileSheet is an instance of a gl-texture2d object
  • tileData is an [m,n,2] shaped ndarray
  • tileShape is a length 2 array describing the size of each tile

Returns A TileMap object

TileMap Methods

tileMap.draw(view)

Draws the tilemap with the given view matrix. view is a homography represented by a 3x3 matrix giving the transformation from the world coordinates to the viewing frustum, which is in the coordinate system [-1,1] x [-1,1].

tileMap.update(data[, x, y])

Updates a region of the underlying tileIds.

  • data is an ndarray containing the new pixels to update
  • x is the x-offset of the region to update
  • y is the y-offset of the region to update

tileMap.dispose()

Releases the resources associated with the tile map object.

Credits

(c) 2013 Mikola Lysenko. MIT License