new PhSim( [dynSimOptions])
Dynamic Simulation Instance Object
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
dynSimOptions |
DynSimOptions |
<optional> |
The simulation object |
- Mixes In:
- Source:
Classes
Mixins
Namespaces
Members
-
<static> statusStruct :Array.<String>
-
Structure giving more human-readable meaning to PhSim status.
Type:
- Array.<String>
- Source:
-
<static> version :String
-
PhSim version
Type:
- String
- Source:
-
audioPlayers :Number
-
Number of audio players. This is reset to 0 whenever PhSim#gotoSimulationIndex is executed.
Type:
- Number
- Source:
-
bgFillStyle :String
-
Background fill style for rendering. When PhSim#gotoSimulationIndex is run, the function sets this value to the value of PhSim.simOptions.box.bgColor if it is not a Falsey value;
Type:
- String
- Source:
-
canvas :HTMLCanvasElement
-
Simulation canvas
Type:
- HTMLCanvasElement
- Source:
-
classes :Object
-
Classes When PhSim#gotoSimulationIndex is run, this is blanked and repopulated.
Type:
- Object
- Source:
-
container :HTMLElement
-
The simulation container. This is is supposed to be the wrapping element of the PhSim canvas.
Type:
- HTMLElement
- Source:
-
ctx :CanvasRenderingContext2D
-
Simulation context for the canvas
Type:
- CanvasRenderingContext2D
- Source:
-
debugging :Object
-
Debugging Configuration
Type:
- Object
- Source:
-
debuggingData :Object
-
Debugging data
Type:
- Object
- Source:
-
delta
-
Number of frames per second
- Source:
-
dynTree :Array.<PhSimObjectArr>
-
An tree that is used to preserve layer distinctions. It is an array of arrays. The arrays in this array have PhSimObject objects. Resets when PhSim#gotoSimulationIndex is executed.
Type:
- Array.<PhSimObjectArr>
- Source:
-
eventStack :PhSim.EventStack
-
Object containing array functions to be called.
Type:
- Source:
-
eventStack :PhSim.EventStack
-
Global event stack
Type:
- Source:
-
init :Boolean
-
Boolean property for telling if the simulation has loaded a simulation at least one time.
Type:
- Boolean
- Source:
-
loading :Object
-
Loading screen properties
Type:
- Object
- Source:
Properties:
Name Type Argument Default Description bgColor
String <optional>
"black" Background Color
txtColor
String <optional>
"white" Text Color
txtFace
String <optional>
"arial" Text Face
txtAlign
String <optional>
"center" Text align
txt
String <optional>
"Loading..." Loading text
yPos
String <optional>
"center" y-position
txtSize
Number <optional>
20 Text size
-
magicWords
-
Object containing magic words
- Source:
-
matterJSEngine :Object
-
The matter.js engine Resets when PhSim#gotoSimulationIndex is executed.
Type:
- Object
- Source:
-
matterJSWorld :Object
-
The matter.js world Resets when PhSim#gotoSimulationIndex is executed.
Type:
- Object
- Source:
-
mouseX :Number
-
x-coordinate of the mouse
Type:
- Number
- Source:
-
mouseY :Number
-
y-coordinate of the mouse
Type:
- Number
- Source:
-
objUniverse :PhSimObjectArr
-
Array of objects in the PhSim simulation Resets when PhSim#gotoSimulationIndex is executed.
Type:
- Source:
-
paused :Boolean
-
Boolean property to tell if the simulation is paused or not.
Type:
- Boolean
- Source:
-
sim
-
Simulation options
- Deprecated:
-
- Due to confusing name.
- Source:
-
simulation
-
Current simulation options
- Deprecated:
-
- Due to confusing name.
- Source:
-
simulationEventStack :PhSim.EventStack
-
An array stack that is cleared each time the main simulation is changed.
Type:
- Source:
-
simulationEventStack :PhSim.EventStack
-
Event stack for simulation specfic events
Type:
- Source:
-
simulationIndex :Number
-
Index of the current simulation.
Type:
- Number
- Default Value:
-
- 0
- Source:
-
sl_time :Number
-
Time for inside the world
Type:
- Number
- Source:
-
staticSprites
-
Array of static sprite objects that are to be extracted by
- Source:
-
status :Number
-
Loading status of the dynamic simulation
Type:
- Number
- Source:
-
vars
-
Object containing variables that can be read by widgets such as the {@link|RectText} widget.
- Source:
-
wFunctions :Array.<WFunctions>
-
Array of widget functions
Type:
- Array.<WFunctions>
- Source:
Methods
-
<static> addGlobalMagicalWord(name, call)
-
Adds a global magical word function.
Parameters:
Name Type Description name
String Name of magical word
call
function - Source:
-
<static> calc_skinmesh(dynObject)
-
Calculate DynObject skinmesh
Parameters:
Name Type Description dynObject
PhSim.DynObject - Source:
-
<static> createFromCanvas(sim, canvas)
-
Parameters:
Name Type Description sim
Object canvas
HTMLCanvasElement - Source:
-
<static> createFromContainer(sim, container)
-
Parameters:
Name Type Description sim
Object container
HTMLElement - Source:
-
<static> diagRect(x1, y1, x2, y2)
-
Get Rectangle by diagonal with points (x1,y1) and (x2,y2);
Parameters:
Name Type Description x1
Number y1
Number x2
Number y2
Number - Source:
Returns:
- Rectangle Object
-
<static> gotoSimulationIndex(i)
-
Go to simulation in the composite simulation
In a PhSim object, there is a property known as PhSim.prototype.sim. This property is used to define a simulation.
When PhSim.prototype.gotoSimulationIndex is used, it resets
This:
Parameters:
Name Type Description i
Number - Source:
Returns:
- A promise that is fulfiled if the loading is successful.
- Type
- Promise
-
<static> loadFromJSON(jsonURL, onload)
-
Parameters:
Name Type Description jsonURL
String URL For JSON File
onload
function Onload function
- Source:
-
<static> Widget(onextraction)
-
Widget Object
Parameters:
Name Type Description onextraction
function - Source:
-
addKeyboardControls(dynObj, keyboardControls)
-
The
keyboardControls
widget is a widget that makes an object go at a certain velocity if the arrow keys are pressed.Parameters:
Name Type Description dynObj
PhSim.DynObject keyboardControls
Object Keyboard Controls options
Properties
Name Type Description right
Number Velocity in the right direction if the right key is pressed.
up
NUmber Velocity in the up direction if the up key is pressed.
left
Number Velocity in the left direction if the left key is pressed.
down
Number Velocity in the down direction if the down key is pressed.
- Source:
-
addLocalMagicalWord(name, call)
-
Adds a local magical word function.
Parameters:
Name Type Description name
String Name of magical word
call
function - Source:
-
addObject(o, options)
-
Add Object to PhSim simulation
Parameters:
Name Type Description o
PhSimObject options
Object Properties
Name Type Description layer
Number - Source:
Returns:
- The added dynObject.
- Type
- PhSim.DynObject
-
addToOverlayer(dynObject)
-
Add object to over layer.
Parameters:
Name Type Description dynObject
PhSim.DynObject - Source:
-
alert(options)
-
Parameters:
Name Type Description options
Object Options
Properties
Name Type Description msg
String The message
closeButtonTxt
String Inner text for closing button
bgColor
String Background Color
txtColor
String Text Color
w
Number Width
h
Number Height
onok
function Function to call when alert is closed
- Source:
-
applyGravitationalField()
-
Apply Newtonian gravity field.
- Source:
-
assignPhRender(phRender)
-
Assign PhRender to PhSim simulation
Parameters:
Name Type Description phRender
PhSim.PhRender - Source:
-
callEventClass(event)
-
Parameters:
Name Type Description event
PhSim.Events.PhSimEvent Event Object
- Mixes In:
- Source:
-
callObjLinkFunctions(dynObject)
-
Call ObjLink functions
Parameters:
Name Type Description dynObject
PhSim.DynObject - Source:
-
cloneObject(dynObject, options)
-
Clone object
Parameters:
Name Type Description dynObject
PhSim.DynObject options
Object The options used for creating a spawned object
Properties
Name Type Description velocity
Vector The velocity to add to an object when it got spawned.
- Source:
-
collided(dynObjectA, dynObjectB)
-
Check if two objects are colliding
Parameters:
Name Type Description dynObjectA
PhSim.DynObject dynObjectB
PhSim.DynObject - Source:
Returns:
- Type
- Boolean
-
configFilter(container)
-
Config filter
Parameters:
Name Type Description container
HTMLElement - Source:
-
configRender()
-
- Source:
-
connectCanvas(canvas)
-
Connect an HTML canvas to the PhSim simulation object.
Parameters:
Name Type Description canvas
HTMLCanvasElement - Source:
-
connectContainer(c)
-
Connect a container for the PhSim simulation object. The PhSim canvas is supposed to be the only child element of the container.
When set, the container has the simulation canvas appened as a child.
Parameters:
Name Type Description c
HTMLElement Container
- Source:
-
createCircularConstraint(dynObject [, x] [, y])
-
Create circular constraint
Parameters:
Name Type Argument Description dynObject
PhSim.DynObject x
Number <optional>
x position of vector.
y
Number <optional>
y position of vector.
- Source:
-
createMotionFunction(mode, dyn_object, motion)
-
Generate a function to put some dynamic object in motion, given some mode and vector or scalar.
Parameters:
Name Type Description mode
"setAngle" | "force" | "velocity" | "translate" | "position" | "rotation" | "circular_constraint_rotation" The possible modes are "force","velocity","translate"
dyn_object
dyn_object The dynamic object to put in motion.
motion
Vector | Number The vector or scalar that defines the motion.
- Source:
Returns:
- A function that makes an object undergo some motion.
- Type
- function
-
createWFunction(trigger, wFunctionBody, options)
-
Function used to generate WFunctions. To learn more, see the Widget Functions tutorial.
This:
- {PhSim}
Parameters:
Name Type Description trigger
wFunctionTrigger The type of SimpleEvent.
wFunctionBody
WFunctionBody | Number The JavaScript function to be wrapped. If
wFunctionBody
is an integeri
, the function body is deterimined by thePhSim#options.wFunctions[i]
options
WFunctionOptions The Simple Event Options Object.
- Source:
Returns:
- The wFunction.
- Type
- WFunction
-
disableFilter()
-
Disable filter
- Source:
-
disableWFunction(o)
-
Disable wFunction
Parameters:
Name Type Description o
WFunction Reference created by PhSim#createWFunction.
- Source:
-
dispatchClick(e)
-
Parameters:
Name Type Description e
external:MouseEvent - Source:
Fires:
- Events#event:click
- Events#event:objclick
-
dispatchMouseDown(e)
-
This:
- HTMLCanvasElement
Parameters:
Name Type Description e
external:MouseEvent MouseEvent object
- Source:
Fires:
- Events#event:mousedown
- Events#event:objmousedown
-
dispatchMouseMove(e)
-
Dispatch
mousemove
event.Parameters:
Name Type Description e
external:MouseEvent Standard MouseEvent Javascript object
- Source:
Fires:
- PhSim.Events#event:objmousemove
- PhSim.Events#event:objmouseover
- PhSim.Events#event:objmouseout
- PhSim.Events#event:mousemove
-
drawLoadingScreen()
-
The
drawLoadingScreen
function draws the loading screen for a simulation change. The behaviour of the loading screen can be customized by modifing the properties of PhSim#loading.- Source:
-
enableFilter()
-
Enable filter
- Source:
-
exit()
-
Completely reset PhSim object. That is, make it as if it is a new one.
- Source:
Returns:
- Type
- Promise
-
exitSl()
-
Exit simulation
- Source:
-
extractWidget(widget, dyn_object)
-
Extract Widgets from Dynamic Object. To extract a widget in PhSim is to read all of the objects in the "widgets" array found in each well-formed PhSim object and then translate it into JavaScript.
Parameters:
Name Type Description widget
WidgetOptions The Widget
dyn_object
PhSim.DynObject The individual Dynamic Object
- Source:
Returns:
undefined
-
extractWidgets(dyn_object)
-
Extract all widgets from a dynamic object.
Parameters:
Name Type Description dyn_object
PhSim.DynObject - Source:
-
forAllObjects(call)
-
Run function on all objects.
Parameters:
Name Type Description call
function - Source:
-
getCollidingObjects(dynObject)
-
Get array of Dynamic Object colliding some specified colliding object.
Parameters:
Name Type Description dynObject
PhSim.DynObject Dynamic Object
- Source:
Returns:
- Type
- Array.<PhSim.DynObject>
-
getCollidingSensorObjects(dynObject)
-
Get objects colliding some object that share the same sensor classes.
Parameters:
Name Type Description dynObject
PhSim.DynObject Object to check for colliding sensor objects
- Source:
Returns:
- Type
- Array.<PhSim.DynObject>
-
getCollisionChecker(dynObjectA, dynObjectB)
-
Get object that checks the collision relations between two objects
Parameters:
Name Type Description dynObjectA
PhSim.DynObject The first object
dynObjectB
PhSim.DynObject The second object
- Source:
Returns:
- A collision report that updates itself after each update
- Type
- PhSim.CollisionReport
-
getCollisionList(dynObject)
-
Get the collison pairs that contain a certain object
Parameters:
Name Type Description dynObject
PhSim.DynObject - Source:
Returns:
- Type
- Array.<PhSim.phSimCollision>
-
getDynObjectByID(idNum)
-
Get object by ID
Parameters:
Name Type Description idNum
String - Source:
Returns:
- Type
- PhSim.DynObject
-
getEventBridge(f)
-
Create a wrapping function that is used for events.
Parameters:
Name Type Description f
function Function
- Source:
-
getObjectByName(str)
-
Get object by name in PhSim simulation
Parameters:
Name Type Description str
String String for the name
- Source:
Returns:
- Returns the object if found, but returns "null" object if not.
- Type
- PhSimObject | null
-
getObjectFromLOStr(str)
-
Parameters:
Name Type Description str
LOStr - Source:
Returns:
- Type
- PhSimObject
-
getStatic(dynObject)
-
Get static object of a dynamic object
Parameters:
Name Type Description dynObject
PhSim.DynObject The dynamic object
- Source:
-
getStatusStr()
-
Get the status string of the the dynamic simulation
- Source:
-
getUniversalObjArray()
-
- Source:
-
inSensorCollision(dynObject)
-
Parameters:
Name Type Description dynObject
PhSim.DynObject - Source:
Returns:
- Type
- Boolean
-
isInCollision(dynObject)
-
Check if an object is in a collision
Parameters:
Name Type Description dynObject
PhSim.DynObject - Source:
Returns:
- Type
- Boolean
-
isNonDyn(o)
-
Check if the object is a dynamic object.
Parameters:
Name Type Description o
PhSimObject - Source:
-
L(L)
-
Parameters:
Name Type Description L
Number - Source:
-
LO(L, O)
-
Parameters:
Name Type Description L
Number O
Number - Source:
-
loopFunction()
-
The loopFunction is a function that is executed over and over again. It is responsible for providing the simulation loop.
- Source:
-
off(eventStr, call)
-
Parameters:
Name Type Description eventStr
String call
PhSimEventCall - Mixes In:
- Source:
-
on(eventStr, call [, options])
-
Used to add events to a PhSim simulation
Parameters:
Name Type Argument Default Description eventStr
string String representing the event.
call
PhSimEventCall Function to run when event is executed.
options
object <optional>
{} Event Listener Options.
Properties
Name Type Argument Description once
boolean <optional>
If true, the function is executed only once.
slEvent
boolean <optional>
If true, the event will be removed when the simulation changes
- Mixes In:
- Source:
-
pause()
-
Pause simulation
- Source:
Returns:
- A promise that is fulfilled if the pausing the simulation is sucessful.
If resolved, the promise is fullfilled with the
PhSim
instance as its value.
- Type
- Promise
-
pauseAudioByIndex(i)
-
Pause audio by index. Alternative function: PhSim.Audio#pauseAudioByIndex
Parameters:
Name Type Description i
Number - Source:
-
play()
-
Play simulation
This:
- Source:
Returns:
- A promise that is fulfilled if the playing the simulation is sucessful.
If resolved, the promise is fullfilled with the
PhSim
instance as its value.
- Type
- Promise
-
playAudioByIndex(phsim, i)
-
Play audio by index Alternative function: PhSim.Audio#playAudioByIndex
Parameters:
Name Type Description phsim
PhSim PhSim instance.
i
Number Index in audio array.
- Source:
Returns:
- Promise that is fulfilled when the audio is played.
- Type
- Promise
-
pointObjArray(x, y)
-
Get array of objects that contain a certain point
Parameters:
Name Type Description x
Number x-coordinate
y
Number y-coordinate
- Source:
Returns:
- Type
- Array.<PhSim.DynObject>
-
processVar(str)
-
Process string by replacing magical words and the values of elements in PhSim.prototype.vars.
Some of the magic words are the following:
{__game__score}
- The game score{__game__life}
- The game life{__game__goal}
- The game goal{__game__int_life}
- The inital life value for the gameThe expression
${key}
is replaced by the value ofPhSim.prototype.vars[key]
.Parameters:
Name Type Description str
String - Source:
Returns:
- Type
- String
-
registerCanvasEvents()
-
Used to set event listeners for a canvas. This function works if PhSim.prototype#ctx and PhSim.prototype#canvas are set.
This:
- Source:
-
removeDynObj(dynObject)
-
Remove dynamic object
Parameters:
Name Type Description dynObject
PhSim.DynObject Dynamic Object
- Source:
Returns:
- The removed Dynamic Object
- Type
- PhSim.DynObject
-
setAudioMuteByIndex(phsim)
-
Mute the
i
th element of the audio array.Alternative function: PhSim.Audio#setAudioMuteByIndex
Parameters:
Name Type Description phsim
PhSim PhSim instance
- Source:
-
setAudioVolByIndex(i, v)
-
Set volume by index Alternative function: PhSim.Audio#setAudioVolByIndex
Parameters:
Name Type Description i
Number Index
v
Number Volume
- Source:
-
setDynObjectLifespan(dynObject, lifespan)
-
Set Object Lifespan
Parameters:
Name Type Description dynObject
* Dynamic Object
lifespan
Number Milliseconds
- Source:
-
setLock(dynObject, value)
-
Set lock of the Dynamic Object
Parameters:
Name Type Description dynObject
PhSim.DynObject value
Boolean If
true
, lock. Otherwise, unlock.- Source:
-
toggle()
-
Toggle Simulation
- Source:
Returns:
- Type
- Promise
-
toggleAudioByIndex(i)
-
Parameters:
Name Type Description i
Number - Source:
Returns:
- True if paused, false otherwise.
- Type
- Boolean
-
toggleFilter()
-
Toggle filter
- Source:
-
toggleLock(dynObject)
-
Toggle Lock Status of Dynamic Object.
Parameters:
Name Type Description dynObject
PhSim.DynObject - Source:
-
toggleSemiLock(dynObject)
-
Toggle Semi-Lock Status of Dynamic Object.
Parameters:
Name Type Description dynObject
PhSim.DynObject - Source:
-
updateDynObj(currentObj)
-
Update a dynamic object.
Parameters:
Name Type Description currentObj
PhSimObject Object to be updated
- Source:
Fires:
- PhSim.Events.event:PhSimEvent
-
wFunctionRefs(arg, thisRef)
-
Create a widget function and push it to the wFunctions array.
Parameters:
Name Type Description arg
String | function content of function if string, function if function
thisRef
Object - Source:
Returns:
- Type
- WFunction
Type Definitions
-
options
-
The static simulation object
Type:
- Source: