bear.js v0.1.3
bear.js
š» bear.js - game engine using pixi.js to render. Inspired by ELM and Phaser.
Install
Add bear.js with npm/yarn or use unpkg
Examples
Counter example, the very basics. Source
Pong built with bear.js. Source
Api
game
Game init function
Parameters
GameArgs
ObjectGameArgs.state
any Initial state of the gameGameArgs.update
function Returns a new state each frameGameArgs.render
function Returns an array of sprite/text each frameGameArgs.textures
Array<{name: string, url: string}> List of textures that will be loaded before the game starts (optional, default[]
)GameArgs.options
Object Game options (optional, default{}
)
landingpad
Node
Examples
import { game } from "bear.js"
Returns Promise<PIXI.Application>
_Point
Point class
Parameters
x
x position
Type: number
y
y position
Type: number
length
The length of the point
Returns number
setX
Returns a copy with its x value changed
Parameters
x
number
Returns _Point
setY
Returns a copy with its y value changed
Parameters
y
number
Returns _Point
normalize
Returns a normalized copy
Returns _Point
directionTo
Returns a normalized copy pointing towards the provided point
Parameters
otherPoint
_Point
Returns _Point
add
Returns a copy subtracted by the provided point
Parameters
otherPoint
_PointotherPoint.x
otherPoint.y
Returns _Point
subtract
Returns a copy subtracted by the provided point
Parameters
otherPoint
_PointotherPoint.x
otherPoint.y
multiply
Returns a copy multiplied by the provided point
Parameters
otherPoint
_PointotherPoint.x
otherPoint.y
divide
Returns a copy divided by the provided point
Parameters
otherPoint
_PointotherPoint.x
otherPoint.y
clampX
Returns a copy with x clamped between the provided min and max
Parameters
Returns _Point
clampY
Returns a copy with y clamped between the provided min and max
Parameters
Returns _Point
invertX
Returns a copy with x inverted
Returns _Point
invertY
Returns a copy with y inverted
Returns _Point
invert
Returns a copy with both x and y inverted
Returns _Point
Point
Parameters
Examples
import { Point } from "bear.js"
Returns _Point
_Rectangle
Rectangle class
Parameters
$0
any$0.position
$0.width
$0.height
position
Rectangle top left position
Type: _Point
width
Rectangle's width
Type: number
height
Rectangle's height
Type: number
left
x position at the left edge
Returns number
right
x position at the right edge
Returns number
top
y position at the top edge
Returns number
bottom
y position at the bottom edge
Returns number
center
Returns a copy with its x value changed
Returns _Point
intersects
Checks if the rectangle intersect with the provided one
Parameters
otherRectangle
_Rectangle
Returns boolean
Rectangle
Parameters
rectangleArgs
Object
Examples
import { Rectangle } from "bear.js"
Returns _Rectangle
sprite
Used in the render function
Parameters
spriteOptions
Object
Examples
import { sprite } from "bear.js"
Returns SpriteObject
text
Used in the render function
Parameters
textOptions
ObjecttextOptions.position
_PointtextOptions.anchor
_Point (optional, defaultPoint(0,0)
)textOptions.content
string Text to be displayedtextOptions.style
PIXI.TextStyle http://pixijs.download/release/docs/PIXI.TextStyle.html
Examples
import { text } from "bear.js"
Returns TextObject