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