Interface: FGame
Callable#
FGame#
â–¸ FGame(selector): Entity[]
Parameters#
| Name | Type |
|---|---|
selector | string |
Returns#
Entity[]
Defined in#
Properties#
fps#
• fps: number
Defined in#
math#
• math: Math
Defined in#
rectManager#
• rectManager: any
Defined in#
viewport#
• viewport: Viewport
Defined in#
Methods#
UID#
â–¸ UID(): any
Returns#
any
Defined in#
background#
â–¸ background(color): FGame
Set background color to html color name.
Parameters#
| Name | Type |
|---|---|
color | string |
Returns#
Defined in#
c#
â–¸ c<T>(name, component): T
Create a component.
Type parameters#
| Name | Type |
|---|---|
T | extends Component |
Parameters#
| Name | Type | Description |
|---|---|---|
name | string | name of the new component |
component | T | component object data |
Returns#
T
Defined in#
cc#
â–¸ cc<T>(component): T
Create a component.
Type parameters#
| Name | Type |
|---|---|
T | extends CComponent |
Parameters#
| Name | Type | Description |
|---|---|---|
component | CComponent | componenent object data |
Returns#
T
Defined in#
e#
â–¸ e<T>(components): T
Type parameters#
| Name | Type |
|---|---|
T | extends Entity<T> |
Parameters#
| Name | Type |
|---|---|
components | string |
Returns#
T
Defined in#
init#
â–¸ init(width?, height?, element?): FGame
Parameters#
| Name | Type |
|---|---|
width? | number |
height? | number |
element? | null | string | HTMLElement |
Returns#
Defined in#
isPaused#
â–¸ isPaused(): boolean
Returns#
boolean
Defined in#
loadPlugin#
â–¸ loadPlugin(plugin): FPlugin
Parameters#
| Name | Type |
|---|---|
plugin | FPlugin |
Returns#
Defined in#
pause#
â–¸ pause(toggle?): FGame
Pauses the game by stopping the UpdateFrame event from firing. If the game is already paused it is unpaused.
You can pass a boolean parameter if you want to pause or unpause no matter what the current state is.
Modern browsers pauses the game when the page is not visible to the user. If you want the Pause event
to be triggered when that happens you can enable autoPause in Crafty.settings.
Parameters#
| Name | Type |
|---|---|
toggle? | boolean |
Returns#
Defined in#
s#
â–¸ s<T>(name, template?): T
Registers a system.
Triggers Events
"SystemLoaded", this- When the system has initialized itself"SystemDestroyed", this- Right before the system is destroyed
Objects which handle entities might want to subscribe to the event system without being entities themselves.
When you declare a system with a template object, all the methods and properties of that template are copied to a new object.
This new system will automatically have the following event related methods, which function like those of components:
.bind(), unbind(), trigger(), one(), uniqueBind(), destroy().
Much like components, you can also provide init() and remove() methods,
a properties dictionary which will be used to define properties with Object.defineProperty,
as well as an events parameter for automatically binding to events.
note The init() method is for setting up the internal state of the system,
if you create entities in it that then reference the system, that'll create an infinite loop.
Type parameters#
| Name |
|---|
T |
Parameters#
| Name | Type |
|---|---|
name | string |
template? | T |
Returns#
T
Defined in#
stop#
â–¸ stop(clearState?): FGame
Stops the UpdateFrame interval and removes the stage element.
To restart, use Crafty.init().
Parameters#
| Name | Type | Description |
|---|---|---|
clearState? | boolean | if true the stage and all game state is cleared. |
Returns#
Defined in#
trigger#
â–¸ trigger(event, data): void
Trigger event
Parameters#
| Name | Type | Description |
|---|---|---|
event | string | name of event |
data | any | data to pass |
Returns#
void