Skip to content

Game making library for using Canvas element

Notifications You must be signed in to change notification settings

joski2490/notpygamejs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

notpygamejs

Game making library for Javascript with the Canvas element. Andrej Karpathy 1 May 2012

Usage

This library abstracts away boring stuff such as game loop, mouse, keyboard API calls, etc etc etc. All that is left to do is to implement the meat of the following functions:

//executes once in the beginning
function myinit(){ }

//executes every tick, FPS (typically around 30-50) times a second
function update(){ }

//executes every tick right after update()
function draw(){
    ctx.clearRect(0,0,WIDTH,HEIGHT);
}

//event function when a click occurs. x, y coordinates of click are given
function mouseClick(x, y){ }

//events for key up and down. key value is passed in.
function keyUp(key){ }
function keyDown(key){ }

The library assumes that your HTML file looks, for example as:

<body onLoad="NPGinit(50);">
<canvas id="NPGcanvas" width="500" height="500">Browser not supported for Canvas. Get a real browser.</canvas>

In other words, call NPGinit({#FPS}) function once somewhere in your code. The function will hook its functionality into a canvas on the page with id "NPGcanvas". Since this is not using any namespaces, a few things get added to global namespace (I know, I know...). For now, extra variables include:

var canvas;
var ctx;
var WIDTH;
var HEIGHT; 
var FPS;

The variable ctx will get instantiated to the canvas context that you should use for drawing. See demos for details.

License

BSD

About

Game making library for using Canvas element

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 85.8%
  • HTML 14.2%