phaser/v2-community/docs/src_plugins_weapon_WeaponPlugin.js.html

2833 lines
88 KiB
HTML
Raw Normal View History

2016-06-17 00:11:24 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Phaser Source: src/plugins/weapon/WeaponPlugin.js</title>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/default.css">
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
</head>
<body>
<div class="container-fluid">
<div class="navbar navbar-fixed-top navbar-inverse">
<div style="position: absolute; width: 143px; height: 31px; right: 10px; top: 10px; z-index: 1050"><a href="http://phaser.io"><img src="img/phaser.png" border="0" /></a></div>
<div class="navbar-inner">
<a class="brand" href="index.html">Phaser API</a>
<ul class="nav">
<li class="dropdown">
<a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li class="class-depth-0">
<a href="Phaser.html">Phaser</a>
</li>
<li class="class-depth-0">
<a href="PIXI.html">PIXI</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
class="caret"></b></a>
<ul class="dropdown-menu ">
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="EarCut.html">EarCut</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-0">
<a href="Event.html">Event</a>
</li>
<li class="class-depth-0">
<a href="EventTarget.html">EventTarget</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-1">
<a href="Phaser.Animation.html">Animation</a>
</li>
<li class="class-depth-1">
<a href="Phaser.AnimationManager.html">AnimationManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.AnimationParser.html">AnimationParser</a>
</li>
<li class="class-depth-1">
<a href="Phaser.ArraySet.html">ArraySet</a>
</li>
<li class="class-depth-1">
<a href="Phaser.ArrayUtils.html">ArrayUtils</a>
</li>
<li class="class-depth-1">
<a href="Phaser.AudioSprite.html">AudioSprite</a>
</li>
<li class="class-depth-1">
<a href="Phaser.BitmapData.html">BitmapData</a>
</li>
<li class="class-depth-1">
<a href="Phaser.BitmapText.html">BitmapText</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Bullet.html">Bullet</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Button.html">Button</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Cache.html">Cache</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Camera.html">Camera</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Canvas.html">Canvas</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-1">
<a href="Phaser.CanvasPool.html">CanvasPool</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-1">
<a href="Phaser.Circle.html">Circle</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Color.html">Color</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.Angle.html">Angle</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.Animation.html">Animation</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.AutoCull.html">AutoCull</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.Bounds.html">Bounds</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.BringToTop.html">BringToTop</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.Core.html">Core</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.Crop.html">Crop</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.Delta.html">Delta</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.Destroy.html">Destroy</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.FixedToCamera.html">FixedToCamera</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.Health.html">Health</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.InCamera.html">InCamera</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.InputEnabled.html">InputEnabled</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.InWorld.html">InWorld</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.LifeSpan.html">LifeSpan</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.LoadTexture.html">LoadTexture</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.Overlap.html">Overlap</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.PhysicsBody.html">PhysicsBody</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.Reset.html">Reset</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.ScaleMinMax.html">ScaleMinMax</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Component.Smoothed.html">Smoothed</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Create.html">Create</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Creature.html">Creature</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Device.html">Device</a>
</li>
<li class="class-depth-1">
<a href="Phaser.DeviceButton.html">DeviceButton</a>
</li>
<li class="class-depth-1">
<a href="Phaser.DOM.html">DOM</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Easing.html">Easing</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Easing.Back.html">Back</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Easing.Bounce.html">Bounce</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Easing.Circular.html">Circular</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Easing.Cubic.html">Cubic</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Easing.Elastic.html">Elastic</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Easing.Exponential.html">Exponential</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Easing.Linear.html">Linear</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Easing.Quadratic.html">Quadratic</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Easing.Quartic.html">Quartic</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Easing.Quintic.html">Quintic</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Easing.Sinusoidal.html">Sinusoidal</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Ellipse.html">Ellipse</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Events.html">Events</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Filter.html">Filter</a>
</li>
<li class="class-depth-1">
<a href="Phaser.FlexGrid.html">FlexGrid</a>
</li>
<li class="class-depth-1">
<a href="Phaser.FlexLayer.html">FlexLayer</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Frame.html">Frame</a>
</li>
<li class="class-depth-1">
<a href="Phaser.FrameData.html">FrameData</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Game.html">Game</a>
</li>
<li class="class-depth-1">
<a href="Phaser.GameObjectCreator.html">GameObjectCreator</a>
</li>
<li class="class-depth-1">
<a href="Phaser.GameObjectFactory.html">GameObjectFactory</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Gamepad.html">Gamepad</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Graphics.html">Graphics</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Group.html">Group</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-1">
<a href="Phaser.Hermite.html">Hermite</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-1">
<a href="Phaser.Image.html">Image</a>
</li>
<li class="class-depth-1">
<a href="Phaser.ImageCollection.html">ImageCollection</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Input.html">Input</a>
</li>
<li class="class-depth-1">
<a href="Phaser.InputHandler.html">InputHandler</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Key.html">Key</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Keyboard.html">Keyboard</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-1">
<a href="Phaser.KeyCode.html">KeyCode</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-1">
<a href="Phaser.Line.html">Line</a>
</li>
<li class="class-depth-1">
<a href="Phaser.LinkedList.html">LinkedList</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Loader.html">Loader</a>
</li>
<li class="class-depth-1">
<a href="Phaser.LoaderParser.html">LoaderParser</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Math.html">Math</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Matrix.html">Matrix</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Mouse.html">Mouse</a>
</li>
<li class="class-depth-1">
<a href="Phaser.MSPointer.html">MSPointer</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Net.html">Net</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Particle.html">Particle</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Particles.html">Particles</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Particles.Arcade.html">Arcade</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Particles.Arcade.Emitter.html">Emitter</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-1">
<a href="Phaser.Path.html">Path</a>
</li>
<li class="class-depth-1">
<a href="Phaser.PathFollower.html">PathFollower</a>
</li>
<li class="class-depth-1">
<a href="Phaser.PathPoint.html">PathPoint</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-1">
<a href="Phaser.Physics.html">Physics</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Physics.Arcade.html">Arcade</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.Arcade.Body.html">Body</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.Arcade.TilemapCollision.html">TilemapCollision</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Physics.Ninja.html">Ninja</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.AABB.html">AABB</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Body.html">Body</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Circle.html">Circle</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Tile.html">Tile</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Physics.P2.html">P2</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Body.html">Body</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.BodyDebug.html">BodyDebug</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.CollisionGroup.html">CollisionGroup</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.ContactMaterial.html">ContactMaterial</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.DistanceConstraint.html">DistanceConstraint</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.FixtureList.html">FixtureList</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.GearConstraint.html">GearConstraint</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.InversePointProxy.html">InversePointProxy</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.LockConstraint.html">LockConstraint</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Material.html">Material</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.PointProxy.html">PointProxy</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.PrismaticConstraint.html">PrismaticConstraint</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.RevoluteConstraint.html">RevoluteConstraint</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.RotationalSpring.html">RotationalSpring</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Spring.html">Spring</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Plugin.html">Plugin</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-2">
<a href="Phaser.Plugin.PathManager.html">PathManager</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-1">
<a href="Phaser.PluginManager.html">PluginManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Point.html">Point</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Pointer.html">Pointer</a>
</li>
<li class="class-depth-1">
<a href="Phaser.PointerMode.html">PointerMode</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Polygon.html">Polygon</a>
</li>
<li class="class-depth-1">
<a href="Phaser.QuadTree.html">QuadTree</a>
</li>
<li class="class-depth-1">
<a href="Phaser.RandomDataGenerator.html">RandomDataGenerator</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Rectangle.html">Rectangle</a>
</li>
<li class="class-depth-1">
<a href="Phaser.RenderTexture.html">RenderTexture</a>
</li>
<li class="class-depth-1">
<a href="Phaser.RequestAnimationFrame.html">RequestAnimationFrame</a>
</li>
<li class="class-depth-1">
<a href="Phaser.RetroFont.html">RetroFont</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Rope.html">Rope</a>
</li>
<li class="class-depth-1">
<a href="Phaser.RoundedRectangle.html">RoundedRectangle</a>
</li>
<li class="class-depth-1">
<a href="Phaser.ScaleManager.html">ScaleManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Signal.html">Signal</a>
</li>
<li class="class-depth-1">
<a href="Phaser.SignalBinding.html">SignalBinding</a>
</li>
<li class="class-depth-1">
<a href="Phaser.SinglePad.html">SinglePad</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Sound.html">Sound</a>
</li>
<li class="class-depth-1">
<a href="Phaser.SoundManager.html">SoundManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Sprite.html">Sprite</a>
</li>
<li class="class-depth-1">
<a href="Phaser.SpriteBatch.html">SpriteBatch</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Stage.html">Stage</a>
</li>
<li class="class-depth-1">
<a href="Phaser.State.html">State</a>
</li>
<li class="class-depth-1">
<a href="Phaser.StateManager.html">StateManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Text.html">Text</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Tile.html">Tile</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Tilemap.html">Tilemap</a>
</li>
<li class="class-depth-1">
<a href="Phaser.TilemapLayer.html">TilemapLayer</a>
</li>
<li class="class-depth-1">
<a href="Phaser.TilemapParser.html">TilemapParser</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Tileset.html">Tileset</a>
</li>
<li class="class-depth-1">
<a href="Phaser.TileSprite.html">TileSprite</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Time.html">Time</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Timer.html">Timer</a>
</li>
<li class="class-depth-1">
<a href="Phaser.TimerEvent.html">TimerEvent</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Touch.html">Touch</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Tween.html">Tween</a>
</li>
<li class="class-depth-1">
<a href="Phaser.TweenData.html">TweenData</a>
</li>
<li class="class-depth-1">
<a href="Phaser.TweenManager.html">TweenManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Utils.html">Utils</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Utils.Debug.html">Debug</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Video.html">Video</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Weapon.html">Weapon</a>
</li>
<li class="class-depth-1">
<a href="Phaser.World.html">World</a>
</li>
<li class="class-depth-1">
<a href="PIXI.BaseTexture.html">BaseTexture</a>
</li>
<li class="class-depth-1">
<a href="PIXI.CanvasBuffer.html">CanvasBuffer</a>
</li>
<li class="class-depth-1">
<a href="PIXI.CanvasGraphics.html">CanvasGraphics</a>
</li>
<li class="class-depth-1">
<a href="PIXI.CanvasMaskManager.html">CanvasMaskManager</a>
</li>
<li class="class-depth-1">
<a href="PIXI.CanvasRenderer.html">CanvasRenderer</a>
</li>
<li class="class-depth-1">
<a href="PIXI.CanvasTinter.html">CanvasTinter</a>
</li>
<li class="class-depth-1">
<a href="PIXI.ComplexPrimitiveShader.html">ComplexPrimitiveShader</a>
</li>
<li class="class-depth-1">
<a href="PIXI.DisplayObjectContainer.html">DisplayObjectContainer</a>
</li>
<li class="class-depth-1">
<a href="PIXI.FilterTexture.html">FilterTexture</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-2">
<a href="PIXI.Phaser.GraphicsData.html">Phaser.GraphicsData</a>
2016-06-17 00:11:24 +00:00
</li>
<li class="class-depth-1">
<a href="PIXI.PIXI.html">PIXI</a>
</li>
2016-07-01 15:57:13 +00:00
<li class="class-depth-2">
<a href="PIXI.PIXI.DisplayObject.html">DisplayObject</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-1">
<a href="PIXI.PixiFastShader.html">PixiFastShader</a>
</li>
<li class="class-depth-1">
<a href="PIXI.PixiShader.html">PixiShader</a>
</li>
<li class="class-depth-1">
<a href="PIXI.PrimitiveShader.html">PrimitiveShader</a>
</li>
<li class="class-depth-1">
<a href="PIXI.Sprite.html">Sprite</a>
</li>
<li class="class-depth-1">
<a href="PIXI.StripShader.html">StripShader</a>
</li>
<li class="class-depth-1">
<a href="PIXI.Texture.html">Texture</a>
</li>
<li class="class-depth-1">
<a href="PIXI.WebGLBlendModeManager.html">WebGLBlendModeManager</a>
</li>
<li class="class-depth-1">
<a href="PIXI.WebGLFastSpriteBatch.html">WebGLFastSpriteBatch</a>
</li>
<li class="class-depth-1">
<a href="PIXI.WebGLFilterManager.html">WebGLFilterManager</a>
</li>
<li class="class-depth-1">
<a href="PIXI.WebGLRenderer.html">WebGLRenderer</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li class="class-depth-0">
<a href="global.html#ANGLE_DOWN">ANGLE_DOWN</a>
</li>
<li class="class-depth-0">
<a href="global.html#ANGLE_LEFT">ANGLE_LEFT</a>
</li>
<li class="class-depth-0">
<a href="global.html#ANGLE_NORTH_EAST">ANGLE_NORTH_EAST</a>
</li>
<li class="class-depth-0">
<a href="global.html#ANGLE_NORTH_WEST">ANGLE_NORTH_WEST</a>
</li>
<li class="class-depth-0">
<a href="global.html#ANGLE_RIGHT">ANGLE_RIGHT</a>
</li>
<li class="class-depth-0">
<a href="global.html#ANGLE_SOUTH_EAST">ANGLE_SOUTH_EAST</a>
</li>
<li class="class-depth-0">
<a href="global.html#ANGLE_SOUTH_WEST">ANGLE_SOUTH_WEST</a>
</li>
<li class="class-depth-0">
<a href="global.html#ANGLE_UP">ANGLE_UP</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#arc">arc</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#AUTO">AUTO</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#beginFill">beginFill</a>
</li>
<li class="class-depth-0">
<a href="global.html#bezierCurveTo">bezierCurveTo</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#BITMAPDATA">BITMAPDATA</a>
</li>
<li class="class-depth-0">
<a href="global.html#BITMAPTEXT">BITMAPTEXT</a>
</li>
<li class="class-depth-0">
<a href="global.html#blendModes">blendModes</a>
</li>
<li class="class-depth-0">
<a href="global.html#BOTTOM_CENTER">BOTTOM_CENTER</a>
</li>
<li class="class-depth-0">
<a href="global.html#BOTTOM_LEFT">BOTTOM_LEFT</a>
</li>
<li class="class-depth-0">
<a href="global.html#BOTTOM_RIGHT">BOTTOM_RIGHT</a>
</li>
<li class="class-depth-0">
<a href="global.html#BUTTON">BUTTON</a>
</li>
<li class="class-depth-0">
<a href="global.html#CANVAS">CANVAS</a>
</li>
<li class="class-depth-0">
<a href="global.html#CANVAS_FILTER">CANVAS_FILTER</a>
</li>
<li class="class-depth-0">
<a href="global.html#CENTER">CENTER</a>
</li>
<li class="class-depth-0">
<a href="global.html#CIRCLE">CIRCLE</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#clear">clear</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#CREATURE">CREATURE</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#destroyCachedSprite">destroyCachedSprite</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#displayList">displayList</a>
</li>
<li class="class-depth-0">
<a href="global.html#DOWN">DOWN</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#drawCircle">drawCircle</a>
</li>
<li class="class-depth-0">
<a href="global.html#drawEllipse">drawEllipse</a>
</li>
<li class="class-depth-0">
<a href="global.html#drawPolygon">drawPolygon</a>
</li>
<li class="class-depth-0">
<a href="global.html#drawRect">drawRect</a>
</li>
<li class="class-depth-0">
<a href="global.html#drawRoundedRect">drawRoundedRect</a>
</li>
<li class="class-depth-0">
<a href="global.html#drawShape">drawShape</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#ELLIPSE">ELLIPSE</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-0">
<a href="global.html#emit">emit</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#EMITTER">EMITTER</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#endFill">endFill</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#GAMES">GAMES</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#generateTexture">generateTexture</a>
</li>
<li class="class-depth-0">
<a href="global.html#getBounds">getBounds</a>
</li>
<li class="class-depth-0">
<a href="global.html#getLocalBounds">getLocalBounds</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#GRAPHICS">GRAPHICS</a>
</li>
<li class="class-depth-0">
<a href="global.html#GROUP">GROUP</a>
</li>
<li class="class-depth-0">
<a href="global.html#HEADLESS">HEADLESS</a>
</li>
<li class="class-depth-0">
<a href="global.html#HORIZONTAL">HORIZONTAL</a>
</li>
<li class="class-depth-0">
<a href="global.html#IMAGE">IMAGE</a>
</li>
<li class="class-depth-0">
<a href="global.html#LANDSCAPE">LANDSCAPE</a>
</li>
<li class="class-depth-0">
<a href="global.html#LEFT">LEFT</a>
</li>
<li class="class-depth-0">
<a href="global.html#LEFT_BOTTOM">LEFT_BOTTOM</a>
</li>
<li class="class-depth-0">
<a href="global.html#LEFT_CENTER">LEFT_CENTER</a>
</li>
<li class="class-depth-0">
<a href="global.html#LEFT_TOP">LEFT_TOP</a>
</li>
<li class="class-depth-0">
<a href="global.html#LINE">LINE</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#lineStyle">lineStyle</a>
</li>
<li class="class-depth-0">
<a href="global.html#lineTo">lineTo</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-0">
<a href="global.html#listeners">listeners</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#MATRIX">MATRIX</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-0">
<a href="global.html#mixin">mixin</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#moveTo">moveTo</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#NONE">NONE</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-0">
<a href="global.html#off">off</a>
</li>
<li class="class-depth-0">
<a href="global.html#on">on</a>
</li>
<li class="class-depth-0">
<a href="global.html#once">once</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#PENDING_ATLAS">PENDING_ATLAS</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-2">
<a href="global.html#Phaser.Path#numPointsreturn%257Bnumber%257DThetotalnumberofPathPointsinthisPath.">Phaser.Path#numPoints
return {number} The total number of PathPoints in this Path.</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#POINT">POINT</a>
</li>
<li class="class-depth-0">
<a href="global.html#POINTER">POINTER</a>
</li>
<li class="class-depth-0">
<a href="global.html#POLYGON">POLYGON</a>
</li>
<li class="class-depth-0">
<a href="global.html#PORTRAIT">PORTRAIT</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#quadraticCurveTo">quadraticCurveTo</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#RECTANGLE">RECTANGLE</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-0">
<a href="global.html#removeAllListeners">removeAllListeners</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#RENDERTEXTURE">RENDERTEXTURE</a>
</li>
<li class="class-depth-0">
<a href="global.html#RETROFONT">RETROFONT</a>
</li>
<li class="class-depth-0">
<a href="global.html#RIGHT">RIGHT</a>
</li>
<li class="class-depth-0">
<a href="global.html#RIGHT_BOTTOM">RIGHT_BOTTOM</a>
</li>
<li class="class-depth-0">
<a href="global.html#RIGHT_CENTER">RIGHT_CENTER</a>
</li>
<li class="class-depth-0">
<a href="global.html#RIGHT_TOP">RIGHT_TOP</a>
</li>
<li class="class-depth-0">
<a href="global.html#ROPE">ROPE</a>
</li>
<li class="class-depth-0">
<a href="global.html#ROUNDEDRECTANGLE">ROUNDEDRECTANGLE</a>
</li>
<li class="class-depth-0">
<a href="global.html#scaleModes">scaleModes</a>
</li>
<li class="class-depth-0">
<a href="global.html#SPRITE">SPRITE</a>
</li>
<li class="class-depth-0">
<a href="global.html#SPRITEBATCH">SPRITEBATCH</a>
</li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-0">
<a href="global.html#stopImmediatePropagation">stopImmediatePropagation</a>
</li>
<li class="class-depth-0">
<a href="global.html#stopPropagation">stopPropagation</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#TEXT">TEXT</a>
</li>
<li class="class-depth-0">
<a href="global.html#TILEMAP">TILEMAP</a>
</li>
<li class="class-depth-0">
<a href="global.html#TILEMAPLAYER">TILEMAPLAYER</a>
</li>
<li class="class-depth-0">
<a href="global.html#TILESPRITE">TILESPRITE</a>
</li>
<li class="class-depth-0">
<a href="global.html#TOP_CENTER">TOP_CENTER</a>
</li>
<li class="class-depth-0">
<a href="global.html#TOP_LEFT">TOP_LEFT</a>
</li>
<li class="class-depth-0">
<a href="global.html#TOP_RIGHT">TOP_RIGHT</a>
</li>
<li class="class-depth-0">
<a href="global.html#UP">UP</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#updateLocalBounds">updateLocalBounds</a>
</li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-0">
<a href="global.html#VERSION">VERSION</a>
</li>
<li class="class-depth-0">
<a href="global.html#VERTICAL">VERTICAL</a>
</li>
<li class="class-depth-0">
<a href="global.html#VIDEO">VIDEO</a>
</li>
<li class="class-depth-0">
<a href="global.html#WEBGL">WEBGL</a>
</li>
<li class="class-depth-0">
<a href="global.html#WEBGL_FILTER">WEBGL_FILTER</a>
</li>
2016-11-23 00:59:32 +00:00
<li class="class-depth-0">
<a href="global.html#WEBGL_MULTI">WEBGL_MULTI</a>
</li>
2016-06-17 00:11:24 +00:00
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Core<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li class="class-depth-1"><a href="Phaser.Game.html">Game</a></li>
<li class="class-depth-1"><a href="Phaser.Group.html">Group</a></li>
<li class="class-depth-1"><a href="Phaser.World.html">World</a></li>
<li class="class-depth-1"><a href="Phaser.Loader.html">Loader</a></li>
<li class="class-depth-1"><a href="Phaser.Cache.html">Cache</a></li>
<li class="class-depth-1"><a href="Phaser.Time.html">Time</a></li>
<li class="class-depth-1"><a href="Phaser.Camera.html">Camera</a></li>
<li class="class-depth-1"><a href="Phaser.StateManager.html">State Manager</a></li>
<li class="class-depth-1"><a href="Phaser.TweenManager.html">Tween Manager</a></li>
<li class="class-depth-1"><a href="Phaser.SoundManager.html">Sound Manager</a></li>
<li class="class-depth-1"><a href="Phaser.Input.html">Input Manager</a></li>
<li class="class-depth-1"><a href="Phaser.ScaleManager.html">Scale Manager</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Game Objects<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li class="class-depth-1"><a href="Phaser.GameObjectFactory.html">Factory (game.add)</a></li>
<li class="class-depth-1"><a href="Phaser.GameObjectCreator.html">Creator (game.make)</a></li>
<li class="class-depth-1"><a href="Phaser.Sprite.html">Sprite</a></li>
<li class="class-depth-1"><a href="Phaser.Image.html">Image</a></li>
<li class="class-depth-1"><a href="Phaser.Sound.html">Sound</a></li>
<li class="class-depth-1"><a href="Phaser.Video.html">Video</a></li>
<li class="class-depth-1"><a href="Phaser.Particles.Arcade.Emitter.html">Particle Emitter</a></li>
<li class="class-depth-1"><a href="Phaser.Particle.html">Particle</a></li>
<li class="class-depth-1"><a href="Phaser.Text.html">Text</a></li>
<li class="class-depth-1"><a href="Phaser.Tween.html">Tween</a></li>
<li class="class-depth-1"><a href="Phaser.BitmapText.html">BitmapText</a></li>
<li class="class-depth-1"><a href="Phaser.Tilemap.html">Tilemap</a></li>
<li class="class-depth-1"><a href="Phaser.BitmapData.html">BitmapData</a></li>
<li class="class-depth-1"><a href="Phaser.RetroFont.html">RetroFont</a></li>
<li class="class-depth-1"><a href="Phaser.Button.html">Button</a></li>
<li class="class-depth-1"><a href="Phaser.Animation.html">Animation</a></li>
<li class="class-depth-1"><a href="Phaser.Graphics.html">Graphics</a></li>
<li class="class-depth-1"><a href="Phaser.RenderTexture.html">RenderTexture</a></li>
<li class="class-depth-1"><a href="Phaser.TileSprite.html">TileSprite</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Geometry<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li class="class-depth-1"><a href="Phaser.Circle.html">Circle</a></li>
<li class="class-depth-1"><a href="Phaser.Ellipse.html">Ellipse</a></li>
<li class="class-depth-1"><a href="Phaser.Line.html">Line</a></li>
<li class="class-depth-1"><a href="Phaser.Matrix.html">Matrix</a></li>
<li class="class-depth-1"><a href="Phaser.Point.html">Point</a></li>
<li class="class-depth-1"><a href="Phaser.Polygon.html">Polygon</a></li>
<li class="class-depth-1"><a href="Phaser.Rectangle.html">Rectangle</a></li>
<li class="class-depth-1"><a href="Phaser.RoundedRectangle.html">Rounded Rectangle</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Physics<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li class="class-depth-1"><a href="Phaser.Physics.Arcade.html">Arcade Physics</a></li>
<li class="class-depth-2"><a href="Phaser.Physics.Arcade.Body.html">Body</a></li>
<li class="class-depth-2"><a href="Phaser.Weapon.html">Weapon</a></li>
<li class="class-depth-1"><a href="Phaser.Physics.P2.html">P2 Physics</a></li>
<li class="class-depth-2"><a href="Phaser.Physics.P2.Body.html">Body</a></li>
<li class="class-depth-2"><a href="Phaser.Physics.P2.Spring.html">Spring</a></li>
<li class="class-depth-2"><a href="Phaser.Physics.P2.CollisionGroup.html">CollisionGroup</a></li>
<li class="class-depth-2"><a href="Phaser.Physics.P2.ContactMaterial.html">ContactMaterial</a></li>
<li class="class-depth-1"><a href="Phaser.Physics.Ninja.html">Ninja Physics</a></li>
<li class="class-depth-2"><a href="Phaser.Physics.Body.html">Body</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Input<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li class="class-depth-1"><a href="Phaser.InputHandler.html">Input Handler</a></li>
<li class="class-depth-1"><a href="Phaser.Pointer.html">Pointer</a></li>
<li class="class-depth-1"><a href="Phaser.DeviceButton.html">Device Button</a></li>
<li class="class-depth-1"><a href="Phaser.Mouse.html">Mouse</a></li>
<li class="class-depth-1"><a href="Phaser.Keyboard.html">Keyboard</a></li>
<li class="class-depth-1"><a href="Phaser.Key.html">Key</a></li>
2016-08-26 00:18:47 +00:00
<li class="class-depth-1"><a href="Phaser.KeyCode.html">Key Codes</a></li>
2016-06-17 00:11:24 +00:00
<li class="class-depth-1"><a href="Phaser.Gamepad.html">Gamepad</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community<b class="caret"></b></a>
<ul class="dropdown-menu ">
<li class="class-depth-1"><a href="http://phaser.io">Phaser Web Site</a></li>
<li class="class-depth-1"><a href="https://github.com/photonstorm/phaser">Phaser Github</a></li>
<li class="class-depth-1"><a href="http://phaser.io/examples">Phaser Examples</a></li>
<li class="class-depth-1"><a href="https://github.com/photonstorm/phaser-plugins">Phaser Plugins</a></li>
<li class="class-depth-1"><a href="http://www.html5gamedevs.com/forum/14-phaser/">Forum</a></li>
<li class="class-depth-1"><a href="http://stackoverflow.com/questions/tagged/phaser-framework">Stack Overflow</a></li>
<li class="class-depth-1"><a href="http://phaser.io/learn">Tutorials</a></li>
<li class="class-depth-1"><a href="http://phaser.io/community/newsletter">Newsletter</a></li>
<li class="class-depth-1"><a href="http://phaser.io/community/twitter">Twitter</a></li>
<li class="class-depth-1"><a href="http://phaser.io/community/slack">Slack</a></li>
<li class="class-depth-1"><a href="http://phaser.io/community/donate">Donate</a></li>
<li class="class-depth-1"><a href="https://www.codeandweb.com/texturepacker/phaser">Texture Packer</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<div id="main">
<h1 class="page-title">Source: src/plugins/weapon/WeaponPlugin.js</h1>
<section>
<article>
<pre class="sunlight-highlight-javascript linenums">/**
* @author Richard Davey &lt;rich@photonstorm.com>
* @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Weapon Plugin provides the ability to easily create a bullet pool and manager.
*
* Weapons fire Phaser.Bullet objects, which are essentially Sprites with a few extra properties.
* The Bullets are enabled for Arcade Physics. They do not currently work with P2 Physics.
*
* The Bullets are created inside of `Weapon.bullets`, which is a Phaser.Group instance. Anything you
* can usually do with a Group, such as move it around the display list, iterate it, etc can be done
* to the bullets Group too.
*
* Bullets can have textures and even animations. You can control the speed at which they are fired,
* the firing rate, the firing angle, and even set things like gravity for them.
*
* A small example, assumed to be running from within a Phaser.State create method.
*
* `var weapon = this.add.weapon(10, 'bullet');`
* `weapon.fireFrom.set(300, 300);`
* `this.input.onDown.add(weapon.fire, this);`
*
* @class Phaser.Weapon
* @constructor
* @param {Phaser.Game} game - A reference to the current Phaser.Game instance.
* @param {Phaser.PluginManager} parent - The Phaser Plugin Manager which looks after this plugin.
*/
Phaser.Weapon = function (game, parent) {
Phaser.Plugin.call(this, game, parent);
/**
* This is the Phaser.Group that contains all of the bullets managed by this plugin.
* @type {Phaser.Group}
*/
this.bullets = null;
/**
* Should the bullet pool run out of bullets (i.e. they are all in flight) then this
* boolean controls if the Group will create a brand new bullet object or not.
* @type {boolean}
*/
this.autoExpandBulletsGroup = false;
/**
* Will this weapon auto fire? If set to true then a new bullet will be fired
* based on the `fireRate` value.
* @type {boolean}
*/
this.autofire = false;
/**
* The total number of bullets this Weapon has fired so far.
* You can limit the number of shots allowed (via `fireLimit`), and reset
* this total via `Weapon.resetShots`.
* @type {number}
*/
this.shots = 0;
/**
* The maximum number of shots that this Weapon is allowed to fire before it stops.
* When the limit is his the `Weapon.onFireLimit` Signal is dispatched.
* You can reset the shot counter via `Weapon.resetShots`.
* @type {number}
*/
this.fireLimit = 0;
/**
* The rate at which this Weapon can fire. The value is given in milliseconds.
* @type {number}
*/
this.fireRate = 100;
/**
* This is a modifier that is added to the `fireRate` each update to add variety
* to the firing rate of the Weapon. The value is given in milliseconds.
* If you've a `fireRate` of 200 and a `fireRateVariance` of 50 then the actual
* firing rate of the Weapon will be between 150 and 250.
* @type {number}
*/
this.fireRateVariance = 0;
/**
* This is a Rectangle from within which the bullets are fired. By default it's a 1x1
* rectangle, the equivalent of a Point. But you can change the width and height, and if
* larger than 1x1 it'll pick a random point within the rectangle to launch the bullet from.
* @type {Phaser.Rectangle}
*/
this.fireFrom = new Phaser.Rectangle(0, 0, 1, 1);
/**
2016-07-01 15:57:13 +00:00
* The angle at which the bullets are fired. This can be a const such as Phaser.ANGLE_UP
2016-06-17 00:11:24 +00:00
* or it can be any number from 0 to 360 inclusive, where 0 degrees is to the right.
* @type {integer}
*/
this.fireAngle = Phaser.ANGLE_UP;
/**
* When a Bullet is fired it can optionally inherit the velocity of the `trackedSprite` if set.
* @type {boolean}
*/
this.bulletInheritSpriteSpeed = false;
/**
* The string based name of the animation that the Bullet will be given on launch.
* This is set via `Weapon.addBulletAnimation`.
* @type {string}
*/
this.bulletAnimation = '';
/**
* If you've added a set of frames via `Weapon.setBulletFrames` then you can optionally
* chose for each Bullet fired to pick a random frame from the set.
* @type {boolean}
*/
this.bulletFrameRandom = false;
/**
* If you've added a set of frames via `Weapon.setBulletFrames` then you can optionally
* chose for each Bullet fired to use the next frame in the set. The frame index is then
* advanced one frame until it reaches the end of the set, then it starts from the start
* again. Cycling frames like this allows you to create varied bullet effects via
* sprite sheets.
* @type {boolean}
*/
this.bulletFrameCycle = false;
/**
* Should the Bullets wrap around the world bounds? This automatically calls
* `World.wrap` on the Bullet each frame. See the docs for that method for details.
* @type {boolean}
*/
this.bulletWorldWrap = false;
/**
* If `bulletWorldWrap` is true then you can provide an optional padding value with this
* property. It's added to the calculations determining when the Bullet should wrap around
* the world or not. The value is given in pixels.
* @type {integer}
*/
this.bulletWorldWrapPadding = 0;
/**
* An optional angle offset applied to the Bullets when they are launched.
* This is useful if for example your bullet sprites have been drawn facing up, instead of
* to the right, and you want to fire them at an angle. In which case you can set the
* angle offset to be 90 and they'll be properly rotated when fired.
* @type {number}
*/
this.bulletAngleOffset = 0;
/**
* This is a variance added to the angle of Bullets when they are fired.
* If you fire from an angle of 90 and have a `bulletAngleVariance` of 20 then the actual
* angle of the Bullets will be between 70 and 110 degrees. This is a quick way to add a
* great 'spread' effect to a Weapon.
* @type {number}
*/
this.bulletAngleVariance = 0;
/**
* The speed at which the bullets are fired. This value is given in pixels per second, and
* is used to set the starting velocity of the bullets.
* @type {number}
*/
this.bulletSpeed = 200;
/**
* This is a variance added to the speed of Bullets when they are fired.
2016-07-01 15:57:13 +00:00
* If bullets have a `bulletSpeed` value of 200, and a `bulletSpeedVariance` of 50
2016-06-17 00:11:24 +00:00
* then the actual speed of the Bullets will be between 150 and 250 pixels per second.
* @type {number}
*/
this.bulletSpeedVariance = 0;
/**
2016-07-01 15:57:13 +00:00
* If you've set `bulletKillType` to `Phaser.Weapon.KILL_LIFESPAN` this controls the amount
2016-06-17 00:11:24 +00:00
* of lifespan the Bullets have set on launch. The value is given in milliseconds.
* When a Bullet hits its lifespan limit it will be automatically killed.
* @type {number}
*/
this.bulletLifespan = 0;
/**
2016-07-01 15:57:13 +00:00
* If you've set `bulletKillType` to `Phaser.Weapon.KILL_DISTANCE` this controls the distance
2016-06-17 00:11:24 +00:00
* the Bullet can travel before it is automatically killed. The distance is given in pixels.
* @type {number}
*/
this.bulletKillDistance = 0;
/**
* This is the amount of gravity added to the Bullets physics body when fired.
* Gravity is expressed in pixels / second / second.
* @type {Phaser.Point}
*/
this.bulletGravity = new Phaser.Point(0, 0);
/**
* Bullets can optionally adjust their rotation in-flight to match their velocity.
* This can create the effect of a bullet 'pointing' to the path it is following, for example
* an arrow being fired from a bow, and works especially well when added to `bulletGravity`.
* @type {boolean}
*/
this.bulletRotateToVelocity = false;
/**
* The Texture Key that the Bullets use when rendering.
* Changing this has no effect on bullets in-flight, only on newly spawned bullets.
* @type {string}
*/
this.bulletKey = '';
/**
* The Texture Frame that the Bullets use when rendering.
* Changing this has no effect on bullets in-flight, only on newly spawned bullets.
* @type {string|integer}
*/
this.bulletFrame = '';
/**
* Private var that holds the public `bulletClass` property.
* @type {object}
* @private
*/
this._bulletClass = Phaser.Bullet;
/**
* Private var that holds the public `bulletCollideWorldBounds` property.
* @type {boolean}
* @private
*/
this._bulletCollideWorldBounds = false;
/**
* Private var that holds the public `bulletKillType` property.
* @type {integer}
* @private
*/
this._bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS;
/**
* Holds internal data about custom bullet body sizes.
*
* @type {Object}
* @private
*/
this._data = {
customBody: false,
width: 0,
height: 0,
offsetX: 0,
offsetY: 0
};
/**
* This Rectangle defines the bounds that are used when determining if a Bullet should be killed or not.
* It's used in combination with `Weapon.bulletKillType` when that is set to either `Phaser.Weapon.KILL_WEAPON_BOUNDS`
* or `Phaser.Weapon.KILL_STATIC_BOUNDS`. If you are not using either of these kill types then the bounds are ignored.
2016-07-01 15:57:13 +00:00
* If you are tracking a Sprite or Point then the bounds are centered on that object every frame.
2016-06-17 00:11:24 +00:00
*
* @type {Phaser.Rectangle}
*/
this.bounds = new Phaser.Rectangle();
/**
* The Rectangle used to calculate the bullet bounds from.
*
* @type {Phaser.Rectangle}
* @private
*/
this.bulletBounds = game.world.bounds;
/**
* This array stores the frames added via `Weapon.setBulletFrames`.
*
* @type {Array}
* @protected
*/
this.bulletFrames = [];
/**
* The index of the frame within `Weapon.bulletFrames` that is currently being used.
* This value is only used if `Weapon.bulletFrameCycle` is set to `true`.
* @type {number}
* @private
*/
this.bulletFrameIndex = 0;
/**
* An internal object that stores the animation data added via `Weapon.addBulletAnimation`.
* @type {Object}
* @private
*/
this.anims = {};
/**
* The onFire Signal is dispatched each time `Weapon.fire` is called, and a Bullet is
2016-07-01 15:57:13 +00:00
* _successfully_ launched. The callback is set two arguments: a reference to the bullet sprite itself,
* and a reference to the Weapon that fired the bullet.
2016-06-17 00:11:24 +00:00
*
* @type {Phaser.Signal}
*/
this.onFire = new Phaser.Signal();
/**
* The onKill Signal is dispatched each time a Bullet that is in-flight is killed. This can be the result
* of leaving the Weapon bounds, an expiring lifespan, or exceeding a specified distance.
* The callback is sent one argument: A reference to the bullet sprite itself.
*
* @type {Phaser.Signal}
*/
this.onKill = new Phaser.Signal();
/**
* The onFireLimit Signal is dispatched if `Weapon.fireLimit` is > 0, and a bullet launch takes the number
* of shots fired to equal the fire limit.
* The callback is sent two arguments: A reference to the Weapon that hit the limit, and the value of
* `Weapon.fireLimit`.
*
* @type {Phaser.Signal}
*/
this.onFireLimit = new Phaser.Signal();
/**
* The Sprite currently being tracked by the Weapon, if any.
* This is set via the `Weapon.trackSprite` method.
*
* @type {Phaser.Sprite|Object}
*/
this.trackedSprite = null;
/**
* The Pointer currently being tracked by the Weapon, if any.
* This is set via the `Weapon.trackPointer` method.
*
* @type {Phaser.Pointer}
*/
this.trackedPointer = null;
2016-11-23 00:59:32 +00:00
/**
* If you want this Weapon to be able to fire more than 1 bullet in a single
* update, then set this property to `true`. When `true` the Weapon plugin won't
* set the shot / firing timers until the `postRender` phase of the game loop.
* This means you can call `fire` (and similar methods) as often as you like in one
* single game update.
*
* @type {boolean}
*/
this.multiFire = false;
/**
* Internal multiFire test flag.
*
* @type {boolean}
*/
this._hasFired = false;
2016-06-17 00:11:24 +00:00
/**
* If the Weapon is tracking a Sprite, should it also track the Sprites rotation?
* This is useful for a game such as Asteroids, where you want the weapon to fire based
* on the sprites rotation.
*
* @type {boolean}
*/
this.trackRotation = false;
/**
* The Track Offset is a Point object that allows you to specify a pixel offset that bullets use
* when launching from a tracked Sprite or Pointer. For example if you've got a bullet that is 2x2 pixels
* in size, but you're tracking a Sprite that is 32x32, then you can set `trackOffset.x = 16` to have
* the bullet launched from the center of the Sprite.
*
* @type {Phaser.Point}
*/
this.trackOffset = new Phaser.Point();
/**
* Internal firing rate time tracking variable.
*
* @type {number}
* @private
*/
this._nextFire = 0;
2016-11-23 00:59:32 +00:00
/**
* Internal firing rate time tracking variable used by multiFire.
*
* @type {number}
* @private
*/
this._tempNextFire = 0;
2016-08-26 00:18:47 +00:00
/**
* Internal firing rotation tracking point.
*
* @type {Phaser.Point}
* @private
*/
this._rotatedPoint = new Phaser.Point();
2016-06-17 00:11:24 +00:00
};
Phaser.Weapon.prototype = Object.create(Phaser.Plugin.prototype);
Phaser.Weapon.prototype.constructor = Phaser.Weapon;
/**
* A `bulletKillType` constant that stops the bullets from ever being destroyed automatically.
* @constant
* @type {integer}
*/
Phaser.Weapon.KILL_NEVER = 0;
/**
* A `bulletKillType` constant that automatically kills the bullets when their `bulletLifespan` expires.
* @constant
* @type {integer}
*/
Phaser.Weapon.KILL_LIFESPAN = 1;
/**
2016-07-01 15:57:13 +00:00
* A `bulletKillType` constant that automatically kills the bullets after they
2016-06-17 00:11:24 +00:00
* exceed the `bulletDistance` from their original firing position.
* @constant
* @type {integer}
*/
Phaser.Weapon.KILL_DISTANCE = 2;
/**
* A `bulletKillType` constant that automatically kills the bullets when they leave the `Weapon.bounds` rectangle.
* @constant
* @type {integer}
*/
Phaser.Weapon.KILL_WEAPON_BOUNDS = 3;
/**
* A `bulletKillType` constant that automatically kills the bullets when they leave the `Camera.bounds` rectangle.
* @constant
* @type {integer}
*/
Phaser.Weapon.KILL_CAMERA_BOUNDS = 4;
/**
* A `bulletKillType` constant that automatically kills the bullets when they leave the `World.bounds` rectangle.
* @constant
* @type {integer}
*/
Phaser.Weapon.KILL_WORLD_BOUNDS = 5;
/**
* A `bulletKillType` constant that automatically kills the bullets when they leave the `Weapon.bounds` rectangle.
* @constant
* @type {integer}
*/
Phaser.Weapon.KILL_STATIC_BOUNDS = 6;
/**
* This method performs two actions: First it will check to see if the `Weapon.bullets` Group exists or not,
* and if not it creates it, adding it the `group` given as the 4th argument.
*
* Then it will seed the bullet pool with the `quantity` number of Bullets, using the texture key and frame
* provided (if any).
*
* If for example you set the quantity to be 10, then this Weapon will only ever be able to have 10 bullets
* in-flight simultaneously. If you try to fire an 11th bullet then nothing will happen until one, or more, of
* the in-flight bullets have been killed, freeing them up for use by the Weapon again.
*
* If you do not wish to have a limit set, then pass in -1 as the quantity. In this instance the Weapon will
* keep increasing the size of the bullet pool as needed. It will never reduce the size of the pool however,
* so be careful it doesn't grow too large.
*
* You can either set the texture key and frame here, or via the `Weapon.bulletKey` and `Weapon.bulletFrame`
2016-07-01 15:57:13 +00:00
* properties. You can also animate bullets, or set them to use random frames. All Bullets belonging to a
2016-06-17 00:11:24 +00:00
* single Weapon instance must share the same texture key however.
*
* @method Phaser.Weapon#createBullets
* @param {integer} [quantity=1] - The quantity of bullets to seed the Weapon with. If -1 it will set the pool to automatically expand.
* @param {string} [key] - The Game.cache key of the image that this Sprite will use.
* @param {integer|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here.
* @param {Phaser.Group} [group] - Optional Group to add the object to. If not specified it will be added to the World group.
* @return {Phaser.Weapon} This Weapon instance.
*/
Phaser.Weapon.prototype.createBullets = function (quantity, key, frame, group) {
if (quantity === undefined) { quantity = 1; }
if (group === undefined) { group = this.game.world; }
if (!this.bullets)
{
this.bullets = this.game.add.physicsGroup(Phaser.Physics.ARCADE, group);
this.bullets.classType = this._bulletClass;
}
if (quantity !== 0)
{
if (quantity === -1)
{
this.autoExpandBulletsGroup = true;
quantity = 1;
}
2016-07-01 15:57:13 +00:00
2016-06-17 00:11:24 +00:00
this.bullets.createMultiple(quantity, key, frame);
this.bullets.setAll('data.bulletManager', this);
this.bulletKey = key;
this.bulletFrame = frame;
}
return this;
};
/**
* Call a function on each in-flight bullet in this Weapon.
*
* See {@link Phaser.Group#forEachExists forEachExists} for more details.
*
* @method Phaser.Weapon#forEach
* @param {function} callback - The function that will be called for each applicable child. The child will be passed as the first argument.
* @param {object} callbackContext - The context in which the function should be called (usually 'this').
* @param {...any} [args=(none)] - Additional arguments to pass to the callback function, after the child item.
* @return {Phaser.Weapon} This Weapon instance.
*/
Phaser.Weapon.prototype.forEach = function (callback, callbackContext) {
this.bullets.forEachExists(callback, callbackContext, arguments);
return this;
};
/**
* Sets `Body.enable` to `false` on each bullet in this Weapon.
* This has the effect of stopping them in-flight should they be moving.
* It also stops them being able to be checked for collision.
*
* @method Phaser.Weapon#pauseAll
* @return {Phaser.Weapon} This Weapon instance.
*/
Phaser.Weapon.prototype.pauseAll = function () {
this.bullets.setAll('body.enable', false);
return this;
};
/**
* Sets `Body.enable` to `true` on each bullet in this Weapon.
* This has the effect of resuming their motion should they be in-flight.
* It also enables them for collision checks again.
*
* @method Phaser.Weapon#resumeAll
* @return {Phaser.Weapon} This Weapon instance.
*/
Phaser.Weapon.prototype.resumeAll = function () {
this.bullets.setAll('body.enable', true);
return this;
};
/**
* Calls `Bullet.kill` on every in-flight bullet in this Weapon.
* Also re-enables their physics bodies, should they have been disabled via `pauseAll`.
*
* @method Phaser.Weapon#killAll
* @return {Phaser.Weapon} This Weapon instance.
*/
Phaser.Weapon.prototype.killAll = function () {
this.bullets.callAllExists('kill', true);
this.bullets.setAll('body.enable', true);
return this;
};
/**
* Resets the `Weapon.shots` counter back to zero. This is used when you've set
* `Weapon.fireLimit`, and have hit (or just wish to reset) your limit.
*
* @method Phaser.Weapon#resetShots
* @param {integer} [newLimit] - Optionally set a new `Weapon.fireLimit`.
* @return {Phaser.Weapon} This Weapon instance.
*/
Phaser.Weapon.prototype.resetShots = function (newLimit) {
this.shots = 0;
if (newLimit !== undefined)
{
this.fireLimit = newLimit;
}
return this;
};
/**
* Destroys this Weapon. It removes itself from the PluginManager, destroys
* the bullets Group, and nulls internal references.
*
* @method Phaser.Weapon#destroy
*/
Phaser.Weapon.prototype.destroy = function () {
this.parent.remove(this, false);
this.bullets.destroy();
this.game = null;
this.parent = null;
this.active = false;
this.visible = false;
};
/**
* Internal update method, called by the PluginManager.
*
* @method Phaser.Weapon#update
* @protected
*/
Phaser.Weapon.prototype.update = function () {
if (this._bulletKillType === Phaser.Weapon.KILL_WEAPON_BOUNDS)
{
if (this.trackedSprite)
{
this.trackedSprite.updateTransform();
this.bounds.centerOn(this.trackedSprite.worldPosition.x, this.trackedSprite.worldPosition.y);
}
else if (this.trackedPointer)
{
this.bounds.centerOn(this.trackedPointer.worldX, this.trackedPointer.worldY);
}
}
2016-08-26 00:18:47 +00:00
if (this.autofire)
2016-06-17 00:11:24 +00:00
{
this.fire();
}
};
2016-11-23 00:59:32 +00:00
/**
* Internal update method, called by the PluginManager.
*
* @method Phaser.Weapon#postRender
* @protected
*/
Phaser.Weapon.prototype.postRender = function () {
if (!this.multiFire || !this._hasFired)
{
return;
}
this._hasFired = false;
this._nextFire = this._tempNextFire;
};
2016-06-17 00:11:24 +00:00
/**
* Sets this Weapon to track the given Sprite, or any Object with a public `world` Point object.
* When a Weapon tracks a Sprite it will automatically update its `fireFrom` value to match the Sprites
* position within the Game World, adjusting the coordinates based on the offset arguments.
*
* This allows you to lock a Weapon to a Sprite, so that bullets are always launched from its location.
*
* Calling `trackSprite` will reset `Weapon.trackedPointer` to null, should it have been set, as you can
* only track _either_ a Sprite, or a Pointer, at once, but not both.
*
* @method Phaser.Weapon#trackSprite
* @param {Phaser.Sprite|Object} sprite - The Sprite to track the position of.
* @param {integer} [offsetX=0] - The horizontal offset from the Sprites position to be applied to the Weapon.
* @param {integer} [offsetY=0] - The vertical offset from the Sprites position to be applied to the Weapon.
* @param {boolean} [trackRotation=false] - Should the Weapon also track the Sprites rotation?
* @return {Phaser.Weapon} This Weapon instance.
*/
Phaser.Weapon.prototype.trackSprite = function (sprite, offsetX, offsetY, trackRotation) {
if (offsetX === undefined) { offsetX = 0; }
if (offsetY === undefined) { offsetY = 0; }
if (trackRotation === undefined) { trackRotation = false; }
this.trackedPointer = null;
this.trackedSprite = sprite;
this.trackRotation = trackRotation;
this.trackOffset.set(offsetX, offsetY);
return this;
};
/**
* Sets this Weapon to track the given Pointer.
* When a Weapon tracks a Pointer it will automatically update its `fireFrom` value to match the Pointers
* position within the Game World, adjusting the coordinates based on the offset arguments.
*
* This allows you to lock a Weapon to a Pointer, so that bullets are always launched from its location.
*
* Calling `trackPointer` will reset `Weapon.trackedSprite` to null, should it have been set, as you can
* only track _either_ a Pointer, or a Sprite, at once, but not both.
*
* @method Phaser.Weapon#trackPointer
* @param {Phaser.Pointer} [pointer] - The Pointer to track the position of. Defaults to `Input.activePointer` if not specified.
* @param {integer} [offsetX=0] - The horizontal offset from the Pointers position to be applied to the Weapon.
* @param {integer} [offsetY=0] - The vertical offset from the Pointers position to be applied to the Weapon.
* @return {Phaser.Weapon} This Weapon instance.
*/
Phaser.Weapon.prototype.trackPointer = function (pointer, offsetX, offsetY) {
if (pointer === undefined) { pointer = this.game.input.activePointer; }
if (offsetX === undefined) { offsetX = 0; }
if (offsetY === undefined) { offsetY = 0; }
this.trackedPointer = pointer;
this.trackedSprite = null;
this.trackRotation = false;
this.trackOffset.set(offsetX, offsetY);
return this;
};
2016-11-23 00:59:32 +00:00
/**
* Attempts to fire multiple bullets from the positions defined in the given array.
*
* If you provide a `from` argument, or if there is a tracked Sprite or Pointer, then
* the positions are treated as __offsets__ from the given objects position.
*
* If `from` is undefined, and there is no tracked object, then the bullets are fired
* from the given positions, as they exist in the world.
*
* Calling this method sets `Weapon.multiFire = true`.
*
* If there are not enough bullets available in the pool, and the pool cannot be extended,
* then this method may not fire from all of the given positions.
*
* When the bullets are launched they have their texture and frame updated, as required.
* The velocity of the bullets are calculated based on Weapon properties like `bulletSpeed`.
*
* @method Phaser.Weapon#fireMany
* @param {array} positions - An array of positions. Each position can be any Object, as long as it has public `x` and `y` properties, such as Phaser.Point, { x: 0, y: 0 }, Phaser.Sprite, etc.
* @param {Phaser.Sprite|Phaser.Point|Object|string} [from] - Optionally fires the bullets **from** the `x` and `y` properties of this object, _instead_ of any `Weapon.trackedSprite` or `trackedPointer` that is set.
* @return {array} An array containing all of the fired Phaser.Bullet objects, if a launch was successful, otherwise an empty array.
*/
Phaser.Weapon.prototype.fireMany = function (positions, from) {
this.multiFire = true;
var bullets = [];
var _this = this;
if (from || this.trackedSprite || this.trackedPointer)
{
positions.forEach(function(offset) {
bullets.push(_this.fire(from, null, null, offset.x, offset.y));
});
}
else
{
positions.forEach(function(position) {
bullets.push(_this.fire(position));
});
}
return bullets;
};
/**
* Attempts to fire a single Bullet from a tracked Sprite or Pointer, but applies an offset
* to the position first. This is the same as calling `Weapon.fire` and passing in the offset arguments.
*
* If there are no more bullets available in the pool, and the pool cannot be extended,
* then this method returns `null`. It will also return `null` if not enough time has expired since the last time
* the Weapon was fired, as defined in the `Weapon.fireRate` property.
*
* Otherwise the first available bullet is selected, launched, and returned.
*
* When the bullet is launched it has its texture and frame updated, as required. The velocity of the bullet is
* calculated based on Weapon properties like `bulletSpeed`.
*
* If you wish to fire multiple bullets in a single game update, then set `Weapon.multiFire = true`
* and you can call this method as many times as you like, per loop. See also `Weapon.fireMany`.
*
* @method Phaser.Weapon#fireOffset
* @param {number} [offsetX=0] - The horizontal offset from the position of the tracked Sprite or Pointer, as set with `Weapon.trackSprite`.
* @param {number} [offsetY=0] - The vertical offset from the position of the tracked Sprite or Pointer, as set with `Weapon.trackSprite`.
* @return {Phaser.Bullet} The fired bullet, if a launch was successful, otherwise `null`.
*/
Phaser.Weapon.prototype.fireOffset = function (offsetX, offsetY) {
if (offsetX === undefined) { offsetX = 0; }
if (offsetY === undefined) { offsetY = 0; }
return this.fire(null, null, null, offsetX, offsetY);
};
2016-06-17 00:11:24 +00:00
/**
* Attempts to fire a single Bullet. If there are no more bullets available in the pool, and the pool cannot be extended,
2016-11-23 00:59:32 +00:00
* then this method returns `null`. It will also return `null` if not enough time has expired since the last time
2016-06-17 00:11:24 +00:00
* the Weapon was fired, as defined in the `Weapon.fireRate` property.
2016-07-01 15:57:13 +00:00
*
2016-11-23 00:59:32 +00:00
* Otherwise the first available bullet is selected, launched, and returned.
2016-06-17 00:11:24 +00:00
*
* The arguments are all optional, but allow you to control both where the bullet is launched from, and aimed at.
*
* If you don't provide any of the arguments then it uses those set via properties such as `Weapon.trackedSprite`,
* `Weapon.bulletAngle` and so on.
*
* When the bullet is launched it has its texture and frame updated, as required. The velocity of the bullet is
* calculated based on Weapon properties like `bulletSpeed`.
*
2016-11-23 00:59:32 +00:00
* If you wish to fire multiple bullets in a single game update, then set `Weapon.multiFire = true`
* and you can call `fire` as many times as you like, per loop. Multiple fires in a single update
* only counts once towards the `shots` total, but you will still receive a Signal for each bullet.
*
2016-06-17 00:11:24 +00:00
* @method Phaser.Weapon#fire
2016-11-23 00:59:32 +00:00
* @param {Phaser.Sprite|Phaser.Point|Object|string} [from] - Optionally fires the bullet **from** the `x` and `y` properties of this object. If set this overrides `Weapon.trackedSprite` or `trackedPointer`. Pass `null` to ignore it.
* @param {number} [x] - The x coordinate, in world space, to fire the bullet **towards**. If left as `undefined`, or `null`, the bullet direction is based on its angle.
* @param {number} [y] - The y coordinate, in world space, to fire the bullet **towards**. If left as `undefined`, or `null`, the bullet direction is based on its angle.
* @param {number} [offsetX=0] - If the bullet is fired from a tracked Sprite or Pointer, or the `from` argument is set, this applies a horizontal offset from the launch position.
* @param {number} [offsetY=0] - If the bullet is fired from a tracked Sprite or Pointer, or the `from` argument is set, this applies a vertical offset from the launch position.
* @return {Phaser.Bullet} The fired bullet, if a launch was successful, otherwise `null`.
2016-06-17 00:11:24 +00:00
*/
2016-11-23 00:59:32 +00:00
Phaser.Weapon.prototype.fire = function (from, x, y, offsetX, offsetY) {
if (x === undefined) { x = null; }
if (y === undefined) { y = null; }
2016-06-17 00:11:24 +00:00
if (this.game.time.now &lt; this._nextFire || (this.fireLimit > 0 &amp;&amp; this.shots === this.fireLimit))
{
2016-11-23 00:59:32 +00:00
return null;
2016-06-17 00:11:24 +00:00
}
var speed = this.bulletSpeed;
// Apply +- speed variance
if (this.bulletSpeedVariance !== 0)
{
speed += Phaser.Math.between(-this.bulletSpeedVariance, this.bulletSpeedVariance);
}
if (from)
{
if (this.fireFrom.width > 1)
{
this.fireFrom.centerOn(from.x, from.y);
}
else
{
this.fireFrom.x = from.x;
this.fireFrom.y = from.y;
}
}
else if (this.trackedSprite)
{
2016-08-26 00:18:47 +00:00
if (this.trackRotation)
2016-06-17 00:11:24 +00:00
{
2016-08-26 00:18:47 +00:00
this._rotatedPoint.set(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y);
this._rotatedPoint.rotate(this.trackedSprite.world.x, this.trackedSprite.world.y, this.trackedSprite.rotation);
if (this.fireFrom.width > 1)
{
this.fireFrom.centerOn(this._rotatedPoint.x, this._rotatedPoint.y);
}
else
{
this.fireFrom.x = this._rotatedPoint.x;
this.fireFrom.y = this._rotatedPoint.y;
}
2016-06-17 00:11:24 +00:00
}
else
{
2016-08-26 00:18:47 +00:00
if (this.fireFrom.width > 1)
{
this.fireFrom.centerOn(this.trackedSprite.world.x + this.trackOffset.x, this.trackedSprite.world.y + this.trackOffset.y);
}
else
{
this.fireFrom.x = this.trackedSprite.world.x + this.trackOffset.x;
this.fireFrom.y = this.trackedSprite.world.y + this.trackOffset.y;
}
2016-06-17 00:11:24 +00:00
}
if (this.bulletInheritSpriteSpeed)
{
speed += this.trackedSprite.body.speed;
}
}
else if (this.trackedPointer)
{
if (this.fireFrom.width > 1)
{
this.fireFrom.centerOn(this.trackedPointer.world.x + this.trackOffset.x, this.trackedPointer.world.y + this.trackOffset.y);
}
else
{
this.fireFrom.x = this.trackedPointer.world.x + this.trackOffset.x;
this.fireFrom.y = this.trackedPointer.world.y + this.trackOffset.y;
}
}
2016-11-23 00:59:32 +00:00
if (offsetX !== undefined)
{
this.fireFrom.x += offsetX;
}
if (offsetY !== undefined)
{
this.fireFrom.y += offsetY;
}
2016-06-17 00:11:24 +00:00
var fromX = (this.fireFrom.width > 1) ? this.fireFrom.randomX : this.fireFrom.x;
var fromY = (this.fireFrom.height > 1) ? this.fireFrom.randomY : this.fireFrom.y;
var angle = (this.trackRotation) ? this.trackedSprite.angle : this.fireAngle;
// The position (in world space) to fire the bullet towards, if set
2016-11-23 00:59:32 +00:00
if (x !== null &amp;&amp; y !== null)
2016-06-17 00:11:24 +00:00
{
angle = this.game.math.radToDeg(Math.atan2(y - fromY, x - fromX));
}
// Apply +- angle variance
if (this.bulletAngleVariance !== 0)
{
angle += Phaser.Math.between(-this.bulletAngleVariance, this.bulletAngleVariance);
}
var moveX = 0;
var moveY = 0;
// Avoid sin/cos for right-angled shots
if (angle === 0 || angle === 180)
{
moveX = Math.cos(this.game.math.degToRad(angle)) * speed;
}
else if (angle === 90 || angle === 270)
{
moveY = Math.sin(this.game.math.degToRad(angle)) * speed;
}
else
{
moveX = Math.cos(this.game.math.degToRad(angle)) * speed;
moveY = Math.sin(this.game.math.degToRad(angle)) * speed;
}
var bullet = null;
if (this.autoExpandBulletsGroup)
{
bullet = this.bullets.getFirstExists(false, true, fromX, fromY, this.bulletKey, this.bulletFrame);
bullet.data.bulletManager = this;
}
else
{
bullet = this.bullets.getFirstExists(false);
}
if (bullet)
{
bullet.reset(fromX, fromY);
bullet.data.fromX = fromX;
bullet.data.fromY = fromY;
bullet.data.killType = this.bulletKillType;
bullet.data.killDistance = this.bulletKillDistance;
bullet.data.rotateToVelocity = this.bulletRotateToVelocity;
if (this.bulletKillType === Phaser.Weapon.KILL_LIFESPAN)
{
bullet.lifespan = this.bulletLifespan;
}
bullet.angle = angle + this.bulletAngleOffset;
// Frames and Animations
if (this.bulletAnimation !== '')
{
if (bullet.animations.getAnimation(this.bulletAnimation) === null)
{
var anim = this.anims[this.bulletAnimation];
bullet.animations.add(anim.name, anim.frames, anim.frameRate, anim.loop, anim.useNumericIndex);
}
bullet.animations.play(this.bulletAnimation);
}
else
{
if (this.bulletFrameCycle)
{
bullet.frame = this.bulletFrames[this.bulletFrameIndex];
this.bulletFrameIndex++;
if (this.bulletFrameIndex >= this.bulletFrames.length)
{
this.bulletFrameIndex = 0;
}
}
else if (this.bulletFrameRandom)
{
bullet.frame = this.bulletFrames[Math.floor(Math.random() * this.bulletFrames.length)];
}
}
if (bullet.data.bodyDirty)
{
if (this._data.customBody)
{
bullet.body.setSize(this._data.width, this._data.height, this._data.offsetX, this._data.offsetY);
}
bullet.body.collideWorldBounds = this.bulletCollideWorldBounds;
bullet.data.bodyDirty = false;
}
bullet.body.velocity.set(moveX, moveY);
bullet.body.gravity.set(this.bulletGravity.x, this.bulletGravity.y);
2016-11-23 00:59:32 +00:00
var next = 0;
2016-08-26 00:18:47 +00:00
if (this.bulletSpeedVariance !== 0)
{
var rate = this.fireRate;
rate += Phaser.Math.between(-this.fireRateVariance, this.fireRateVariance);
if (rate &lt; 0)
{
rate = 0;
}
2016-11-23 00:59:32 +00:00
next = this.game.time.now + rate;
2016-08-26 00:18:47 +00:00
}
else
{
2016-11-23 00:59:32 +00:00
next = this.game.time.now + this.fireRate;
}
if (this.multiFire)
{
if (!this._hasFired)
{
// We only add 1 to the 'shots' count for multiFire shots
this._hasFired = true;
this._tempNextFire = next;
this.shots++;
}
2016-08-26 00:18:47 +00:00
}
2016-11-23 00:59:32 +00:00
else
{
this._nextFire = next;
2016-06-17 00:11:24 +00:00
2016-11-23 00:59:32 +00:00
this.shots++;
}
2016-06-17 00:11:24 +00:00
this.onFire.dispatch(bullet, this, speed);
if (this.fireLimit > 0 &amp;&amp; this.shots === this.fireLimit)
{
this.onFireLimit.dispatch(this, this.fireLimit);
}
}
2016-11-23 00:59:32 +00:00
2016-08-26 00:18:47 +00:00
return bullet;
2016-11-23 00:59:32 +00:00
2016-06-17 00:11:24 +00:00
};
/**
* Fires a bullet **at** the given Pointer. The bullet will be launched from the `Weapon.fireFrom` position,
* or from a Tracked Sprite or Pointer, if you have one set.
*
* @method Phaser.Weapon#fireAtPointer
* @param {Phaser.Pointer} [pointer] - The Pointer to fire the bullet towards.
2016-08-26 00:18:47 +00:00
* @return {Phaser.Bullet} The fired bullet if successful, null otherwise.
2016-06-17 00:11:24 +00:00
*/
Phaser.Weapon.prototype.fireAtPointer = function (pointer) {
if (pointer === undefined) { pointer = this.game.input.activePointer; }
return this.fire(null, pointer.worldX, pointer.worldY);
};
/**
* Fires a bullet **at** the given Sprite. The bullet will be launched from the `Weapon.fireFrom` position,
* or from a Tracked Sprite or Pointer, if you have one set.
*
* @method Phaser.Weapon#fireAtSprite
* @param {Phaser.Sprite} [sprite] - The Sprite to fire the bullet towards.
2016-08-26 00:18:47 +00:00
* @return {Phaser.Bullet} The fired bullet if successful, null otherwise.
2016-06-17 00:11:24 +00:00
*/
Phaser.Weapon.prototype.fireAtSprite = function (sprite) {
return this.fire(null, sprite.world.x, sprite.world.y);
};
/**
* Fires a bullet **at** the given coordinates. The bullet will be launched from the `Weapon.fireFrom` position,
* or from a Tracked Sprite or Pointer, if you have one set.
*
* @method Phaser.Weapon#fireAtXY
* @param {number} [x] - The x coordinate, in world space, to fire the bullet towards.
* @param {number} [y] - The y coordinate, in world space, to fire the bullet towards.
2016-08-26 00:18:47 +00:00
* @return {Phaser.Bullet} The fired bullet if successful, null otherwise.
2016-06-17 00:11:24 +00:00
*/
Phaser.Weapon.prototype.fireAtXY = function (x, y) {
return this.fire(null, x, y);
};
/**
* You can modify the size of the physics Body the Bullets use to be any dimension you need.
* This allows you to make it smaller, or larger, than the parent Sprite.
* You can also control the x and y offset of the Body. This is the position of the
* Body relative to the top-left of the Sprite _texture_.
*
* For example: If you have a Sprite with a texture that is 80x100 in size,
* and you want the physics body to be 32x32 pixels in the middle of the texture, you would do:
*
2016-11-23 00:59:32 +00:00
* `setSize(32 / Math.abs(this.scale.x), 32 / Math.abs(this.scale.y), 24, 34)`
2016-06-17 00:11:24 +00:00
*
2016-11-23 00:59:32 +00:00
* Where the first two parameters are the new Body size (32x32 pixels) relative to the Sprite's scale.
2016-06-17 00:11:24 +00:00
* 24 is the horizontal offset of the Body from the top-left of the Sprites texture, and 34
* is the vertical offset.
*
* @method Phaser.Weapon#setBulletBodyOffset
* @param {number} width - The width of the Body.
* @param {number} height - The height of the Body.
* @param {number} [offsetX] - The X offset of the Body from the top-left of the Sprites texture.
* @param {number} [offsetY] - The Y offset of the Body from the top-left of the Sprites texture.
* @return {Phaser.Weapon} The Weapon Plugin.
*/
Phaser.Weapon.prototype.setBulletBodyOffset = function (width, height, offsetX, offsetY) {
if (offsetX === undefined) { offsetX = 0; }
if (offsetY === undefined) { offsetY = 0; }
this._data.customBody = true;
this._data.width = width;
this._data.height = height;
this._data.offsetX = offsetX;
this._data.offsetY = offsetY;
// Update all bullets in the pool
this.bullets.callAll('body.setSize', 'body', width, height, offsetX, offsetY);
this.bullets.setAll('data.bodyDirty', false);
return this;
};
/**
* Sets the texture frames that the bullets can use when being launched.
2016-07-01 15:57:13 +00:00
*
2016-06-17 00:11:24 +00:00
* This is intended for use when you've got numeric based frames, such as those loaded via a Sprite Sheet.
2016-07-01 15:57:13 +00:00
*
2016-06-17 00:11:24 +00:00
* It works by calling `Phaser.ArrayUtils.numberArray` internally, using the min and max values
* provided. Then it sets the frame index to be zero.
2016-07-01 15:57:13 +00:00
*
2016-06-17 00:11:24 +00:00
* You can optionally set the cycle and random booleans, to allow bullets to cycle through the frames
* when they're fired, or pick one at random.
*
* @method Phaser.Weapon#setBulletFrames
* @param {integer} min - The minimum value the frame can be. Usually zero.
* @param {integer} max - The maximum value the frame can be.
* @param {boolean} [cycle=true] - Should the bullet frames cycle as they are fired?
* @param {boolean} [random=false] - Should the bullet frames be picked at random as they are fired?
* @return {Phaser.Weapon} The Weapon Plugin.
*/
Phaser.Weapon.prototype.setBulletFrames = function (min, max, cycle, random) {
if (cycle === undefined) { cycle = true; }
if (random === undefined) { random = false; }
this.bulletFrames = Phaser.ArrayUtils.numberArray(min, max);
this.bulletFrameIndex = 0;
this.bulletFrameCycle = cycle;
this.bulletFrameRandom = random;
return this;
};
/**
* Adds a new animation under the given key. Optionally set the frames, frame rate and loop.
* The arguments are all the same as for `Animation.add`, and work in the same way.
*
* `Weapon.bulletAnimation` will be set to this animation after it's created. From that point on, all
* bullets fired will play using this animation. You can swap between animations by calling this method
* several times, and then just changing the `Weapon.bulletAnimation` property to the name of the animation
* you wish to play for the next launched bullet.
*
* If you wish to stop using animations at all, set `Weapon.bulletAnimation` to '' (an empty string).
*
* @method Phaser.Weapon#addBulletAnimation
* @param {string} name - The unique (within the Weapon instance) name for the animation, i.e. "fire", "blast".
* @param {Array} [frames=null] - An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used.
* @param {number} [frameRate=60] - The speed at which the animation should play. The speed is given in frames per second.
* @param {boolean} [loop=false] - Whether or not the animation is looped or just plays once.
* @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings?
* @return {Phaser.Weapon} The Weapon Plugin.
*/
Phaser.Weapon.prototype.addBulletAnimation = function (name, frames, frameRate, loop, useNumericIndex) {
this.anims[name] = {
name: name,
frames: frames,
frameRate: frameRate,
loop: loop,
useNumericIndex: useNumericIndex
};
// Add the animation to any existing bullets in the pool
this.bullets.callAll('animations.add', 'animations', name, frames, frameRate, loop, useNumericIndex);
this.bulletAnimation = name;
return this;
};
/**
* Uses `Game.Debug` to draw some useful information about this Weapon, including the number of bullets
* both in-flight, and available. And optionally the physics debug bodies of the bullets.
*
* @method Phaser.Weapon#debug
* @param {integer} [x=16] - The coordinate, in screen space, at which to draw the Weapon debug data.
* @param {integer} [y=32] - The coordinate, in screen space, at which to draw the Weapon debug data.
* @param {boolean} [debugBodies=false] - Optionally draw the physics body of every bullet in-flight.
*/
Phaser.Weapon.prototype.debug = function (x, y, debugBodies) {
if (x === undefined) { x = 16; }
if (y === undefined) { y = 32; }
if (debugBodies === undefined) { debugBodies = false; }
this.game.debug.text("Weapon Plugin", x, y);
this.game.debug.text("Bullets Alive: " + this.bullets.total + " - Total: " + this.bullets.length, x, y + 24);
if (debugBodies)
{
this.bullets.forEachExists(this.game.debug.body, this.game.debug, 'rgba(255, 0, 255, 0.8)');
}
};
/**
* The Class of the bullets that are launched by this Weapon. Defaults `Phaser.Bullet`, but can be
* overridden before calling `createBullets` and set to your own class type.
*
* @name Phaser.Weapon#bulletClass
* @property {Object} bulletClass
*/
Object.defineProperty(Phaser.Weapon.prototype, "bulletClass", {
get: function () {
return this._bulletClass;
},
set: function (classType) {
this._bulletClass = classType;
2016-11-23 00:59:32 +00:00
//prevent crash if weapon's bullets have not yet been initialized
if (this.bullets) {
this.bullets.classType = this._bulletClass;
}
2016-06-17 00:11:24 +00:00
}
});
/**
* This controls how the bullets will be killed. The default is `Phaser.Weapon.KILL_WORLD_BOUNDS`.
*
* There are 7 different "kill types" available:
*
* * `Phaser.Weapon.KILL_NEVER`
* The bullets are never destroyed by the Weapon. It's up to you to destroy them via your own code.
*
* * `Phaser.Weapon.KILL_LIFESPAN`
* The bullets are automatically killed when their `bulletLifespan` amount expires.
2016-07-01 15:57:13 +00:00
*
2016-06-17 00:11:24 +00:00
* * `Phaser.Weapon.KILL_DISTANCE`
* The bullets are automatically killed when they exceed `bulletDistance` pixels away from their original launch position.
2016-07-01 15:57:13 +00:00
*
2016-06-17 00:11:24 +00:00
* * `Phaser.Weapon.KILL_WEAPON_BOUNDS`
* The bullets are automatically killed when they no longer intersect with the `Weapon.bounds` rectangle.
*
* * `Phaser.Weapon.KILL_CAMERA_BOUNDS`
* The bullets are automatically killed when they no longer intersect with the `Camera.bounds` rectangle.
*
* * `Phaser.Weapon.KILL_WORLD_BOUNDS`
* The bullets are automatically killed when they no longer intersect with the `World.bounds` rectangle.
*
* * `Phaser.Weapon.KILL_STATIC_BOUNDS`
* The bullets are automatically killed when they no longer intersect with the `Weapon.bounds` rectangle.
* The difference between static bounds and weapon bounds, is that a static bounds will never be adjusted to
* match the position of a tracked sprite or pointer.
*
* @name Phaser.Weapon#bulletKillType
* @property {integer} bulletKillType
*/
Object.defineProperty(Phaser.Weapon.prototype, "bulletKillType", {
get: function () {
return this._bulletKillType;
},
set: function (type) {
switch (type)
{
case Phaser.Weapon.KILL_STATIC_BOUNDS:
case Phaser.Weapon.KILL_WEAPON_BOUNDS:
this.bulletBounds = this.bounds;
break;
case Phaser.Weapon.KILL_CAMERA_BOUNDS:
this.bulletBounds = this.game.camera.view;
break;
case Phaser.Weapon.KILL_WORLD_BOUNDS:
this.bulletBounds = this.game.world.bounds;
break;
}
this._bulletKillType = type;
}
});
/**
* Should bullets collide with the World bounds or not?
*
* @name Phaser.Weapon#bulletCollideWorldBounds
* @property {boolean} bulletCollideWorldBounds
*/
Object.defineProperty(Phaser.Weapon.prototype, "bulletCollideWorldBounds", {
get: function () {
return this._bulletCollideWorldBounds;
},
set: function (value) {
this._bulletCollideWorldBounds = value;
this.bullets.setAll('body.collideWorldBounds', value);
this.bullets.setAll('data.bodyDirty', false);
}
});
/**
* The x coordinate from which bullets are fired. This is the same as `Weapon.fireFrom.x`, and
* can be overridden by the `Weapon.fire` arguments.
*
* @name Phaser.Weapon#x
* @property {number} x
*/
Object.defineProperty(Phaser.Weapon.prototype, "x", {
get: function () {
return this.fireFrom.x;
},
set: function (value) {
this.fireFrom.x = value;
}
});
/**
* The y coordinate from which bullets are fired. This is the same as `Weapon.fireFrom.y`, and
* can be overridden by the `Weapon.fire` arguments.
*
* @name Phaser.Weapon#y
* @property {number} y
*/
Object.defineProperty(Phaser.Weapon.prototype, "y", {
get: function () {
return this.fireFrom.y;
},
set: function (value) {
this.fireFrom.y = value;
}
});
</pre>
</article>
</section>
</div>
<div class="clearfix"></div>
<footer>
<span class="copyright">
Phaser Copyright © 2012-2016 Photon Storm Ltd.
</span>
<br />
<span class="jsdoc-message">
2016-11-23 00:59:32 +00:00
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a>
2016-11-28 16:50:04 +00:00
on Mon Nov 28 2016 18:47:54 GMT+0200 (EET) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
2016-06-17 00:11:24 +00:00
</span>
</footer>
</div>
<br clear="both">
</div>
</div>
<script src="scripts/sunlight.js"></script>
<script src="scripts/sunlight.javascript.js"></script>
<script src="scripts/sunlight-plugin.doclinks.js"></script>
<script src="scripts/sunlight-plugin.linenumbers.js"></script>
<script src="scripts/sunlight-plugin.menu.js"></script>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/jquery.scrollTo.js"></script>
<script src="scripts/jquery.localScroll.js"></script>
<script src="scripts/bootstrap-dropdown.js"></script>
<script src="scripts/toc.js"></script>
<script> Sunlight.highlightAll({lineNumbers:true, showMenu: true, enableDoclinks :true}); </script>
<script>
$( function () {
$( "#toc" ).toc( {
anchorName : function(i, heading, prefix) {
return $(heading).attr("id") || ( prefix + i );
},
selectors : "h1,h2,h3,h4",
showAndHide : false,
scrollTo : 60
} );
$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
} );
</script>
</body>
</html>