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 bgColorString <optional>
"black" Background Color
txtColorString <optional>
"white" Text Color
txtFaceString <optional>
"arial" Text Face
txtAlignString <optional>
"center" Text align
txtString <optional>
"Loading..." Loading text
yPosString <optional>
"center" y-position
txtSizeNumber <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 nameString Name of magical word
callfunction - Source:
-
<static> calc_skinmesh(dynObject)
-
Calculate DynObject skinmesh
Parameters:
Name Type Description dynObjectPhSim.DynObject - Source:
-
<static> createFromCanvas(sim, canvas)
-
Parameters:
Name Type Description simObject canvasHTMLCanvasElement - Source:
-
<static> createFromContainer(sim, container)
-
Parameters:
Name Type Description simObject containerHTMLElement - Source:
-
<static> diagRect(x1, y1, x2, y2)
-
Get Rectangle by diagonal with points (x1,y1) and (x2,y2);
Parameters:
Name Type Description x1Number y1Number x2Number y2Number - 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 iNumber - Source:
Returns:
- A promise that is fulfiled if the loading is successful.
- Type
- Promise
-
<static> loadFromJSON(jsonURL, onload)
-
Parameters:
Name Type Description jsonURLString URL For JSON File
onloadfunction Onload function
- Source:
-
<static> Widget(onextraction)
-
Widget Object
Parameters:
Name Type Description onextractionfunction - Source:
-
addKeyboardControls(dynObj, keyboardControls)
-
The
keyboardControlswidget is a widget that makes an object go at a certain velocity if the arrow keys are pressed.Parameters:
Name Type Description dynObjPhSim.DynObject keyboardControlsObject Keyboard Controls options
Properties
Name Type Description rightNumber Velocity in the right direction if the right key is pressed.
upNUmber Velocity in the up direction if the up key is pressed.
leftNumber Velocity in the left direction if the left key is pressed.
downNumber 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 nameString Name of magical word
callfunction - Source:
-
addObject(o, options)
-
Add Object to PhSim simulation
Parameters:
Name Type Description oPhSimObject optionsObject Properties
Name Type Description layerNumber - Source:
Returns:
- The added dynObject.
- Type
- PhSim.DynObject
-
addToOverlayer(dynObject)
-
Add object to over layer.
Parameters:
Name Type Description dynObjectPhSim.DynObject - Source:
-
alert(options)
-
Parameters:
Name Type Description optionsObject Options
Properties
Name Type Description msgString The message
closeButtonTxtString Inner text for closing button
bgColorString Background Color
txtColorString Text Color
wNumber Width
hNumber Height
onokfunction 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 phRenderPhSim.PhRender - Source:
-
callEventClass(event)
-
Parameters:
Name Type Description eventPhSim.Events.PhSimEvent Event Object
- Mixes In:
- Source:
-
callObjLinkFunctions(dynObject)
-
Call ObjLink functions
Parameters:
Name Type Description dynObjectPhSim.DynObject - Source:
-
cloneObject(dynObject, options)
-
Clone object
Parameters:
Name Type Description dynObjectPhSim.DynObject optionsObject The options used for creating a spawned object
Properties
Name Type Description velocityVector 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 dynObjectAPhSim.DynObject dynObjectBPhSim.DynObject - Source:
Returns:
- Type
- Boolean
-
configFilter(container)
-
Config filter
Parameters:
Name Type Description containerHTMLElement - Source:
-
configRender()
-
- Source:
-
connectCanvas(canvas)
-
Connect an HTML canvas to the PhSim simulation object.
Parameters:
Name Type Description canvasHTMLCanvasElement - 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 cHTMLElement Container
- Source:
-
createCircularConstraint(dynObject [, x] [, y])
-
Create circular constraint
Parameters:
Name Type Argument Description dynObjectPhSim.DynObject xNumber <optional>
x position of vector.
yNumber <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_objectdyn_object The dynamic object to put in motion.
motionVector | 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 triggerwFunctionTrigger The type of SimpleEvent.
wFunctionBodyWFunctionBody | Number The JavaScript function to be wrapped. If
wFunctionBodyis an integeri, the function body is deterimined by thePhSim#options.wFunctions[i]optionsWFunctionOptions The Simple Event Options Object.
- Source:
Returns:
- The wFunction.
- Type
- WFunction
-
disableFilter()
-
Disable filter
- Source:
-
disableWFunction(o)
-
Disable wFunction
Parameters:
Name Type Description oWFunction Reference created by PhSim#createWFunction.
- Source:
-
dispatchClick(e)
-
Parameters:
Name Type Description eexternal:MouseEvent - Source:
Fires:
- Events#event:click
- Events#event:objclick
-
dispatchMouseDown(e)
-
This:
- HTMLCanvasElement
Parameters:
Name Type Description eexternal:MouseEvent MouseEvent object
- Source:
Fires:
- Events#event:mousedown
- Events#event:objmousedown
-
dispatchMouseMove(e)
-
Dispatch
mousemoveevent.Parameters:
Name Type Description eexternal: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
drawLoadingScreenfunction 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 widgetWidgetOptions The Widget
dyn_objectPhSim.DynObject The individual Dynamic Object
- Source:
Returns:
undefined
-
extractWidgets(dyn_object)
-
Extract all widgets from a dynamic object.
Parameters:
Name Type Description dyn_objectPhSim.DynObject - Source:
-
forAllObjects(call)
-
Run function on all objects.
Parameters:
Name Type Description callfunction - Source:
-
getCollidingObjects(dynObject)
-
Get array of Dynamic Object colliding some specified colliding object.
Parameters:
Name Type Description dynObjectPhSim.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 dynObjectPhSim.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 dynObjectAPhSim.DynObject The first object
dynObjectBPhSim.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 dynObjectPhSim.DynObject - Source:
Returns:
- Type
- Array.<PhSim.phSimCollision>
-
getDynObjectByID(idNum)
-
Get object by ID
Parameters:
Name Type Description idNumString - Source:
Returns:
- Type
- PhSim.DynObject
-
getEventBridge(f)
-
Create a wrapping function that is used for events.
Parameters:
Name Type Description ffunction Function
- Source:
-
getObjectByName(str)
-
Get object by name in PhSim simulation
Parameters:
Name Type Description strString 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 strLOStr - Source:
Returns:
- Type
- PhSimObject
-
getStatic(dynObject)
-
Get static object of a dynamic object
Parameters:
Name Type Description dynObjectPhSim.DynObject The dynamic object
- Source:
-
getStatusStr()
-
Get the status string of the the dynamic simulation
- Source:
-
getUniversalObjArray()
-
- Source:
-
inSensorCollision(dynObject)
-
Parameters:
Name Type Description dynObjectPhSim.DynObject - Source:
Returns:
- Type
- Boolean
-
isInCollision(dynObject)
-
Check if an object is in a collision
Parameters:
Name Type Description dynObjectPhSim.DynObject - Source:
Returns:
- Type
- Boolean
-
isNonDyn(o)
-
Check if the object is a dynamic object.
Parameters:
Name Type Description oPhSimObject - Source:
-
L(L)
-
Parameters:
Name Type Description LNumber - Source:
-
LO(L, O)
-
Parameters:
Name Type Description LNumber ONumber - 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 eventStrString callPhSimEventCall - Mixes In:
- Source:
-
on(eventStr, call [, options])
-
Used to add events to a PhSim simulation
Parameters:
Name Type Argument Default Description eventStrstring String representing the event.
callPhSimEventCall Function to run when event is executed.
optionsobject <optional>
{} Event Listener Options.
Properties
Name Type Argument Description onceboolean <optional>
If true, the function is executed only once.
slEventboolean <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
PhSiminstance as its value.
- Type
- Promise
-
pauseAudioByIndex(i)
-
Pause audio by index. Alternative function: PhSim.Audio#pauseAudioByIndex
Parameters:
Name Type Description iNumber - 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
PhSiminstance as its value.
- Type
- Promise
-
playAudioByIndex(phsim, i)
-
Play audio by index Alternative function: PhSim.Audio#playAudioByIndex
Parameters:
Name Type Description phsimPhSim PhSim instance.
iNumber 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 xNumber x-coordinate
yNumber 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 strString - 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 dynObjectPhSim.DynObject Dynamic Object
- Source:
Returns:
- The removed Dynamic Object
- Type
- PhSim.DynObject
-
setAudioMuteByIndex(phsim)
-
Mute the
ith element of the audio array.Alternative function: PhSim.Audio#setAudioMuteByIndex
Parameters:
Name Type Description phsimPhSim PhSim instance
- Source:
-
setAudioVolByIndex(i, v)
-
Set volume by index Alternative function: PhSim.Audio#setAudioVolByIndex
Parameters:
Name Type Description iNumber Index
vNumber Volume
- Source:
-
setDynObjectLifespan(dynObject, lifespan)
-
Set Object Lifespan
Parameters:
Name Type Description dynObject* Dynamic Object
lifespanNumber Milliseconds
- Source:
-
setLock(dynObject, value)
-
Set lock of the Dynamic Object
Parameters:
Name Type Description dynObjectPhSim.DynObject valueBoolean If
true, lock. Otherwise, unlock.- Source:
-
toggle()
-
Toggle Simulation
- Source:
Returns:
- Type
- Promise
-
toggleAudioByIndex(i)
-
Parameters:
Name Type Description iNumber - 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 dynObjectPhSim.DynObject - Source:
-
toggleSemiLock(dynObject)
-
Toggle Semi-Lock Status of Dynamic Object.
Parameters:
Name Type Description dynObjectPhSim.DynObject - Source:
-
updateDynObj(currentObj)
-
Update a dynamic object.
Parameters:
Name Type Description currentObjPhSimObject 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 argString | function content of function if string, function if function
thisRefObject - Source:
Returns:
- Type
- WFunction
Type Definitions
-
options
-
The static simulation object
Type:
- Source: