Class enchant.Core
A class for controlling the core’s main loop and scenes. There can be only one instance at a time. When the constructor is executed while an instance exists, the existing instance will be overwritten. The existing instance can be accessed from enchant.Core.instance.
- Defined in: enchant.js
- Extends enchant.EventTarget
Constructor Attributes | Constructor Name and Description |
---|---|
enchant.Core(width, height)
|
Field Attributes | Field Name and Description |
---|---|
Object which stores loaded assets using their paths as keys.
|
|
The Scene which is currently displayed.
|
|
The frame rate of the core.
|
|
The number of frames processed since the core was started.
|
|
The height of the core screen.
|
|
Object that saves the current input state for the core.
|
|
<static> |
enchant.Core.instance
The current Core instance.
|
The Scene to be displayed during loading.
|
|
Indicates whether or not the core can be executed.
|
|
The root Scene.
|
|
Indicates whether or not the core is currently running.
|
|
The scaling of the core rendering.
|
|
The width of the core screen.
|
Method Summary
Method Attributes | Method Name and Description |
---|---|
debug()
Start application in debug mode.
|
|
<static> |
enchant.Core.findExt(path)
Get the file extension from a path.
|
Get the core time (not actual) elapsed since enchant.Core#start was called.
|
|
<static> |
enchant.Core.initialize(array)
|
keybind(key, button)
Bind a key code to an enchant.js button.
|
|
keyunbind(key)
Delete the key binding for the given key.
|
|
load(src, alias, callback, onerror)
Loads a file.
|
|
pause()
Stops the core.
|
|
popScene()
Ends the current Scene and returns to the previous Scene.
|
|
preload(assets)
File preloader.
|
|
pushScene(scene)
Switches to a new Scene.
|
|
removeScene(scene)
Removes a Scene from the Scene stack.
|
|
replaceScene(scene)
Overwrites the current Scene with a new Scene.
|
|
resume()
Resumes core operations.
|
|
start(deferred)
Start the core.
|
|
stop()
Stops the core.
|
|
Perform popScene with transition animation.
|
|
transitionPush(inScene)
Perform pushScene with transition animation.
|
- Methods borrowed from class enchant.EventTarget:
- addEventListener
- clearEventListener
- dispatchEvent
- on
- removeEventListener
Class Detail
enchant.Core(width, height)
- Parameters:
- {Number} width Optional, Default: 320
- The width of the core viewport.
- {Number} height Optional, Default: 320
- The height of the core viewport.
Field Detail
{Object}
assets
Object which stores loaded assets using their paths as keys.
{enchant.Scene}
currentScene
The Scene which is currently displayed. This Scene is on top of the Scene stack.
{Number}
fps
The frame rate of the core.
{Number}
frame
The number of frames processed since the core was started.
{Number}
height
The height of the core screen.
{Object}
input
Object that saves the current input state for the core.
The current Core instance.
{enchant.Scene}
loadingScene
The Scene to be displayed during loading.
{Boolean}
ready
Indicates whether or not the core can be executed.
{enchant.Scene}
rootScene
The root Scene. The Scene at the bottom of the Scene stack.
{Boolean}
running
Indicates whether or not the core is currently running.
{Number}
scale
The scaling of the core rendering.
{Number}
width
The width of the core screen.
Method Detail
-
{enchant.Deferred} debug()Start application in debug mode. Core debug mode can be turned on even if the enchant.Core#_debug flag is already set to true.
- Returns:
- {enchant.Deferred}
-
<static> {*} enchant.Core.findExt(path)Get the file extension from a path.
- Parameters:
- {String} path
- file path.
- Returns:
- {*}
-
{Number} getElapsedTime()Get the core time (not actual) elapsed since enchant.Core#start was called.
- Returns:
- {Number} Time elapsed (in seconds).
-
<static> enchant.Core.initialize(array)
Defined in: widget.enchant.js.- Parameters:
- array
-
{enchant.Core} keybind(key, button)Bind a key code to an enchant.js button. Binds the given key code to the given enchant.js button ('left', 'right', 'up', 'down', 'a', 'b').
- Parameters:
- {Number} key
- Key code for the button to be bound.
- {String} button
- An enchant.js button.
- Returns:
- {enchant.Core} this
-
{enchant.Core} keyunbind(key)Delete the key binding for the given key.
- Parameters:
- {Number} key
- Key code whose binding is to be deleted.
- Returns:
- {enchant.Core} this
-
{enchant.Deferred} load(src, alias, callback, onerror)Loads a file.
- Parameters:
- {String} src
- File path of the resource to be loaded.
- {String} alias Optional
- Name you want to designate for the resource to be loaded.
- {Function} callback Optional
- Function to be called if the file loads successfully.
- {Function} onerror Optional
- Function to be called if the file fails to load.
- Returns:
- {enchant.Deferred}
-
pause()Stops the core. The frame will not be updated, and player input will not be accepted anymore. Core can be started again using enchant.Core#resume.
-
{enchant.Scene} popScene()Ends the current Scene and returns to the previous Scene. Scenes are controlled using a stack, with the top scene on the stack being the one displayed. When enchant.Core#popScene is executed, the Scene at the top of the stack is removed and returned.
- Returns:
- {enchant.Scene} Removed Scene.
-
{enchant.Core} preload(assets)File preloader. Loads the files specified in the parameters when enchant.Core#start is called. When all files are loaded, a enchant.Event.LOAD event is dispatched from the Core object. Depending on the type of each file, different objects will be created and stored in enchant.Core#assets Variable. When an image file is loaded, a enchant.Surface is created. If a sound file is loaded, an enchant.Sound object is created. Any other file type will be accessible as a string. In addition, because this Surface object is created with enchant.Surface.load, it is not possible to manipulate the image directly. Refer to the enchant.Surface.load documentation.
core.preload('player.gif'); core.onload = function() { var sprite = new Sprite(32, 32); sprite.image = core.assets['player.gif']; // Access via path ... }; core.start();
- Parameters:
- {...String|String[]} assets
- Path of images to be preloaded. Multiple settings possible.
- Returns:
- {enchant.Core} this
-
{enchant.Scene} pushScene(scene)Switches to a new Scene. Scenes are controlled using a stack, with the top scene on the stack being the one displayed. When enchant.Core#pushScene is executed, the Scene is placed top of the stack. Frames will be only updated for the Scene which is on the top of the stack.
- Parameters:
- {enchant.Scene} scene
- The new scene to display.
- Returns:
- {enchant.Scene} The new Scene.
-
{enchant.Scene} removeScene(scene)Removes a Scene from the Scene stack. If the scene passed in as a parameter is not the current scene, the stack will be searched for the given scene. If the given scene does not exist anywhere in the stack, this method returns null.
- Parameters:
- {enchant.Scene} scene
- Scene to be removed.
- Returns:
- {enchant.Scene} The deleted Scene.
-
{enchant.Scene} replaceScene(scene)Overwrites the current Scene with a new Scene. Executes enchant.Core#popScene and enchant.Core#pushScene one after another to replace the current scene with the new scene.
- Parameters:
- {enchant.Scene} scene
- The new scene with which to replace the current scene.
- Returns:
- {enchant.Scene} The new Scene.
-
resume()Resumes core operations.
-
{enchant.Deferred} start(deferred)Start the core. Sets the framerate of the enchant.Core#currentScene according to the value stored in enchant.core#fps. If there are images to preload, loading will begin and the loading screen will be displayed.
- Parameters:
- deferred
- Returns:
- {enchant.Deferred}
-
stop()Stops the core. The frame will not be updated, and player input will not be accepted anymore. Core can be restarted using enchant.Core#resume.
-
{enchant.Scene} transitionPop()Perform popScene with transition animation.
Defined in: widget.enchant.js.- Returns:
- {enchant.Scene} Finished scene.
- Requires:
- widget.enchant.js
-
{enchant.Scene} transitionPush(inScene)Perform pushScene with transition animation.
Defined in: widget.enchant.js.- Parameters:
- {enchant.Scene} inScene
- New scene transitioned to.
- Returns:
- {enchant.Scene} New scene
- Requires:
- widget.enchant.js