excalibur 0.28.3 → 0.28.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +63 -63
- package/CHANGELOG.md +2003 -1955
- package/LICENSE.md +25 -25
- package/README.md +134 -134
- package/STYLEGUIDE.md +136 -136
- package/build/dist/Actions/Action/ActionSequence.js +31 -0
- package/build/dist/Actions/Action/ActionSequence.js.map +1 -0
- package/build/dist/Actions/Action/Blink.js +54 -0
- package/build/dist/Actions/Action/Blink.js.map +1 -0
- package/build/dist/Actions/Action/CallMethod.js +21 -0
- package/build/dist/Actions/Action/CallMethod.js.map +1 -0
- package/build/dist/Actions/Action/Delay.js +26 -0
- package/build/dist/Actions/Action/Delay.js.map +1 -0
- package/build/dist/Actions/Action/Die.js +22 -0
- package/build/dist/Actions/Action/Die.js.map +1 -0
- package/build/dist/Actions/Action/EaseBy.js +70 -0
- package/build/dist/Actions/Action/EaseBy.js.map +1 -0
- package/build/dist/Actions/Action/EaseTo.js +69 -0
- package/build/dist/Actions/Action/EaseTo.js.map +1 -0
- package/build/dist/Actions/Action/Fade.js +48 -0
- package/build/dist/Actions/Action/Fade.js.map +1 -0
- package/build/dist/Actions/Action/Follow.js +56 -0
- package/build/dist/Actions/Action/Follow.js.map +1 -0
- package/build/dist/Actions/Action/Meet.js +54 -0
- package/build/dist/Actions/Action/Meet.js.map +1 -0
- package/build/dist/Actions/Action/MoveBy.js +48 -0
- package/build/dist/Actions/Action/MoveBy.js.map +1 -0
- package/build/dist/Actions/Action/MoveTo.js +41 -0
- package/build/dist/Actions/Action/MoveTo.js.map +1 -0
- package/build/dist/Actions/Action/ParallelActions.js +23 -0
- package/build/dist/Actions/Action/ParallelActions.js.map +1 -0
- package/build/dist/Actions/Action/Repeat.js +31 -0
- package/build/dist/Actions/Action/Repeat.js.map +1 -0
- package/build/dist/Actions/Action/RepeatForever.js +37 -0
- package/build/dist/Actions/Action/RepeatForever.js.map +1 -0
- package/build/dist/Actions/Action/RotateBy.js +95 -0
- package/build/dist/Actions/Action/RotateBy.js.map +1 -0
- package/build/dist/Actions/Action/RotateTo.js +91 -0
- package/build/dist/Actions/Action/RotateTo.js.map +1 -0
- package/build/dist/Actions/Action/ScaleBy.js +46 -0
- package/build/dist/Actions/Action/ScaleBy.js.map +1 -0
- package/build/dist/Actions/Action/ScaleTo.js +58 -0
- package/build/dist/Actions/Action/ScaleTo.js.map +1 -0
- package/build/dist/Actions/Action.js +2 -0
- package/build/dist/Actions/Action.js.map +1 -0
- package/build/dist/Actions/ActionContext.js +322 -0
- package/build/dist/Actions/ActionContext.js.map +1 -0
- package/build/dist/Actions/ActionQueue.js +87 -0
- package/build/dist/Actions/ActionQueue.js.map +1 -0
- package/build/dist/Actions/Actionable.js +2 -0
- package/build/dist/Actions/Actionable.js.map +1 -0
- package/build/dist/Actions/ActionsComponent.js +195 -0
- package/build/dist/Actions/ActionsComponent.js.map +1 -0
- package/build/dist/Actions/ActionsSystem.js +30 -0
- package/build/dist/Actions/ActionsSystem.js.map +1 -0
- package/build/dist/Actions/Index.js +26 -0
- package/build/dist/Actions/Index.js.map +1 -0
- package/build/dist/Actions/RotationType.js +27 -0
- package/build/dist/Actions/RotationType.js.map +1 -0
- package/build/dist/Actor.js +629 -0
- package/build/dist/Actor.js.map +1 -0
- package/build/dist/Camera.js +660 -0
- package/build/dist/Camera.js.map +1 -0
- package/build/dist/Collision/BoundingBox.js +415 -0
- package/build/dist/Collision/BoundingBox.js.map +1 -0
- package/build/dist/Collision/ColliderComponent.js +202 -0
- package/build/dist/Collision/ColliderComponent.js.map +1 -0
- package/build/dist/Collision/Colliders/CircleCollider.js +226 -0
- package/build/dist/Collision/Colliders/CircleCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/ClosestLineJumpTable.js +211 -0
- package/build/dist/Collision/Colliders/ClosestLineJumpTable.js.map +1 -0
- package/build/dist/Collision/Colliders/Collider.js +32 -0
- package/build/dist/Collision/Colliders/Collider.js.map +1 -0
- package/build/dist/Collision/Colliders/CollisionJumpTable.js +300 -0
- package/build/dist/Collision/Colliders/CollisionJumpTable.js.map +1 -0
- package/build/dist/Collision/Colliders/EdgeCollider.js +229 -0
- package/build/dist/Collision/Colliders/EdgeCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/PolygonCollider.js +556 -0
- package/build/dist/Collision/Colliders/PolygonCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/SeparatingAxis.js +67 -0
- package/build/dist/Collision/Colliders/SeparatingAxis.js.map +1 -0
- package/build/dist/Collision/Colliders/Shape.js +99 -0
- package/build/dist/Collision/Colliders/Shape.js.map +1 -0
- package/build/dist/Collision/CollisionType.js +33 -0
- package/build/dist/Collision/CollisionType.js.map +1 -0
- package/build/dist/Collision/Detection/CollisionContact.js +51 -0
- package/build/dist/Collision/Detection/CollisionContact.js.map +1 -0
- package/build/dist/Collision/Detection/CollisionProcessor.js +2 -0
- package/build/dist/Collision/Detection/CollisionProcessor.js.map +1 -0
- package/build/dist/Collision/Detection/DynamicTree.js +442 -0
- package/build/dist/Collision/Detection/DynamicTree.js.map +1 -0
- package/build/dist/Collision/Detection/Pair.js +92 -0
- package/build/dist/Collision/Detection/Pair.js.map +1 -0
- package/build/dist/Collision/Detection/QuadTree.js +193 -0
- package/build/dist/Collision/Detection/QuadTree.js.map +1 -0
- package/build/dist/Collision/Group/CollisionGroup.js +3 -3
- package/build/dist/Collision/Integrator.js +25 -0
- package/build/dist/Collision/Integrator.js.map +1 -0
- package/build/dist/Collision/MotionSystem.js +35 -0
- package/build/dist/Collision/MotionSystem.js.map +1 -0
- package/build/dist/Collision/Physics.js +163 -0
- package/build/dist/Collision/Physics.js.map +1 -0
- package/build/dist/Collision/PhysicsWorld.js +10 -0
- package/build/dist/Collision/PhysicsWorld.js.map +1 -0
- package/build/dist/Collision/Side.js +51 -0
- package/build/dist/Collision/Side.js.map +1 -0
- package/build/dist/Collision/Solver/ArcadeSolver.js +154 -0
- package/build/dist/Collision/Solver/ArcadeSolver.js.map +1 -0
- package/build/dist/Collision/Solver/ContactConstraintPoint.js +87 -0
- package/build/dist/Collision/Solver/ContactConstraintPoint.js.map +1 -0
- package/build/dist/Collision/Solver/RealisticSolver.js +293 -0
- package/build/dist/Collision/Solver/RealisticSolver.js.map +1 -0
- package/build/dist/Collision/Solver/Solver.js +2 -0
- package/build/dist/Collision/Solver/Solver.js.map +1 -0
- package/build/dist/Color.js +417 -0
- package/build/dist/Color.js.map +1 -0
- package/build/dist/Configurable.js +32 -0
- package/build/dist/Configurable.js.map +1 -0
- package/build/dist/Debug/Debug.d.ts +11 -0
- package/build/dist/Debug/Debug.js +385 -0
- package/build/dist/Debug/Debug.js.map +1 -0
- package/build/dist/Debug/DebugFlags.js +40 -0
- package/build/dist/Debug/DebugFlags.js.map +1 -0
- package/build/dist/Debug/DebugSystem.js +263 -0
- package/build/dist/Debug/DebugSystem.js.map +1 -0
- package/build/dist/Debug/index.js +4 -0
- package/build/dist/Debug/index.js.map +1 -0
- package/build/dist/Deprecated.js +2 -0
- package/build/dist/Deprecated.js.map +1 -0
- package/build/dist/Engine.js +986 -0
- package/build/dist/Engine.js.map +1 -0
- package/build/dist/EntityComponentSystem/Component.js +65 -0
- package/build/dist/EntityComponentSystem/Component.js.map +1 -0
- package/build/dist/EntityComponentSystem/Components/MotionComponent.js +33 -0
- package/build/dist/EntityComponentSystem/Components/MotionComponent.js.map +1 -0
- package/build/dist/EntityComponentSystem/Components/TransformComponent.js +107 -0
- package/build/dist/EntityComponentSystem/Components/TransformComponent.js.map +1 -0
- package/build/dist/EntityComponentSystem/Entity.js +487 -0
- package/build/dist/EntityComponentSystem/Entity.js.map +1 -0
- package/build/dist/EntityComponentSystem/EntityManager.js +137 -0
- package/build/dist/EntityComponentSystem/EntityManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/Query.js +90 -0
- package/build/dist/EntityComponentSystem/Query.js.map +1 -0
- package/build/dist/EntityComponentSystem/QueryManager.js +90 -0
- package/build/dist/EntityComponentSystem/QueryManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/System.js +76 -0
- package/build/dist/EntityComponentSystem/System.js.map +1 -0
- package/build/dist/EntityComponentSystem/SystemManager.js +104 -0
- package/build/dist/EntityComponentSystem/SystemManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/Util.js +5 -0
- package/build/dist/EntityComponentSystem/Util.js.map +1 -0
- package/build/dist/EntityComponentSystem/World.js +55 -0
- package/build/dist/EntityComponentSystem/World.js.map +1 -0
- package/build/dist/EntityComponentSystem/index.js +11 -0
- package/build/dist/EntityComponentSystem/index.js.map +1 -0
- package/build/dist/EventDispatcher.js +122 -0
- package/build/dist/EventDispatcher.js.map +1 -0
- package/build/dist/EventEmitter.js +86 -0
- package/build/dist/EventEmitter.js.map +1 -0
- package/build/dist/Events/ExEvent.js +12 -0
- package/build/dist/Events/ExEvent.js.map +1 -0
- package/build/dist/Events/MediaEvents.js +75 -0
- package/build/dist/Events/MediaEvents.js.map +1 -0
- package/build/dist/Events/PointerEvents.js +52 -0
- package/build/dist/Events/PointerEvents.js.map +1 -0
- package/build/dist/Events.js +473 -0
- package/build/dist/Events.js.map +1 -0
- package/build/dist/Flags.js +67 -0
- package/build/dist/Flags.js.map +1 -0
- package/build/dist/Graphics/Animation.js +344 -0
- package/build/dist/Graphics/Animation.js.map +1 -0
- package/build/dist/Graphics/Canvas.js +38 -0
- package/build/dist/Graphics/Canvas.js.map +1 -0
- package/build/dist/Graphics/Circle.js +48 -0
- package/build/dist/Graphics/Circle.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js +2 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js +237 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.d.ts +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js +481 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js.map +1 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.frag.glsl +52 -52
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js +174 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.vert.glsl +37 -37
- package/build/dist/Graphics/Context/debug-text.js +47 -0
- package/build/dist/Graphics/Context/debug-text.js.map +1 -0
- package/build/dist/Graphics/Context/draw-call.js +16 -0
- package/build/dist/Graphics/Context/draw-call.js.map +1 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.frag.glsl +32 -32
- package/build/dist/Graphics/Context/image-renderer/image-renderer.js +246 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.vert.glsl +32 -32
- package/build/dist/Graphics/Context/line-renderer/line-fragment.glsl +10 -10
- package/build/dist/Graphics/Context/line-renderer/line-renderer.js +90 -0
- package/build/dist/Graphics/Context/line-renderer/line-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/line-renderer/line-vertex.glsl +14 -14
- package/build/dist/Graphics/Context/material-renderer/material-renderer.js +23 -2
- package/build/dist/Graphics/Context/material-renderer/material-renderer.js.map +1 -1
- package/build/dist/Graphics/Context/material.d.ts +2 -0
- package/build/dist/Graphics/Context/material.js +72 -0
- package/build/dist/Graphics/Context/material.js.map +1 -0
- package/build/dist/Graphics/Context/point-renderer/point-fragment.glsl +19 -19
- package/build/dist/Graphics/Context/point-renderer/point-renderer.js +91 -0
- package/build/dist/Graphics/Context/point-renderer/point-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/point-renderer/point-vertex.glsl +11 -11
- package/build/dist/Graphics/Context/quad-index-buffer.js +67 -0
- package/build/dist/Graphics/Context/quad-index-buffer.js.map +1 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.frag.glsl +85 -85
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js +305 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.vert.glsl +42 -42
- package/build/dist/Graphics/Context/render-source.js +16 -0
- package/build/dist/Graphics/Context/render-source.js.map +1 -0
- package/build/dist/Graphics/Context/render-target.js +65 -0
- package/build/dist/Graphics/Context/render-target.js.map +1 -0
- package/build/dist/Graphics/Context/renderer.js +2 -0
- package/build/dist/Graphics/Context/renderer.js.map +1 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-fragment.glsl +13 -13
- package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js +56 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js.map +1 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-vertex.glsl +11 -11
- package/build/dist/Graphics/Context/state-stack.js +37 -0
- package/build/dist/Graphics/Context/state-stack.js.map +1 -0
- package/build/dist/Graphics/Context/texture-loader.js +109 -0
- package/build/dist/Graphics/Context/texture-loader.js.map +1 -0
- package/build/dist/Graphics/Context/transform-stack.js +30 -0
- package/build/dist/Graphics/Context/transform-stack.js.map +1 -0
- package/build/dist/Graphics/Context/vertex-buffer.js +53 -0
- package/build/dist/Graphics/Context/vertex-buffer.js.map +1 -0
- package/build/dist/Graphics/Context/webgl-util.js +79 -0
- package/build/dist/Graphics/Context/webgl-util.js.map +1 -0
- package/build/dist/Graphics/DebugGraphicsComponent.d.ts +3 -2
- package/build/dist/Graphics/DebugGraphicsComponent.js +16 -0
- package/build/dist/Graphics/DebugGraphicsComponent.js.map +1 -0
- package/build/dist/Graphics/Filtering.js +17 -0
- package/build/dist/Graphics/Filtering.js.map +1 -0
- package/build/dist/Graphics/Font.js +148 -0
- package/build/dist/Graphics/Font.js.map +1 -0
- package/build/dist/Graphics/FontCache.d.ts +1 -0
- package/build/dist/Graphics/FontCache.js +80 -0
- package/build/dist/Graphics/FontCache.js.map +1 -0
- package/build/dist/Graphics/FontCommon.js +109 -0
- package/build/dist/Graphics/FontCommon.js.map +1 -0
- package/build/dist/Graphics/FontTextInstance.js +230 -0
- package/build/dist/Graphics/FontTextInstance.js.map +1 -0
- package/build/dist/Graphics/Graphic.js +208 -0
- package/build/dist/Graphics/Graphic.js.map +1 -0
- package/build/dist/Graphics/GraphicsComponent.js +336 -0
- package/build/dist/Graphics/GraphicsComponent.js.map +1 -0
- package/build/dist/Graphics/GraphicsDiagnostics.js +9 -0
- package/build/dist/Graphics/GraphicsDiagnostics.js.map +1 -0
- package/build/dist/Graphics/GraphicsGroup.js +69 -0
- package/build/dist/Graphics/GraphicsGroup.js.map +1 -0
- package/build/dist/Graphics/GraphicsSystem.js +210 -0
- package/build/dist/Graphics/GraphicsSystem.js.map +1 -0
- package/build/dist/Graphics/ImageSource.js +124 -0
- package/build/dist/Graphics/ImageSource.js.map +1 -0
- package/build/dist/Graphics/Line.js +45 -0
- package/build/dist/Graphics/Line.js.map +1 -0
- package/build/dist/Graphics/OffscreenSystem.js +64 -0
- package/build/dist/Graphics/OffscreenSystem.js.map +1 -0
- package/build/dist/Graphics/ParallaxComponent.js +11 -0
- package/build/dist/Graphics/ParallaxComponent.js.map +1 -0
- package/build/dist/Graphics/Polygon.js +59 -0
- package/build/dist/Graphics/Polygon.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js +7 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js +52 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/PostProcessor.js +2 -0
- package/build/dist/Graphics/PostProcessor/PostProcessor.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ScreenShader.js +59 -0
- package/build/dist/Graphics/PostProcessor/ScreenShader.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/color-blind-fragment.glsl +64 -64
- package/build/dist/Graphics/Raster.js +215 -0
- package/build/dist/Graphics/Raster.js.map +1 -0
- package/build/dist/Graphics/Rectangle.js +29 -0
- package/build/dist/Graphics/Rectangle.js.map +1 -0
- package/build/dist/Graphics/Sprite.js +82 -0
- package/build/dist/Graphics/Sprite.js.map +1 -0
- package/build/dist/Graphics/SpriteFont.js +139 -0
- package/build/dist/Graphics/SpriteFont.js.map +1 -0
- package/build/dist/Graphics/SpriteSheet.js +116 -0
- package/build/dist/Graphics/SpriteSheet.js.map +1 -0
- package/build/dist/Graphics/Text.js +103 -0
- package/build/dist/Graphics/Text.js.map +1 -0
- package/build/dist/Graphics/index.js +46 -0
- package/build/dist/Graphics/index.js.map +1 -0
- package/build/dist/Id.js +8 -0
- package/build/dist/Id.js.map +1 -0
- package/build/dist/Input/CapturePointerConfig.js +5 -0
- package/build/dist/Input/CapturePointerConfig.js.map +1 -0
- package/build/dist/Input/EngineInput.js +2 -0
- package/build/dist/Input/EngineInput.js.map +1 -0
- package/build/dist/Input/Gamepad.js +422 -0
- package/build/dist/Input/Gamepad.js.map +1 -0
- package/build/dist/Input/Index.js +88 -0
- package/build/dist/Input/Index.js.map +1 -0
- package/build/dist/Input/InputMapper.js +45 -0
- package/build/dist/Input/InputMapper.js.map +1 -0
- package/build/dist/Input/Keyboard.js +348 -0
- package/build/dist/Input/Keyboard.js.map +1 -0
- package/build/dist/Input/NativePointerButton.js +12 -0
- package/build/dist/Input/NativePointerButton.js.map +1 -0
- package/build/dist/Input/PointerAbstraction.js +44 -0
- package/build/dist/Input/PointerAbstraction.js.map +1 -0
- package/build/dist/Input/PointerButton.js +12 -0
- package/build/dist/Input/PointerButton.js.map +1 -0
- package/build/dist/Input/PointerComponent.js +28 -0
- package/build/dist/Input/PointerComponent.js.map +1 -0
- package/build/dist/Input/PointerEvent.js +25 -0
- package/build/dist/Input/PointerEvent.js.map +1 -0
- package/build/dist/Input/PointerEventReceiver.js +456 -0
- package/build/dist/Input/PointerEventReceiver.js.map +1 -0
- package/build/dist/Input/PointerScope.js +16 -0
- package/build/dist/Input/PointerScope.js.map +1 -0
- package/build/dist/Input/PointerSystem.js +249 -0
- package/build/dist/Input/PointerSystem.js.map +1 -0
- package/build/dist/Input/PointerType.js +11 -0
- package/build/dist/Input/PointerType.js.map +1 -0
- package/build/dist/Input/WheelDeltaMode.js +7 -0
- package/build/dist/Input/WheelDeltaMode.js.map +1 -0
- package/build/dist/Input/WheelEvent.js +21 -0
- package/build/dist/Input/WheelEvent.js.map +1 -0
- package/build/dist/Interfaces/Audio.js +2 -0
- package/build/dist/Interfaces/Audio.js.map +1 -0
- package/build/dist/Interfaces/AudioImplementation.js +11 -0
- package/build/dist/Interfaces/AudioImplementation.js.map +1 -0
- package/build/dist/Interfaces/Clonable.js +2 -0
- package/build/dist/Interfaces/Clonable.js.map +1 -0
- package/build/dist/Interfaces/Evented.js +2 -0
- package/build/dist/Interfaces/Evented.js.map +1 -0
- package/build/dist/Interfaces/Index.js +8 -0
- package/build/dist/Interfaces/Index.js.map +1 -0
- package/build/dist/Interfaces/LifecycleEvents.js +51 -0
- package/build/dist/Interfaces/LifecycleEvents.js.map +1 -0
- package/build/dist/Interfaces/Loadable.js +2 -0
- package/build/dist/Interfaces/Loadable.js.map +1 -0
- package/build/dist/Interfaces/PointerEventHandlers.js +2 -0
- package/build/dist/Interfaces/PointerEventHandlers.js.map +1 -0
- package/build/dist/Label.js +81 -0
- package/build/dist/Label.js.map +1 -0
- package/build/dist/Loader.js +416 -0
- package/build/dist/Loader.js.map +1 -0
- package/build/dist/Math/Index.js +13 -0
- package/build/dist/Math/Index.js.map +1 -0
- package/build/dist/Math/Random.js +239 -0
- package/build/dist/Math/Random.js.map +1 -0
- package/build/dist/Math/affine-matrix.js +331 -0
- package/build/dist/Math/affine-matrix.js.map +1 -0
- package/build/dist/Math/coord-plane.js +17 -0
- package/build/dist/Math/coord-plane.js.map +1 -0
- package/build/dist/Math/global-coordinates.js +30 -0
- package/build/dist/Math/global-coordinates.js.map +1 -0
- package/build/dist/Math/line-segment.js +205 -0
- package/build/dist/Math/line-segment.js.map +1 -0
- package/build/dist/Math/matrix.js +457 -0
- package/build/dist/Math/matrix.js.map +1 -0
- package/build/dist/Math/projection.js +24 -0
- package/build/dist/Math/projection.js.map +1 -0
- package/build/dist/Math/ray.js +52 -0
- package/build/dist/Math/ray.js.map +1 -0
- package/build/dist/Math/transform.js +219 -0
- package/build/dist/Math/transform.js.map +1 -0
- package/build/dist/Math/util.js +82 -0
- package/build/dist/Math/util.js.map +1 -0
- package/build/dist/Math/vector-view.js +25 -0
- package/build/dist/Math/vector-view.js.map +1 -0
- package/build/dist/Math/vector.js +340 -0
- package/build/dist/Math/vector.js.map +1 -0
- package/build/dist/Math/watch-vector.js +26 -0
- package/build/dist/Math/watch-vector.js.map +1 -0
- package/build/dist/Particles.js +430 -0
- package/build/dist/Particles.js.map +1 -0
- package/build/dist/Polyfill.js +56 -0
- package/build/dist/Polyfill.js.map +1 -0
- package/build/dist/Resources/Gif.js +464 -0
- package/build/dist/Resources/Gif.js.map +1 -0
- package/build/dist/Resources/Index.js +4 -0
- package/build/dist/Resources/Index.js.map +1 -0
- package/build/dist/Resources/Resource.js +81 -0
- package/build/dist/Resources/Resource.js.map +1 -0
- package/build/dist/Resources/Sound/AudioContext.js +16 -0
- package/build/dist/Resources/Sound/AudioContext.js.map +1 -0
- package/build/dist/Resources/Sound/Index.js +4 -0
- package/build/dist/Resources/Sound/Index.js.map +1 -0
- package/build/dist/Resources/Sound/Sound.js +326 -0
- package/build/dist/Resources/Sound/Sound.js.map +1 -0
- package/build/dist/Resources/Sound/WebAudioInstance.js +190 -0
- package/build/dist/Resources/Sound/WebAudioInstance.js.map +1 -0
- package/build/dist/Scene.js +444 -0
- package/build/dist/Scene.js.map +1 -0
- package/build/dist/Screen.js +782 -0
- package/build/dist/Screen.js.map +1 -0
- package/build/dist/ScreenElement.js +43 -0
- package/build/dist/ScreenElement.js.map +1 -0
- package/build/dist/TileMap/IsometricEntityComponent.js +17 -0
- package/build/dist/TileMap/IsometricEntityComponent.js.map +1 -0
- package/build/dist/TileMap/IsometricEntitySystem.js +23 -0
- package/build/dist/TileMap/IsometricEntitySystem.js.map +1 -0
- package/build/dist/TileMap/IsometricMap.js +311 -0
- package/build/dist/TileMap/IsometricMap.js.map +1 -0
- package/build/dist/TileMap/TileMap.d.ts +2 -1
- package/build/dist/TileMap/TileMap.js +630 -0
- package/build/dist/TileMap/TileMap.js.map +1 -0
- package/build/dist/TileMap/index.js +5 -0
- package/build/dist/TileMap/index.js.map +1 -0
- package/build/dist/Timer.js +202 -0
- package/build/dist/Timer.js.map +1 -0
- package/build/dist/Trigger.js +94 -0
- package/build/dist/Trigger.js.map +1 -0
- package/build/dist/Util/Browser.js +66 -0
- package/build/dist/Util/Browser.js.map +1 -0
- package/build/dist/Util/Clock.js +219 -0
- package/build/dist/Util/Clock.js.map +1 -0
- package/build/dist/Util/Decorators.js +78 -0
- package/build/dist/Util/Decorators.js.map +1 -0
- package/build/dist/Util/Detector.js +167 -0
- package/build/dist/Util/Detector.js.map +1 -0
- package/build/dist/Util/DrawUtil.js +115 -0
- package/build/dist/Util/DrawUtil.js.map +1 -0
- package/build/dist/Util/EasingFunctions.js +102 -0
- package/build/dist/Util/EasingFunctions.js.map +1 -0
- package/build/dist/Util/Fps.js +47 -0
- package/build/dist/Util/Fps.js.map +1 -0
- package/build/dist/Util/Future.js +30 -0
- package/build/dist/Util/Future.js.map +1 -0
- package/build/dist/Util/IFrame.js +23 -0
- package/build/dist/Util/IFrame.js.map +1 -0
- package/build/dist/Util/Index.js +7 -0
- package/build/dist/Util/Index.js.map +1 -0
- package/build/dist/Util/Log.js +195 -0
- package/build/dist/Util/Log.js.map +1 -0
- package/build/dist/Util/Observable.js +66 -0
- package/build/dist/Util/Observable.js.map +1 -0
- package/build/dist/Util/Pool.js +74 -0
- package/build/dist/Util/Pool.js.map +1 -0
- package/build/dist/Util/Semaphore.js +55 -0
- package/build/dist/Util/Semaphore.js.map +1 -0
- package/build/dist/Util/Sound.js +22 -0
- package/build/dist/Util/Sound.js.map +1 -0
- package/build/dist/Util/StateMachine.js +79 -0
- package/build/dist/Util/StateMachine.js.map +1 -0
- package/build/dist/Util/Toaster.css +28 -28
- package/build/dist/Util/Toaster.js +84 -0
- package/build/dist/Util/Toaster.js.map +1 -0
- package/build/dist/Util/Util.d.ts +6 -0
- package/build/dist/Util/Util.js +95 -0
- package/build/dist/Util/Util.js.map +1 -0
- package/build/dist/Util/Watch.js +67 -0
- package/build/dist/Util/Watch.js.map +1 -0
- package/build/dist/Util/WebAudio.js +62 -0
- package/build/dist/Util/WebAudio.js.map +1 -0
- package/build/dist/excalibur.d.ts +2 -2
- package/build/dist/excalibur.js +389 -258
- package/build/dist/excalibur.js.map +1 -1
- package/build/dist/excalibur.min.js +1 -1
- package/build/dist/excalibur.min.js.LICENSE.txt +1 -1
- package/build/dist/excalibur.min.js.map +1 -1
- package/build/dist/index.js +81 -0
- package/build/dist/index.js.map +1 -0
- package/build/esm/Debug/Debug.d.ts +11 -0
- package/build/esm/Graphics/Context/ExcaliburGraphicsContextWebGL.d.ts +1 -0
- package/build/esm/Graphics/Context/material.d.ts +2 -0
- package/build/esm/Graphics/DebugGraphicsComponent.d.ts +3 -2
- package/build/esm/Graphics/FontCache.d.ts +1 -0
- package/build/esm/TileMap/TileMap.d.ts +2 -1
- package/build/esm/Util/Util.d.ts +6 -0
- package/build/esm/excalibur.d.ts +2 -2
- package/build/esm/excalibur.js +389 -258
- package/build/esm/excalibur.js.map +1 -1
- package/build/esm/excalibur.min.js +1 -1
- package/build/esm/excalibur.min.js.LICENSE.txt +1 -1
- package/build/esm/excalibur.min.js.map +1 -1
- package/docker-compose.yml +11 -11
- package/package.json +131 -131
- package/build/dist/Loader.css +0 -122
- package/build/nuget/Excalibur.0.28.3.nupkg +0 -0
- package/build/v0.28.3.zip +0 -0
- package/excalibur-0.28.3.tgz +0 -0
|
@@ -0,0 +1,986 @@
|
|
|
1
|
+
import { EX_VERSION } from './';
|
|
2
|
+
import { EventEmitter } from './EventEmitter';
|
|
3
|
+
import { Gamepads } from './Input/Gamepad';
|
|
4
|
+
import { Keyboard } from './Input/Keyboard';
|
|
5
|
+
import { PointerScope } from './Input/PointerScope';
|
|
6
|
+
import { Flags } from './Flags';
|
|
7
|
+
import { polyfill } from './Polyfill';
|
|
8
|
+
polyfill();
|
|
9
|
+
import { Screen, DisplayMode, Resolution } from './Screen';
|
|
10
|
+
import { Loader } from './Loader';
|
|
11
|
+
import { Detector } from './Util/Detector';
|
|
12
|
+
import { VisibleEvent, HiddenEvent, GameStartEvent, GameStopEvent, PreUpdateEvent, PostUpdateEvent, PreFrameEvent, PostFrameEvent, DeactivateEvent, ActivateEvent, PreDrawEvent, PostDrawEvent, InitializeEvent } from './Events';
|
|
13
|
+
import { Logger, LogLevel } from './Util/Log';
|
|
14
|
+
import { Color } from './Color';
|
|
15
|
+
import { Scene } from './Scene';
|
|
16
|
+
import { Entity } from './EntityComponentSystem/Entity';
|
|
17
|
+
import { Debug } from './Debug/Debug';
|
|
18
|
+
import { BrowserEvents } from './Util/Browser';
|
|
19
|
+
import { ExcaliburGraphicsContext2DCanvas, ExcaliburGraphicsContextWebGL, TextureLoader } from './Graphics';
|
|
20
|
+
import { PointerEventReceiver } from './Input/PointerEventReceiver';
|
|
21
|
+
import { StandardClock } from './Util/Clock';
|
|
22
|
+
import { ImageFiltering } from './Graphics/Filtering';
|
|
23
|
+
import { GraphicsDiagnostics } from './Graphics/GraphicsDiagnostics';
|
|
24
|
+
import { Toaster } from './Util/Toaster';
|
|
25
|
+
import { InputMapper } from './Input/InputMapper';
|
|
26
|
+
export const EngineEvents = {
|
|
27
|
+
FallbackGraphicsContext: 'fallbackgraphicscontext',
|
|
28
|
+
Initialize: 'initialize',
|
|
29
|
+
Visible: 'visible',
|
|
30
|
+
Hidden: 'hidden',
|
|
31
|
+
Start: 'start',
|
|
32
|
+
Stop: 'stop',
|
|
33
|
+
PreUpdate: 'preupdate',
|
|
34
|
+
PostUpdate: 'postupdate',
|
|
35
|
+
PreFrame: 'preframe',
|
|
36
|
+
PostFrame: 'postframe',
|
|
37
|
+
PreDraw: 'predraw',
|
|
38
|
+
PostDraw: 'postdraw'
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Enum representing the different mousewheel event bubble prevention
|
|
42
|
+
*/
|
|
43
|
+
export var ScrollPreventionMode;
|
|
44
|
+
(function (ScrollPreventionMode) {
|
|
45
|
+
/**
|
|
46
|
+
* Do not prevent any page scrolling
|
|
47
|
+
*/
|
|
48
|
+
ScrollPreventionMode[ScrollPreventionMode["None"] = 0] = "None";
|
|
49
|
+
/**
|
|
50
|
+
* Prevent page scroll if mouse is over the game canvas
|
|
51
|
+
*/
|
|
52
|
+
ScrollPreventionMode[ScrollPreventionMode["Canvas"] = 1] = "Canvas";
|
|
53
|
+
/**
|
|
54
|
+
* Prevent all page scrolling via mouse wheel
|
|
55
|
+
*/
|
|
56
|
+
ScrollPreventionMode[ScrollPreventionMode["All"] = 2] = "All";
|
|
57
|
+
})(ScrollPreventionMode || (ScrollPreventionMode = {}));
|
|
58
|
+
/**
|
|
59
|
+
* The Excalibur Engine
|
|
60
|
+
*
|
|
61
|
+
* The [[Engine]] is the main driver for a game. It is responsible for
|
|
62
|
+
* starting/stopping the game, maintaining state, transmitting events,
|
|
63
|
+
* loading resources, and managing the scene.
|
|
64
|
+
*/
|
|
65
|
+
export class Engine {
|
|
66
|
+
/**
|
|
67
|
+
* The width of the game canvas in pixels (physical width component of the
|
|
68
|
+
* resolution of the canvas element)
|
|
69
|
+
*/
|
|
70
|
+
get canvasWidth() {
|
|
71
|
+
return this.screen.canvasWidth;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns half width of the game canvas in pixels (half physical width component)
|
|
75
|
+
*/
|
|
76
|
+
get halfCanvasWidth() {
|
|
77
|
+
return this.screen.halfCanvasWidth;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The height of the game canvas in pixels, (physical height component of
|
|
81
|
+
* the resolution of the canvas element)
|
|
82
|
+
*/
|
|
83
|
+
get canvasHeight() {
|
|
84
|
+
return this.screen.canvasHeight;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns half height of the game canvas in pixels (half physical height component)
|
|
88
|
+
*/
|
|
89
|
+
get halfCanvasHeight() {
|
|
90
|
+
return this.screen.halfCanvasHeight;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns the width of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
|
|
94
|
+
*/
|
|
95
|
+
get drawWidth() {
|
|
96
|
+
return this.screen.drawWidth;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns half the width of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
|
|
100
|
+
*/
|
|
101
|
+
get halfDrawWidth() {
|
|
102
|
+
return this.screen.halfDrawWidth;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns the height of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
|
|
106
|
+
*/
|
|
107
|
+
get drawHeight() {
|
|
108
|
+
return this.screen.drawHeight;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Returns half the height of the engine's visible drawing surface in pixels including zoom and device pixel ratio.
|
|
112
|
+
*/
|
|
113
|
+
get halfDrawHeight() {
|
|
114
|
+
return this.screen.halfDrawHeight;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Returns whether excalibur detects the current screen to be HiDPI
|
|
118
|
+
*/
|
|
119
|
+
get isHiDpi() {
|
|
120
|
+
return this.screen.isHiDpi;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Access [[stats]] that holds frame statistics.
|
|
124
|
+
*/
|
|
125
|
+
get stats() {
|
|
126
|
+
return this.debug.stats;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Indicates whether the engine is set to fullscreen or not
|
|
130
|
+
*/
|
|
131
|
+
get isFullscreen() {
|
|
132
|
+
return this.screen.isFullScreen;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Indicates the current [[DisplayMode]] of the engine.
|
|
136
|
+
*/
|
|
137
|
+
get displayMode() {
|
|
138
|
+
return this.screen.displayMode;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Returns the calculated pixel ration for use in rendering
|
|
142
|
+
*/
|
|
143
|
+
get pixelRatio() {
|
|
144
|
+
return this.screen.pixelRatio;
|
|
145
|
+
}
|
|
146
|
+
get isDebug() {
|
|
147
|
+
return this._isDebug;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Hints the graphics context to truncate fractional world space coordinates
|
|
151
|
+
*/
|
|
152
|
+
get snapToPixel() {
|
|
153
|
+
return this.graphicsContext.snapToPixel;
|
|
154
|
+
}
|
|
155
|
+
;
|
|
156
|
+
set snapToPixel(shouldSnapToPixel) {
|
|
157
|
+
this.graphicsContext.snapToPixel = shouldSnapToPixel;
|
|
158
|
+
}
|
|
159
|
+
;
|
|
160
|
+
emit(eventName, event) {
|
|
161
|
+
this.events.emit(eventName, event);
|
|
162
|
+
}
|
|
163
|
+
on(eventName, handler) {
|
|
164
|
+
return this.events.on(eventName, handler);
|
|
165
|
+
}
|
|
166
|
+
once(eventName, handler) {
|
|
167
|
+
return this.events.once(eventName, handler);
|
|
168
|
+
}
|
|
169
|
+
off(eventName, handler) {
|
|
170
|
+
this.events.off(eventName, handler);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Creates a new game using the given [[EngineOptions]]. By default, if no options are provided,
|
|
174
|
+
* the game will be rendered full screen (taking up all available browser window space).
|
|
175
|
+
* You can customize the game rendering through [[EngineOptions]].
|
|
176
|
+
*
|
|
177
|
+
* Example:
|
|
178
|
+
*
|
|
179
|
+
* ```js
|
|
180
|
+
* var game = new ex.Engine({
|
|
181
|
+
* width: 0, // the width of the canvas
|
|
182
|
+
* height: 0, // the height of the canvas
|
|
183
|
+
* enableCanvasTransparency: true, // the transparencySection of the canvas
|
|
184
|
+
* canvasElementId: '', // the DOM canvas element ID, if you are providing your own
|
|
185
|
+
* displayMode: ex.DisplayMode.FullScreen, // the display mode
|
|
186
|
+
* pointerScope: ex.PointerScope.Document, // the scope of capturing pointer (mouse/touch) events
|
|
187
|
+
* backgroundColor: ex.Color.fromHex('#2185d0') // background color of the engine
|
|
188
|
+
* });
|
|
189
|
+
*
|
|
190
|
+
* // call game.start, which is a Promise
|
|
191
|
+
* game.start().then(function () {
|
|
192
|
+
* // ready, set, go!
|
|
193
|
+
* });
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
constructor(options) {
|
|
197
|
+
var _a, _b, _c, _d, _e, _f;
|
|
198
|
+
/**
|
|
199
|
+
* Current Excalibur version string
|
|
200
|
+
*
|
|
201
|
+
* Useful for plugins or other tools that need to know what features are available
|
|
202
|
+
*/
|
|
203
|
+
this.version = EX_VERSION;
|
|
204
|
+
/**
|
|
205
|
+
* Listen to and emit events on the Engine
|
|
206
|
+
*/
|
|
207
|
+
this.events = new EventEmitter();
|
|
208
|
+
/**
|
|
209
|
+
* Optionally set the maximum fps if not set Excalibur will go as fast as the device allows.
|
|
210
|
+
*
|
|
211
|
+
* You may want to constrain max fps if your game cannot maintain fps consistently, it can look and feel better to have a 30fps game than
|
|
212
|
+
* one that bounces between 30fps and 60fps
|
|
213
|
+
*/
|
|
214
|
+
this.maxFps = Number.POSITIVE_INFINITY;
|
|
215
|
+
/**
|
|
216
|
+
* Contains all the scenes currently registered with Excalibur
|
|
217
|
+
*/
|
|
218
|
+
this.scenes = {};
|
|
219
|
+
this._suppressPlayButton = false;
|
|
220
|
+
/**
|
|
221
|
+
* Indicates whether audio should be paused when the game is no longer visible.
|
|
222
|
+
*/
|
|
223
|
+
this.pauseAudioWhenHidden = true;
|
|
224
|
+
/**
|
|
225
|
+
* Indicates whether the engine should draw with debug information
|
|
226
|
+
*/
|
|
227
|
+
this._isDebug = false;
|
|
228
|
+
/**
|
|
229
|
+
* Sets the Transparency for the engine.
|
|
230
|
+
*/
|
|
231
|
+
this.enableCanvasTransparency = true;
|
|
232
|
+
/**
|
|
233
|
+
* The action to take when a fatal exception is thrown
|
|
234
|
+
*/
|
|
235
|
+
this.onFatalException = (e) => {
|
|
236
|
+
Logger.getInstance().fatal(e);
|
|
237
|
+
};
|
|
238
|
+
this._toaster = new Toaster();
|
|
239
|
+
this._timescale = 1.0;
|
|
240
|
+
this._isInitialized = false;
|
|
241
|
+
this._deferredGoTo = null;
|
|
242
|
+
this._originalOptions = {};
|
|
243
|
+
this._performanceThresholdTriggered = false;
|
|
244
|
+
this._fpsSamples = [];
|
|
245
|
+
this._loadingComplete = false;
|
|
246
|
+
this._isReady = false;
|
|
247
|
+
this._isReadyPromise = new Promise(resolve => {
|
|
248
|
+
this._isReadyResolve = resolve;
|
|
249
|
+
});
|
|
250
|
+
/**
|
|
251
|
+
* Returns the current frames elapsed milliseconds
|
|
252
|
+
*/
|
|
253
|
+
this.currentFrameElapsedMs = 0;
|
|
254
|
+
/**
|
|
255
|
+
* Returns the current frame lag when in fixed update mode
|
|
256
|
+
*/
|
|
257
|
+
this.currentFrameLagMs = 0;
|
|
258
|
+
this._lagMs = 0;
|
|
259
|
+
this._screenShotRequests = [];
|
|
260
|
+
options = { ...Engine._DEFAULT_ENGINE_OPTIONS, ...options };
|
|
261
|
+
this._originalOptions = options;
|
|
262
|
+
Flags.freeze();
|
|
263
|
+
// Initialize browser events facade
|
|
264
|
+
this.browser = new BrowserEvents(window, document);
|
|
265
|
+
// Check compatibility
|
|
266
|
+
const detector = new Detector();
|
|
267
|
+
if (!options.suppressMinimumBrowserFeatureDetection && !(this._compatible = detector.test())) {
|
|
268
|
+
const message = document.createElement('div');
|
|
269
|
+
message.innerText = 'Sorry, your browser does not support all the features needed for Excalibur';
|
|
270
|
+
document.body.appendChild(message);
|
|
271
|
+
detector.failedTests.forEach(function (test) {
|
|
272
|
+
const testMessage = document.createElement('div');
|
|
273
|
+
testMessage.innerText = 'Browser feature missing ' + test;
|
|
274
|
+
document.body.appendChild(testMessage);
|
|
275
|
+
});
|
|
276
|
+
if (options.canvasElementId) {
|
|
277
|
+
const canvas = document.getElementById(options.canvasElementId);
|
|
278
|
+
if (canvas) {
|
|
279
|
+
canvas.parentElement.removeChild(canvas);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
this._compatible = true;
|
|
286
|
+
}
|
|
287
|
+
// Use native console API for color fun
|
|
288
|
+
// eslint-disable-next-line no-console
|
|
289
|
+
if (console.log && !options.suppressConsoleBootMessage) {
|
|
290
|
+
// eslint-disable-next-line no-console
|
|
291
|
+
console.log(`%cPowered by Excalibur.js (v${EX_VERSION})`, 'background: #176BAA; color: white; border-radius: 5px; padding: 15px; font-size: 1.5em; line-height: 80px;');
|
|
292
|
+
// eslint-disable-next-line no-console
|
|
293
|
+
console.log('\n\
|
|
294
|
+
/| ________________\n\
|
|
295
|
+
O|===|* >________________>\n\
|
|
296
|
+
\\|');
|
|
297
|
+
// eslint-disable-next-line no-console
|
|
298
|
+
console.log('Visit', 'http://excaliburjs.com', 'for more information');
|
|
299
|
+
}
|
|
300
|
+
// Suppress play button
|
|
301
|
+
if (options.suppressPlayButton) {
|
|
302
|
+
this._suppressPlayButton = true;
|
|
303
|
+
}
|
|
304
|
+
this._logger = Logger.getInstance();
|
|
305
|
+
// If debug is enabled, let's log browser features to the console.
|
|
306
|
+
if (this._logger.defaultLevel === LogLevel.Debug) {
|
|
307
|
+
detector.logBrowserFeatures();
|
|
308
|
+
}
|
|
309
|
+
this._logger.debug('Building engine...');
|
|
310
|
+
this.canvasElementId = options.canvasElementId;
|
|
311
|
+
if (options.canvasElementId) {
|
|
312
|
+
this._logger.debug('Using Canvas element specified: ' + options.canvasElementId);
|
|
313
|
+
this.canvas = document.getElementById(options.canvasElementId);
|
|
314
|
+
}
|
|
315
|
+
else if (options.canvasElement) {
|
|
316
|
+
this._logger.debug('Using Canvas element specified:', options.canvasElement);
|
|
317
|
+
this.canvas = options.canvasElement;
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
this._logger.debug('Using generated canvas element');
|
|
321
|
+
this.canvas = document.createElement('canvas');
|
|
322
|
+
}
|
|
323
|
+
let displayMode = (_a = options.displayMode) !== null && _a !== void 0 ? _a : DisplayMode.Fixed;
|
|
324
|
+
if ((options.width && options.height) || options.viewport) {
|
|
325
|
+
if (options.displayMode === undefined) {
|
|
326
|
+
displayMode = DisplayMode.Fixed;
|
|
327
|
+
}
|
|
328
|
+
this._logger.debug('Engine viewport is size ' + options.width + ' x ' + options.height);
|
|
329
|
+
}
|
|
330
|
+
else if (!options.displayMode) {
|
|
331
|
+
this._logger.debug('Engine viewport is fit');
|
|
332
|
+
displayMode = DisplayMode.FitScreen;
|
|
333
|
+
}
|
|
334
|
+
this._originalDisplayMode = displayMode;
|
|
335
|
+
// Canvas 2D fallback can be flagged on
|
|
336
|
+
let useCanvasGraphicsContext = Flags.isEnabled('use-canvas-context');
|
|
337
|
+
if (!useCanvasGraphicsContext) {
|
|
338
|
+
// Attempt webgl first
|
|
339
|
+
try {
|
|
340
|
+
this.graphicsContext = new ExcaliburGraphicsContextWebGL({
|
|
341
|
+
canvasElement: this.canvas,
|
|
342
|
+
enableTransparency: this.enableCanvasTransparency,
|
|
343
|
+
smoothing: options.antialiasing,
|
|
344
|
+
backgroundColor: options.backgroundColor,
|
|
345
|
+
snapToPixel: options.snapToPixel,
|
|
346
|
+
useDrawSorting: options.useDrawSorting
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
catch (e) {
|
|
350
|
+
this._logger.warn(`Excalibur could not load webgl for some reason (${e.message}) and loaded a Canvas 2D fallback. ` +
|
|
351
|
+
`Some features of Excalibur will not work in this mode. \n\n` +
|
|
352
|
+
'Read more about this issue at https://excaliburjs.com/docs/webgl');
|
|
353
|
+
// fallback to canvas in case of failure
|
|
354
|
+
useCanvasGraphicsContext = true;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (useCanvasGraphicsContext) {
|
|
358
|
+
this.graphicsContext = new ExcaliburGraphicsContext2DCanvas({
|
|
359
|
+
canvasElement: this.canvas,
|
|
360
|
+
enableTransparency: this.enableCanvasTransparency,
|
|
361
|
+
smoothing: options.antialiasing,
|
|
362
|
+
backgroundColor: options.backgroundColor,
|
|
363
|
+
snapToPixel: options.snapToPixel,
|
|
364
|
+
useDrawSorting: options.useDrawSorting
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
this.screen = new Screen({
|
|
368
|
+
canvas: this.canvas,
|
|
369
|
+
context: this.graphicsContext,
|
|
370
|
+
antialiasing: (_b = options.antialiasing) !== null && _b !== void 0 ? _b : true,
|
|
371
|
+
browser: this.browser,
|
|
372
|
+
viewport: (_c = options.viewport) !== null && _c !== void 0 ? _c : (options.width && options.height ? { width: options.width, height: options.height } : Resolution.SVGA),
|
|
373
|
+
resolution: options.resolution,
|
|
374
|
+
displayMode,
|
|
375
|
+
pixelRatio: options.suppressHiDPIScaling ? 1 : ((_d = options.pixelRatio) !== null && _d !== void 0 ? _d : null)
|
|
376
|
+
});
|
|
377
|
+
// Set default filtering based on antialiasing
|
|
378
|
+
TextureLoader.filtering = options.antialiasing ? ImageFiltering.Blended : ImageFiltering.Pixel;
|
|
379
|
+
if (options.backgroundColor) {
|
|
380
|
+
this.backgroundColor = options.backgroundColor.clone();
|
|
381
|
+
}
|
|
382
|
+
this.maxFps = (_e = options.maxFps) !== null && _e !== void 0 ? _e : this.maxFps;
|
|
383
|
+
this.fixedUpdateFps = (_f = options.fixedUpdateFps) !== null && _f !== void 0 ? _f : this.fixedUpdateFps;
|
|
384
|
+
this.clock = new StandardClock({
|
|
385
|
+
maxFps: this.maxFps,
|
|
386
|
+
tick: this._mainloop.bind(this),
|
|
387
|
+
onFatalException: (e) => this.onFatalException(e)
|
|
388
|
+
});
|
|
389
|
+
this.enableCanvasTransparency = options.enableCanvasTransparency;
|
|
390
|
+
this._loader = new Loader();
|
|
391
|
+
this._loader.wireEngine(this);
|
|
392
|
+
this.debug = new Debug(this);
|
|
393
|
+
this._initialize(options);
|
|
394
|
+
this.rootScene = this.currentScene = new Scene();
|
|
395
|
+
this.addScene('root', this.rootScene);
|
|
396
|
+
window.___EXCALIBUR_DEVTOOL = this;
|
|
397
|
+
}
|
|
398
|
+
_monitorPerformanceThresholdAndTriggerFallback() {
|
|
399
|
+
const { allow } = this._originalOptions.configurePerformanceCanvas2DFallback;
|
|
400
|
+
let { threshold, showPlayerMessage } = this._originalOptions.configurePerformanceCanvas2DFallback;
|
|
401
|
+
if (threshold === undefined) {
|
|
402
|
+
threshold = Engine._DEFAULT_ENGINE_OPTIONS.configurePerformanceCanvas2DFallback.threshold;
|
|
403
|
+
}
|
|
404
|
+
if (showPlayerMessage === undefined) {
|
|
405
|
+
showPlayerMessage = Engine._DEFAULT_ENGINE_OPTIONS.configurePerformanceCanvas2DFallback.showPlayerMessage;
|
|
406
|
+
}
|
|
407
|
+
if (!Flags.isEnabled('use-canvas-context') && allow && this.ready && !this._performanceThresholdTriggered) {
|
|
408
|
+
// Calculate Average fps for last X number of frames after start
|
|
409
|
+
if (this._fpsSamples.length === threshold.numberOfFrames) {
|
|
410
|
+
this._fpsSamples.splice(0, 1);
|
|
411
|
+
}
|
|
412
|
+
this._fpsSamples.push(this.clock.fpsSampler.fps);
|
|
413
|
+
let total = 0;
|
|
414
|
+
for (let i = 0; i < this._fpsSamples.length; i++) {
|
|
415
|
+
total += this._fpsSamples[i];
|
|
416
|
+
}
|
|
417
|
+
const average = total / this._fpsSamples.length;
|
|
418
|
+
if (this._fpsSamples.length === threshold.numberOfFrames) {
|
|
419
|
+
if (average <= threshold.fps) {
|
|
420
|
+
this._performanceThresholdTriggered = true;
|
|
421
|
+
this._logger.warn(`Switching to browser 2D Canvas fallback due to performance. Some features of Excalibur will not work in this mode.\n` +
|
|
422
|
+
'this might mean your browser doesn\'t have webgl enabled or hardware acceleration is unavailable.\n\n' +
|
|
423
|
+
'If in Chrome:\n' +
|
|
424
|
+
' * Visit Settings > Advanced > System, and ensure "Use Hardware Acceleration" is checked.\n' +
|
|
425
|
+
' * Visit chrome://flags/#ignore-gpu-blocklist and ensure "Override software rendering list" is "enabled"\n' +
|
|
426
|
+
'If in Firefox, visit about:config\n' +
|
|
427
|
+
' * Ensure webgl.disabled = false\n' +
|
|
428
|
+
' * Ensure webgl.force-enabled = true\n' +
|
|
429
|
+
' * Ensure layers.acceleration.force-enabled = true\n\n' +
|
|
430
|
+
'Read more about this issue at https://excaliburjs.com/docs/performance');
|
|
431
|
+
if (showPlayerMessage) {
|
|
432
|
+
this._toaster.toast('Excalibur is encountering performance issues. ' +
|
|
433
|
+
'It\'s possible that your browser doesn\'t have hardware acceleration enabled. ' +
|
|
434
|
+
'Visit [LINK] for more information and potential solutions.', 'https://excaliburjs.com/docs/performance');
|
|
435
|
+
}
|
|
436
|
+
this.useCanvas2DFallback();
|
|
437
|
+
this.emit('fallbackgraphicscontext', this.graphicsContext);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Switches the engine's graphics context to the 2D Canvas.
|
|
444
|
+
* @warning Some features of Excalibur will not work in this mode.
|
|
445
|
+
*/
|
|
446
|
+
useCanvas2DFallback() {
|
|
447
|
+
var _a, _b, _c;
|
|
448
|
+
// Swap out the canvas
|
|
449
|
+
const newCanvas = this.canvas.cloneNode(false);
|
|
450
|
+
this.canvas.parentNode.replaceChild(newCanvas, this.canvas);
|
|
451
|
+
this.canvas = newCanvas;
|
|
452
|
+
const options = { ...this._originalOptions, antialiasing: this.getAntialiasing() };
|
|
453
|
+
const displayMode = this._originalDisplayMode;
|
|
454
|
+
// New graphics context
|
|
455
|
+
this.graphicsContext = new ExcaliburGraphicsContext2DCanvas({
|
|
456
|
+
canvasElement: this.canvas,
|
|
457
|
+
enableTransparency: this.enableCanvasTransparency,
|
|
458
|
+
smoothing: options.antialiasing,
|
|
459
|
+
backgroundColor: options.backgroundColor,
|
|
460
|
+
snapToPixel: options.snapToPixel,
|
|
461
|
+
useDrawSorting: options.useDrawSorting
|
|
462
|
+
});
|
|
463
|
+
// Reset screen
|
|
464
|
+
if (this.screen) {
|
|
465
|
+
this.screen.dispose();
|
|
466
|
+
}
|
|
467
|
+
this.screen = new Screen({
|
|
468
|
+
canvas: this.canvas,
|
|
469
|
+
context: this.graphicsContext,
|
|
470
|
+
antialiasing: (_a = options.antialiasing) !== null && _a !== void 0 ? _a : true,
|
|
471
|
+
browser: this.browser,
|
|
472
|
+
viewport: (_b = options.viewport) !== null && _b !== void 0 ? _b : (options.width && options.height ? { width: options.width, height: options.height } : Resolution.SVGA),
|
|
473
|
+
resolution: options.resolution,
|
|
474
|
+
displayMode,
|
|
475
|
+
pixelRatio: options.suppressHiDPIScaling ? 1 : ((_c = options.pixelRatio) !== null && _c !== void 0 ? _c : null)
|
|
476
|
+
});
|
|
477
|
+
this.screen.setCurrentCamera(this.currentScene.camera);
|
|
478
|
+
// Reset pointers
|
|
479
|
+
this.input.pointers.detach();
|
|
480
|
+
const pointerTarget = options && options.pointerScope === PointerScope.Document ? document : this.canvas;
|
|
481
|
+
this.input.pointers = this.input.pointers.recreate(pointerTarget, this);
|
|
482
|
+
this.input.pointers.init();
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Returns a BoundingBox of the top left corner of the screen
|
|
486
|
+
* and the bottom right corner of the screen.
|
|
487
|
+
*/
|
|
488
|
+
getWorldBounds() {
|
|
489
|
+
return this.screen.getWorldBounds();
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Gets the current engine timescale factor (default is 1.0 which is 1:1 time)
|
|
493
|
+
*/
|
|
494
|
+
get timescale() {
|
|
495
|
+
return this._timescale;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Sets the current engine timescale factor. Useful for creating slow-motion effects or fast-forward effects
|
|
499
|
+
* when using time-based movement.
|
|
500
|
+
*/
|
|
501
|
+
set timescale(value) {
|
|
502
|
+
if (value <= 0) {
|
|
503
|
+
Logger.getInstance().error('Cannot set engine.timescale to a value of 0 or less than 0.');
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
this._timescale = value;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Adds a [[Timer]] to the [[currentScene]].
|
|
510
|
+
* @param timer The timer to add to the [[currentScene]].
|
|
511
|
+
*/
|
|
512
|
+
addTimer(timer) {
|
|
513
|
+
return this.currentScene.addTimer(timer);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Removes a [[Timer]] from the [[currentScene]].
|
|
517
|
+
* @param timer The timer to remove to the [[currentScene]].
|
|
518
|
+
*/
|
|
519
|
+
removeTimer(timer) {
|
|
520
|
+
return this.currentScene.removeTimer(timer);
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Adds a [[Scene]] to the engine, think of scenes in Excalibur as you
|
|
524
|
+
* would levels or menus.
|
|
525
|
+
* @param key The name of the scene, must be unique
|
|
526
|
+
* @param scene The scene to add to the engine
|
|
527
|
+
*/
|
|
528
|
+
addScene(key, scene) {
|
|
529
|
+
if (this.scenes[key]) {
|
|
530
|
+
this._logger.warn('Scene', key, 'already exists overwriting');
|
|
531
|
+
}
|
|
532
|
+
this.scenes[key] = scene;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* @internal
|
|
536
|
+
*/
|
|
537
|
+
removeScene(entity) {
|
|
538
|
+
if (entity instanceof Scene) {
|
|
539
|
+
// remove scene
|
|
540
|
+
for (const key in this.scenes) {
|
|
541
|
+
if (this.scenes.hasOwnProperty(key)) {
|
|
542
|
+
if (this.scenes[key] === entity) {
|
|
543
|
+
delete this.scenes[key];
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
if (typeof entity === 'string') {
|
|
549
|
+
// remove scene
|
|
550
|
+
delete this.scenes[entity];
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
add(entity) {
|
|
554
|
+
if (arguments.length === 2) {
|
|
555
|
+
this.addScene(arguments[0], arguments[1]);
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
if (this._deferredGoTo && this.scenes[this._deferredGoTo]) {
|
|
559
|
+
this.scenes[this._deferredGoTo].add(entity);
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
this.currentScene.add(entity);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
remove(entity) {
|
|
566
|
+
if (entity instanceof Entity) {
|
|
567
|
+
this.currentScene.remove(entity);
|
|
568
|
+
}
|
|
569
|
+
if (entity instanceof Scene) {
|
|
570
|
+
this.removeScene(entity);
|
|
571
|
+
}
|
|
572
|
+
if (typeof entity === 'string') {
|
|
573
|
+
this.removeScene(entity);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Changes the currently updating and drawing scene to a different,
|
|
578
|
+
* named scene. Calls the [[Scene]] lifecycle events.
|
|
579
|
+
* @param key The key of the scene to transition to.
|
|
580
|
+
* @param data Optional data to send to the scene's onActivate method
|
|
581
|
+
*/
|
|
582
|
+
goToScene(key, data) {
|
|
583
|
+
// if not yet initialized defer goToScene
|
|
584
|
+
if (!this.isInitialized) {
|
|
585
|
+
this._deferredGoTo = key;
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
if (this.scenes[key]) {
|
|
589
|
+
const previousScene = this.currentScene;
|
|
590
|
+
const nextScene = this.scenes[key];
|
|
591
|
+
this._logger.debug('Going to scene:', key);
|
|
592
|
+
// only deactivate when initialized
|
|
593
|
+
if (this.currentScene.isInitialized) {
|
|
594
|
+
const context = { engine: this, previousScene, nextScene };
|
|
595
|
+
this.currentScene._deactivate.apply(this.currentScene, [context, nextScene]);
|
|
596
|
+
this.currentScene.events.emit('deactivate', new DeactivateEvent(context, this.currentScene));
|
|
597
|
+
}
|
|
598
|
+
// set current scene to new one
|
|
599
|
+
this.currentScene = nextScene;
|
|
600
|
+
this.screen.setCurrentCamera(nextScene.camera);
|
|
601
|
+
// initialize the current scene if has not been already
|
|
602
|
+
this.currentScene._initialize(this);
|
|
603
|
+
const context = { engine: this, previousScene, nextScene, data };
|
|
604
|
+
this.currentScene._activate.apply(this.currentScene, [context, nextScene]);
|
|
605
|
+
this.currentScene.events.emit('activate', new ActivateEvent(context, this.currentScene));
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
this._logger.error('Scene', key, 'does not exist!');
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Transforms the current x, y from screen coordinates to world coordinates
|
|
613
|
+
* @param point Screen coordinate to convert
|
|
614
|
+
*/
|
|
615
|
+
screenToWorldCoordinates(point) {
|
|
616
|
+
return this.screen.screenToWorldCoordinates(point);
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Transforms a world coordinate, to a screen coordinate
|
|
620
|
+
* @param point World coordinate to convert
|
|
621
|
+
*/
|
|
622
|
+
worldToScreenCoordinates(point) {
|
|
623
|
+
return this.screen.worldToScreenCoordinates(point);
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Initializes the internal canvas, rendering context, display mode, and native event listeners
|
|
627
|
+
*/
|
|
628
|
+
_initialize(options) {
|
|
629
|
+
var _a, _b, _c, _d;
|
|
630
|
+
this.pageScrollPreventionMode = options.scrollPreventionMode;
|
|
631
|
+
// initialize inputs
|
|
632
|
+
const pointerTarget = options && options.pointerScope === PointerScope.Document ? document : this.canvas;
|
|
633
|
+
this.input = {
|
|
634
|
+
keyboard: new Keyboard(),
|
|
635
|
+
pointers: new PointerEventReceiver(pointerTarget, this),
|
|
636
|
+
gamepads: new Gamepads()
|
|
637
|
+
};
|
|
638
|
+
this.input.keyboard.init({
|
|
639
|
+
grabWindowFocus: (_b = (_a = this._originalOptions) === null || _a === void 0 ? void 0 : _a.grabWindowFocus) !== null && _b !== void 0 ? _b : true
|
|
640
|
+
});
|
|
641
|
+
this.input.pointers.init({
|
|
642
|
+
grabWindowFocus: (_d = (_c = this._originalOptions) === null || _c === void 0 ? void 0 : _c.grabWindowFocus) !== null && _d !== void 0 ? _d : true
|
|
643
|
+
});
|
|
644
|
+
this.input.gamepads.init();
|
|
645
|
+
this.inputMapper = new InputMapper(this.input);
|
|
646
|
+
// Issue #385 make use of the visibility api
|
|
647
|
+
// https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API
|
|
648
|
+
this.browser.document.on('visibilitychange', () => {
|
|
649
|
+
if (document.visibilityState === 'hidden') {
|
|
650
|
+
this.events.emit('hidden', new HiddenEvent(this));
|
|
651
|
+
this._logger.debug('Window hidden');
|
|
652
|
+
}
|
|
653
|
+
else if (document.visibilityState === 'visible') {
|
|
654
|
+
this.events.emit('visible', new VisibleEvent(this));
|
|
655
|
+
this._logger.debug('Window visible');
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
if (!this.canvasElementId && !options.canvasElement) {
|
|
659
|
+
document.body.appendChild(this.canvas);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
onInitialize(_engine) {
|
|
663
|
+
// Override me
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* If supported by the browser, this will set the antialiasing flag on the
|
|
667
|
+
* canvas. Set this to `false` if you want a 'jagged' pixel art look to your
|
|
668
|
+
* image resources.
|
|
669
|
+
* @param isSmooth Set smoothing to true or false
|
|
670
|
+
*/
|
|
671
|
+
setAntialiasing(isSmooth) {
|
|
672
|
+
this.screen.antialiasing = isSmooth;
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Return the current smoothing status of the canvas
|
|
676
|
+
*/
|
|
677
|
+
getAntialiasing() {
|
|
678
|
+
return this.screen.antialiasing;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Gets whether the actor is Initialized
|
|
682
|
+
*/
|
|
683
|
+
get isInitialized() {
|
|
684
|
+
return this._isInitialized;
|
|
685
|
+
}
|
|
686
|
+
_overrideInitialize(engine) {
|
|
687
|
+
if (!this.isInitialized) {
|
|
688
|
+
this.onInitialize(engine);
|
|
689
|
+
this.events.emit('initialize', new InitializeEvent(engine, this));
|
|
690
|
+
this._isInitialized = true;
|
|
691
|
+
if (this._deferredGoTo) {
|
|
692
|
+
const deferredScene = this._deferredGoTo;
|
|
693
|
+
this._deferredGoTo = null;
|
|
694
|
+
this.goToScene(deferredScene);
|
|
695
|
+
}
|
|
696
|
+
else {
|
|
697
|
+
this.goToScene('root');
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Updates the entire state of the game
|
|
703
|
+
* @param delta Number of milliseconds elapsed since the last update.
|
|
704
|
+
*/
|
|
705
|
+
_update(delta) {
|
|
706
|
+
if (!this.ready) {
|
|
707
|
+
// suspend updates until loading is finished
|
|
708
|
+
this._loader.update(this, delta);
|
|
709
|
+
// Update input listeners
|
|
710
|
+
this.inputMapper.execute();
|
|
711
|
+
this.input.keyboard.update();
|
|
712
|
+
this.input.gamepads.update();
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
// Publish preupdate events
|
|
716
|
+
this._preupdate(delta);
|
|
717
|
+
// process engine level events
|
|
718
|
+
this.currentScene.update(this, delta);
|
|
719
|
+
// Update graphics postprocessors
|
|
720
|
+
this.graphicsContext.updatePostProcessors(delta);
|
|
721
|
+
// Publish update event
|
|
722
|
+
this._postupdate(delta);
|
|
723
|
+
// Update input listeners
|
|
724
|
+
this.inputMapper.execute();
|
|
725
|
+
this.input.keyboard.update();
|
|
726
|
+
this.input.gamepads.update();
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* @internal
|
|
730
|
+
*/
|
|
731
|
+
_preupdate(delta) {
|
|
732
|
+
this.emit('preupdate', new PreUpdateEvent(this, delta, this));
|
|
733
|
+
this.onPreUpdate(this, delta);
|
|
734
|
+
}
|
|
735
|
+
onPreUpdate(_engine, _delta) {
|
|
736
|
+
// Override me
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* @internal
|
|
740
|
+
*/
|
|
741
|
+
_postupdate(delta) {
|
|
742
|
+
this.emit('postupdate', new PostUpdateEvent(this, delta, this));
|
|
743
|
+
this.onPostUpdate(this, delta);
|
|
744
|
+
}
|
|
745
|
+
onPostUpdate(_engine, _delta) {
|
|
746
|
+
// Override me
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Draws the entire game
|
|
750
|
+
* @param delta Number of milliseconds elapsed since the last draw.
|
|
751
|
+
*/
|
|
752
|
+
_draw(delta) {
|
|
753
|
+
this.graphicsContext.beginDrawLifecycle();
|
|
754
|
+
this.graphicsContext.clear();
|
|
755
|
+
this._predraw(this.graphicsContext, delta);
|
|
756
|
+
// Drawing nothing else while loading
|
|
757
|
+
if (!this._isReady) {
|
|
758
|
+
this._loader.canvas.draw(this.graphicsContext, 0, 0);
|
|
759
|
+
this.graphicsContext.flush();
|
|
760
|
+
return;
|
|
761
|
+
}
|
|
762
|
+
this.graphicsContext.backgroundColor = this.backgroundColor;
|
|
763
|
+
this.currentScene.draw(this.graphicsContext, delta);
|
|
764
|
+
this._postdraw(this.graphicsContext, delta);
|
|
765
|
+
// Flush any pending drawings
|
|
766
|
+
this.graphicsContext.flush();
|
|
767
|
+
this.graphicsContext.endDrawLifecycle();
|
|
768
|
+
this._checkForScreenShots();
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* @internal
|
|
772
|
+
*/
|
|
773
|
+
_predraw(_ctx, delta) {
|
|
774
|
+
this.emit('predraw', new PreDrawEvent(_ctx, delta, this));
|
|
775
|
+
this.onPreDraw(_ctx, delta);
|
|
776
|
+
}
|
|
777
|
+
onPreDraw(_ctx, _delta) {
|
|
778
|
+
// Override me
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* @internal
|
|
782
|
+
*/
|
|
783
|
+
_postdraw(_ctx, delta) {
|
|
784
|
+
this.emit('postdraw', new PostDrawEvent(_ctx, delta, this));
|
|
785
|
+
this.onPostDraw(_ctx, delta);
|
|
786
|
+
}
|
|
787
|
+
onPostDraw(_ctx, _delta) {
|
|
788
|
+
// Override me
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Enable or disable Excalibur debugging functionality.
|
|
792
|
+
* @param toggle a value that debug drawing will be changed to
|
|
793
|
+
*/
|
|
794
|
+
showDebug(toggle) {
|
|
795
|
+
this._isDebug = toggle;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Toggle Excalibur debugging functionality.
|
|
799
|
+
*/
|
|
800
|
+
toggleDebug() {
|
|
801
|
+
this._isDebug = !this._isDebug;
|
|
802
|
+
return this._isDebug;
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Returns true when loading is totally complete and the player has clicked start
|
|
806
|
+
*/
|
|
807
|
+
get loadingComplete() {
|
|
808
|
+
return this._loadingComplete;
|
|
809
|
+
}
|
|
810
|
+
get ready() {
|
|
811
|
+
return this._isReady;
|
|
812
|
+
}
|
|
813
|
+
isReady() {
|
|
814
|
+
return this._isReadyPromise;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Starts the internal game loop for Excalibur after loading
|
|
818
|
+
* any provided assets.
|
|
819
|
+
* @param loader Optional [[Loader]] to use to load resources. The default loader is [[Loader]], override to provide your own
|
|
820
|
+
* custom loader.
|
|
821
|
+
*
|
|
822
|
+
* Note: start() only resolves AFTER the user has clicked the play button
|
|
823
|
+
*/
|
|
824
|
+
async start(loader) {
|
|
825
|
+
if (!this._compatible) {
|
|
826
|
+
throw new Error('Excalibur is incompatible with your browser');
|
|
827
|
+
}
|
|
828
|
+
// Wire loader if we have it
|
|
829
|
+
if (loader) {
|
|
830
|
+
// Push the current user entered resolution/viewport
|
|
831
|
+
this.screen.pushResolutionAndViewport();
|
|
832
|
+
// Configure resolution for loader, it expects resolution === viewport
|
|
833
|
+
this.screen.resolution = this.screen.viewport;
|
|
834
|
+
this.screen.applyResolutionAndViewport();
|
|
835
|
+
this._loader = loader;
|
|
836
|
+
this._loader.suppressPlayButton = this._suppressPlayButton || this._loader.suppressPlayButton;
|
|
837
|
+
this._loader.wireEngine(this);
|
|
838
|
+
}
|
|
839
|
+
// Start the excalibur clock which drives the mainloop
|
|
840
|
+
// has started is a slight misnomer, it's really mainloop started
|
|
841
|
+
this._logger.debug('Starting game clock...');
|
|
842
|
+
this.browser.resume();
|
|
843
|
+
this.clock.start();
|
|
844
|
+
this._logger.debug('Game clock started');
|
|
845
|
+
if (loader) {
|
|
846
|
+
await this.load(this._loader);
|
|
847
|
+
this._loadingComplete = true;
|
|
848
|
+
// reset back to previous user resolution/viewport
|
|
849
|
+
this.screen.popResolutionAndViewport();
|
|
850
|
+
this.screen.applyResolutionAndViewport();
|
|
851
|
+
}
|
|
852
|
+
this._loadingComplete = true;
|
|
853
|
+
// Initialize before ready
|
|
854
|
+
this._overrideInitialize(this);
|
|
855
|
+
this._isReady = true;
|
|
856
|
+
this._isReadyResolve();
|
|
857
|
+
this.emit('start', new GameStartEvent(this));
|
|
858
|
+
return this._isReadyPromise;
|
|
859
|
+
}
|
|
860
|
+
_mainloop(elapsed) {
|
|
861
|
+
this.emit('preframe', new PreFrameEvent(this, this.stats.prevFrame));
|
|
862
|
+
const delta = elapsed * this.timescale;
|
|
863
|
+
this.currentFrameElapsedMs = delta;
|
|
864
|
+
// reset frame stats (reuse existing instances)
|
|
865
|
+
const frameId = this.stats.prevFrame.id + 1;
|
|
866
|
+
this.stats.currFrame.reset();
|
|
867
|
+
this.stats.currFrame.id = frameId;
|
|
868
|
+
this.stats.currFrame.delta = delta;
|
|
869
|
+
this.stats.currFrame.fps = this.clock.fpsSampler.fps;
|
|
870
|
+
GraphicsDiagnostics.clear();
|
|
871
|
+
const beforeUpdate = this.clock.now();
|
|
872
|
+
const fixedTimestepMs = 1000 / this.fixedUpdateFps;
|
|
873
|
+
if (this.fixedUpdateFps) {
|
|
874
|
+
this._lagMs += delta;
|
|
875
|
+
while (this._lagMs >= fixedTimestepMs) {
|
|
876
|
+
this._update(fixedTimestepMs);
|
|
877
|
+
this._lagMs -= fixedTimestepMs;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
else {
|
|
881
|
+
this._update(delta);
|
|
882
|
+
}
|
|
883
|
+
const afterUpdate = this.clock.now();
|
|
884
|
+
this.currentFrameLagMs = this._lagMs;
|
|
885
|
+
this._draw(delta);
|
|
886
|
+
const afterDraw = this.clock.now();
|
|
887
|
+
this.stats.currFrame.duration.update = afterUpdate - beforeUpdate;
|
|
888
|
+
this.stats.currFrame.duration.draw = afterDraw - afterUpdate;
|
|
889
|
+
this.stats.currFrame.graphics.drawnImages = GraphicsDiagnostics.DrawnImagesCount;
|
|
890
|
+
this.stats.currFrame.graphics.drawCalls = GraphicsDiagnostics.DrawCallCount;
|
|
891
|
+
this.emit('postframe', new PostFrameEvent(this, this.stats.currFrame));
|
|
892
|
+
this.stats.prevFrame.reset(this.stats.currFrame);
|
|
893
|
+
this._monitorPerformanceThresholdAndTriggerFallback();
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Stops Excalibur's main loop, useful for pausing the game.
|
|
897
|
+
*/
|
|
898
|
+
stop() {
|
|
899
|
+
if (this.clock.isRunning()) {
|
|
900
|
+
this.emit('stop', new GameStopEvent(this));
|
|
901
|
+
this.browser.pause();
|
|
902
|
+
this.clock.stop();
|
|
903
|
+
this._logger.debug('Game stopped');
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Returns the Engine's running status, Useful for checking whether engine is running or paused.
|
|
908
|
+
*/
|
|
909
|
+
isRunning() {
|
|
910
|
+
return this.clock.isRunning();
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Takes a screen shot of the current viewport and returns it as an
|
|
914
|
+
* HTML Image Element.
|
|
915
|
+
* @param preserveHiDPIResolution in the case of HiDPI return the full scaled backing image, by default false
|
|
916
|
+
*/
|
|
917
|
+
screenshot(preserveHiDPIResolution = false) {
|
|
918
|
+
const screenShotPromise = new Promise((resolve) => {
|
|
919
|
+
this._screenShotRequests.push({ preserveHiDPIResolution, resolve });
|
|
920
|
+
});
|
|
921
|
+
return screenShotPromise;
|
|
922
|
+
}
|
|
923
|
+
_checkForScreenShots() {
|
|
924
|
+
// We must grab the draw buffer before we yield to the browser
|
|
925
|
+
// the draw buffer is cleared after compositing
|
|
926
|
+
// the reason for the asynchrony is setting `preserveDrawingBuffer: true`
|
|
927
|
+
// forces the browser to copy buffers which can have a mass perf impact on mobile
|
|
928
|
+
for (const request of this._screenShotRequests) {
|
|
929
|
+
const finalWidth = request.preserveHiDPIResolution ? this.canvas.width : this.screen.resolution.width;
|
|
930
|
+
const finalHeight = request.preserveHiDPIResolution ? this.canvas.height : this.screen.resolution.height;
|
|
931
|
+
const screenshot = document.createElement('canvas');
|
|
932
|
+
screenshot.width = finalWidth;
|
|
933
|
+
screenshot.height = finalHeight;
|
|
934
|
+
const ctx = screenshot.getContext('2d');
|
|
935
|
+
ctx.imageSmoothingEnabled = this.screen.antialiasing;
|
|
936
|
+
ctx.drawImage(this.canvas, 0, 0, finalWidth, finalHeight);
|
|
937
|
+
const result = new Image();
|
|
938
|
+
const raw = screenshot.toDataURL('image/png');
|
|
939
|
+
result.src = raw;
|
|
940
|
+
request.resolve(result);
|
|
941
|
+
}
|
|
942
|
+
// Reset state
|
|
943
|
+
this._screenShotRequests.length = 0;
|
|
944
|
+
}
|
|
945
|
+
/**
|
|
946
|
+
* Another option available to you to load resources into the game.
|
|
947
|
+
* Immediately after calling this the game will pause and the loading screen
|
|
948
|
+
* will appear.
|
|
949
|
+
* @param loader Some [[Loadable]] such as a [[Loader]] collection, [[Sound]], or [[Texture]].
|
|
950
|
+
*/
|
|
951
|
+
async load(loader) {
|
|
952
|
+
try {
|
|
953
|
+
await loader.load();
|
|
954
|
+
}
|
|
955
|
+
catch (e) {
|
|
956
|
+
this._logger.error('Error loading resources, things may not behave properly', e);
|
|
957
|
+
await Promise.resolve();
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
/**
|
|
962
|
+
* Default [[EngineOptions]]
|
|
963
|
+
*/
|
|
964
|
+
Engine._DEFAULT_ENGINE_OPTIONS = {
|
|
965
|
+
width: 0,
|
|
966
|
+
height: 0,
|
|
967
|
+
enableCanvasTransparency: true,
|
|
968
|
+
useDrawSorting: true,
|
|
969
|
+
configurePerformanceCanvas2DFallback: {
|
|
970
|
+
allow: false,
|
|
971
|
+
showPlayerMessage: false,
|
|
972
|
+
threshold: { fps: 20, numberOfFrames: 100 }
|
|
973
|
+
},
|
|
974
|
+
canvasElementId: '',
|
|
975
|
+
canvasElement: undefined,
|
|
976
|
+
snapToPixel: false,
|
|
977
|
+
pointerScope: PointerScope.Canvas,
|
|
978
|
+
suppressConsoleBootMessage: null,
|
|
979
|
+
suppressMinimumBrowserFeatureDetection: null,
|
|
980
|
+
suppressHiDPIScaling: null,
|
|
981
|
+
suppressPlayButton: null,
|
|
982
|
+
grabWindowFocus: true,
|
|
983
|
+
scrollPreventionMode: ScrollPreventionMode.Canvas,
|
|
984
|
+
backgroundColor: Color.fromHex('#2185d0') // Excalibur blue
|
|
985
|
+
};
|
|
986
|
+
//# sourceMappingURL=Engine.js.map
|