-
Notifications
You must be signed in to change notification settings - Fork 10
Graphics Components
Rogan Murley edited this page Sep 25, 2015
·
11 revisions
Describes a sprite that does not animate.
var entity = new hitagi.Entity()
.attach(new hitagi.components.Position({
x: 0,
y: 0
}))
.attach(new hitagi.components.graphics.Graphic())
.attach(new hitagi.components.graphics.StaticSprite({
path: 'player.png'
}));
parameters:
params (object): {
path (string): path to load sprite asset from,
rotation (number) [default: 0]: sprite rotation in radians
}
path:
string
rotation:
number [default: 0]
Describes an animated sprite.
var entity = new hitagi.Entity()
.attach(new hitagi.components.Position({
x: 0,
y: 0
}))
.attach(new hitagi.components.graphics.Graphic())
.attach(new hitagi.components.graphics.Sprite({
path: 'player.png'
}));
parameters:
params (object): {
path (string): path to load sprite asset from,
animationSpeed (number) [default: 1]: animations frames to change per seconds
currentFrame (number) [default: 1]: current frame number,
loop (boolean) [default: true]: if animation replays after it finishes
rotation (number) [default: 0]: sprite rotation in radians
}
path:
string
frameCount:
number (READ-ONLY)
animationSpeed:
number [default: 1]
currentFrame:
number [default: 1]
loop:
boolean [default: true]
rotation:
number [default: 0]
Describes renderable text.
var entity = new hitagi.Entity()
.attach(new hitagi.components.graphics.Graphic())
.attach(new hitagi.components.graphics.Text({
copy: 'Hello, World!',
style: {
font: '72px monospace',
fill: 0x111222
}
}));
parameters:
params (object): {
copy (string): string of text to render
bitmapFont (boolean): if the font in style is a bitmapFont loaded
style (object): {
font (string): font description, for example '32px arial'
fill (string): name of fill color
}
}
copy:
string
bitmapFont:
boolean
style:
object: {
font (string) [default: '32px monospace'],
fill (hex number) [default: 0xffffff]
}
Describes a Rectangle primitive.
var entity = new hitagi.Entity()
.attach(new hitagi.components.Position({
x: 0,
y: 0
}))
.attach(new hitagi.components.graphics.Graphic())
.attach(new hitagi.components.graphics.Rectangle({
color: 0xffffff,
width: 32,
height: 32
}));
parameters:
params (object): {
color (hex number): primitive color hex code
width (number, positive): rectangle width,
height (number): rectangle height
}
color:
hex number
width:
number (positive)
height:
number (positive)
Describes a Polygon primitive.
var entity = new hitagi.Entity()
.attach(new hitagi.components.Position({
x: 0,
y: 0
}))
.attach(new hitagi.components.graphics.Graphic())
.attach(new hitagi.components.graphics.Polygon({
points: [
0, 0,
10, 10,
20, 20
]
}));
parameters:
params (object): {
points (array of numbers): arrays of alternating x and y co-ordinates of points
}
points:
array of numbers
Describes a Line primitive.
var entity = new hitagi.Entity()
.attach(new hitagi.components.Position({
x: 0,
y: 0
}))
.attach(new hitagi.components.graphics.Graphic())
.attach(new hitagi.components.graphics.Line({
x1: 0,
y1: 0,
x2: 100,
y2: 100,
thickness: 5
}));
parameters:
params (object): {
x1 (number): relative x co-ordinate of starting point
y1 (number): relative y co-ordinate of starting point
x2 (number): relative x co-ordinate of finishing point
y2 (number): relative y co-ordinate of finishing point
thickness (number, positive) [default: 1]: line thickness
}
x1:
number
y1:
number
x2:
number
y2:
number
thickness:
number, positive
Describes an Ellipse primitive.
var entity = new hitagi.Entity()
.attach(new hitagi.components.Position({
x: 0,
y: 0
}))
.attach(new hitagi.components.graphics.Graphic())
.attach(new hitagi.components.graphics.Ellipse({
color: 0xffffff,
width: 48,
height: 32
}));
parameters:
params (object): {
width (number, positive): width of the ellipse
height (number, positive): height of ellipse,
color (hex number): hex color
}
width:
number, positive
height:
number, positive
color:
hex number
Describes a Circle primitive.
var entity = new hitagi.Entity()
.attach(new hitagi.components.Position({
x: 0,
y: 0
}))
.attach(new hitagi.components.graphics.Graphic())
.attach(new hitagi.components.graphics.Circle({
color: 0xffffff,
radius: 16
}));
parameters:
params (object): {
color (hex number): hex color
radius (number, positive): circle radius
}
radius:
number, positive
color:
hex number