Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gfx-renderer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gfx-renderer

Provides boilerplate rendering code for canvas graphics

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

GFXRenderer

Provides boilerplate rendering code for canvas graphics

EcmaScript Module Usage

import GFXRenderer from "gfx-renderer";

const gfx = new GFXRenderer({
	canvas: document.getElementById("gfxRenderer")
	/*
    onRender:function(delta){},
    onResize:function(){},
    paused:true
    */
});

//Required function
gfx.onRender = function (delta) {
	const canvas = gfx.canvas;
	const context = gfx.context;

	//Update Position
	testPosition[0] += testSpeed[0] * delta;
	testPosition[1] += testSpeed[1] * delta;

	//Clear
	context.clearRect(0, 0, canvas.width, canvas.height);

	//Draw BG
	context.fillStype = "#000000";
	context.fillRect(0, 0, canvas.width, canvas.height);

	//Draw Circle
	context.save();
	context.fillStyle = "#FFFFFF";
	context.globalAlpha = 0.5;
	context.beginPath();
	context.arc(testPosition[0], testPosition[1], 64, 0, Math.PI << 1);
	context.fill();
	context.closePath();
	context.restore();
};

//Optional function
gfx.onResize = function (width, height) {
	console.log("resize", width, height);
};

CommonJS Usage

var gfx = new GFXRenderer({
	canvas: document.getElementById("gfxRenderer")
	/*
    onRender:function(delta){},
    onResize:function(){},
    paused:true
    */
});

//Required function
gfx.onRender = function (delta) {
	var canvas = gfx.canvas;
	var context = gfx.context;

	//Update Position
	testPosition[0] += testSpeed[0] * delta;
	testPosition[1] += testSpeed[1] * delta;

	//Clear
	context.clearRect(0, 0, canvas.width, canvas.height);

	//Draw BG
	context.fillStype = "#000000";
	context.fillRect(0, 0, canvas.width, canvas.height);

	//Draw Circle
	context.save();
	context.fillStyle = "#FFFFFF";
	context.globalAlpha = 0.5;
	context.beginPath();
	context.arc(testPosition[0], testPosition[1], 64, 0, Math.PI << 1);
	context.fill();
	context.closePath();
	context.restore();
};

//Optional function
gfx.onResize = function (width, height) {
	console.log("resize", width, height);
};

API

constructor({
	fps: 60,
	contextType: "2d",
	canvas: null, //Required
	context: null,
	paused: false,
	onRender: null
});
  • init()
  • destroy()
  • elapsed()
  • delta()
  • onRender = function(delta)
  • onResize = function(width, height)

Keywords

FAQs

Package last updated on 24 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc