phaser/docs/src_core_Group.js.html

3374 lines
102 KiB
HTML
Raw Normal View History

2013-10-02 00:16:40 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
2015-03-23 23:46:30 +00:00
<title>Phaser Source: src/core/Group.js</title>
2013-10-02 00:16:40 +00:00
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
2014-11-15 20:01:46 +00:00
<link type="text/css" rel="stylesheet" href="styles/default.css">
2013-10-02 00:16:40 +00:00
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
</head>
<body>
2014-11-25 00:23:44 +00:00
2013-10-02 00:16:40 +00:00
<div class="container-fluid">
<div class="navbar navbar-fixed-top navbar-inverse">
2014-11-25 00:23:44 +00:00
<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>
2013-10-02 00:16:40 +00:00
<div class="navbar-inner">
2014-11-25 00:23:44 +00:00
<a class="brand" href="index.html">Phaser API</a>
2013-10-02 00:16:40 +00:00
<ul class="nav">
2014-11-25 00:23:44 +00:00
2013-10-02 00:16:40 +00:00
<li class="dropdown">
<a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b
2013-10-02 00:16:40 +00:00
class="caret"></b></a>
<ul class="dropdown-menu ">
2014-04-10 22:13:43 +00:00
<li class="class-depth-0">
<a href="Phaser.html">Phaser</a>
2013-10-02 00:16:40 +00:00
</li>
2014-11-15 20:01:46 +00:00
<li class="class-depth-0">
<a href="PIXI.html">PIXI</a>
</li>
2013-10-02 00:16:40 +00:00
</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 ">
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 00:16:40 +00:00
<a href="Phaser.Animation.html">Animation</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.AnimationManager.html">AnimationManager</a>
2013-10-02 00:16:40 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.AnimationParser.html">AnimationParser</a>
2013-10-02 00:16:40 +00:00
</li>
2014-11-25 00:23:44 +00:00
<li class="class-depth-1">
<a href="Phaser.ArraySet.html">ArraySet</a>
</li>
2014-11-15 20:01:46 +00:00
<li class="class-depth-1">
<a href="Phaser.ArrayUtils.html">ArrayUtils</a>
</li>
2014-10-09 15:12:53 +00:00
<li class="class-depth-1">
<a href="Phaser.AudioSprite.html">AudioSprite</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.BitmapData.html">BitmapData</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.BitmapText.html">BitmapText</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Button.html">Button</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Cache.html">Cache</a>
2013-10-02 00:16:40 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Camera.html">Camera</a>
2013-10-02 00:16:40 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Canvas.html">Canvas</a>
2013-10-02 14:05:55 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Circle.html">Circle</a>
2013-10-02 00:16:40 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Color.html">Color</a>
2013-10-03 00:21:08 +00:00
</li>
2015-03-23 23:46:30 +00:00
<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>
2015-07-22 14:31:30 +00:00
<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>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Device.html">Device</a>
2013-10-02 11:11:22 +00:00
</li>
2015-07-22 14:31:30 +00:00
<li class="class-depth-1">
<a href="Phaser.DeviceButton.html">DeviceButton</a>
</li>
2014-11-15 20:01:46 +00:00
<li class="class-depth-1">
<a href="Phaser.DOM.html">DOM</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Easing.html">Easing</a>
</li>
2015-03-23 23:46:30 +00:00
<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>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Ellipse.html">Ellipse</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Events.html">Events</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.Filter.html">Filter</a>
</li>
2014-09-09 14:36:56 +00:00
<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>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Frame.html">Frame</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.FrameData.html">FrameData</a>
2013-10-03 00:21:08 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 00:16:40 +00:00
<a href="Phaser.Game.html">Game</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.GameObjectCreator.html">GameObjectCreator</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.GameObjectFactory.html">GameObjectFactory</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2014-02-05 06:29:17 +00:00
<a href="Phaser.Gamepad.html">Gamepad</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Graphics.html">Graphics</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 00:16:40 +00:00
<a href="Phaser.Group.html">Group</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Image.html">Image</a>
</li>
2015-07-22 14:31:30 +00:00
<li class="class-depth-1">
<a href="Phaser.ImageCollection.html">ImageCollection</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 12:18:58 +00:00
<a href="Phaser.Input.html">Input</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.InputHandler.html">InputHandler</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Key.html">Key</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Keyboard.html">Keyboard</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2014-02-05 06:29:17 +00:00
<a href="Phaser.Line.html">Line</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 11:11:22 +00:00
<a href="Phaser.LinkedList.html">LinkedList</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Loader.html">Loader</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.LoaderParser.html">LoaderParser</a>
2013-10-02 14:05:55 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Math.html">Math</a>
</li>
2015-07-22 14:31:30 +00:00
<li class="class-depth-1">
<a href="Phaser.Matrix.html">Matrix</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Mouse.html">Mouse</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.MSPointer.html">MSPointer</a>
2013-10-02 11:11:22 +00:00
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 19:18:24 +00:00
<a href="Phaser.Net.html">Net</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Particle.html">Particle</a>
</li>
<li class="class-depth-1">
2013-10-02 19:18:24 +00:00
<a href="Phaser.Particles.html">Particles</a>
</li>
2014-10-09 15:12:53 +00:00
<li class="class-depth-2">
<a href="Phaser.Particles.Arcade.html">Arcade</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
2013-10-02 19:18:24 +00:00
<a href="Phaser.Particles.Arcade.Emitter.html">Emitter</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Physics.html">Physics</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Physics.Arcade.html">Arcade</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.Arcade.Body.html">Body</a>
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.Arcade.html#TilemapCollision">TilemapCollision</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Physics.Ninja.html">Ninja</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.AABB.html">AABB</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Body.html">Body</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Circle.html">Circle</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Tile.html">Tile</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Physics.P2.html">P2</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Body.html">Body</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.BodyDebug.html">BodyDebug</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.CollisionGroup.html">CollisionGroup</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.ContactMaterial.html">ContactMaterial</a>
</li>
2014-04-10 22:13:43 +00:00
<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>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.GearConstraint.html">GearConstraint</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.InversePointProxy.html">InversePointProxy</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.LockConstraint.html">LockConstraint</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Material.html">Material</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.PointProxy.html">PointProxy</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.PrismaticConstraint.html">PrismaticConstraint</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.RevoluteConstraint.html">RevoluteConstraint</a>
</li>
2014-09-09 14:36:56 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.RotationalSpring.html">RotationalSpring</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Spring.html">Spring</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 11:11:22 +00:00
<a href="Phaser.Plugin.html">Plugin</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.PluginManager.html">PluginManager</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 11:11:22 +00:00
<a href="Phaser.Point.html">Point</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Pointer.html">Pointer</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Polygon.html">Polygon</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.QuadTree.html">QuadTree</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.RandomDataGenerator.html">RandomDataGenerator</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 11:11:22 +00:00
<a href="Phaser.Rectangle.html">Rectangle</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.RenderTexture.html">RenderTexture</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-03 00:21:08 +00:00
<a href="Phaser.RequestAnimationFrame.html">RequestAnimationFrame</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.RetroFont.html">RetroFont</a>
</li>
2014-09-09 14:36:56 +00:00
<li class="class-depth-1">
<a href="Phaser.Rope.html">Rope</a>
</li>
2015-07-22 14:31:30 +00:00
<li class="class-depth-1">
<a href="Phaser.RoundedRectangle.html">RoundedRectangle</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.ScaleManager.html">ScaleManager</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 11:11:22 +00:00
<a href="Phaser.Signal.html">Signal</a>
</li>
<li class="class-depth-1">
<a href="Phaser.SignalBinding.html">SignalBinding</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2014-02-05 06:29:17 +00:00
<a href="Phaser.SinglePad.html">SinglePad</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-03 00:21:08 +00:00
<a href="Phaser.Sound.html">Sound</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-03 00:21:08 +00:00
<a href="Phaser.SoundManager.html">SoundManager</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Sprite.html">Sprite</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.SpriteBatch.html">SpriteBatch</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 11:11:22 +00:00
<a href="Phaser.Stage.html">Stage</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 11:11:22 +00:00
<a href="Phaser.State.html">State</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 11:11:22 +00:00
<a href="Phaser.StateManager.html">StateManager</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.Text.html">Text</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.Tile.html">Tile</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.Tilemap.html">Tilemap</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.TilemapLayer.html">TilemapLayer</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.TilemapParser.html">TilemapParser</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.Tileset.html">Tileset</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-25 15:54:40 +00:00
<a href="Phaser.TileSprite.html">TileSprite</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Time.html">Time</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-11-28 15:57:09 +00:00
<a href="Phaser.Timer.html">Timer</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2014-02-05 06:29:17 +00:00
<a href="Phaser.TimerEvent.html">TimerEvent</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2013-10-02 14:05:55 +00:00
<a href="Phaser.Touch.html">Touch</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Tween.html">Tween</a>
</li>
2014-11-25 00:23:44 +00:00
<li class="class-depth-1">
<a href="Phaser.TweenData.html">TweenData</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.TweenManager.html">TweenManager</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
<a href="Phaser.Utils.html">Utils</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-2">
<a href="Phaser.Utils.Debug.html">Debug</a>
</li>
2014-04-10 22:13:43 +00:00
<li class="class-depth-1">
2015-07-22 14:31:30 +00:00
<a href="Phaser.Video.html">Video</a>
2013-10-02 11:11:22 +00:00
</li>
2014-11-15 20:01:46 +00:00
<li class="class-depth-1">
2015-07-22 14:31:30 +00:00
<a href="Phaser.World.html">World</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-07-22 14:31:30 +00:00
<a href="PIXI.AbstractFilter.html">AbstractFilter</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-07-22 14:31:30 +00:00
<a href="PIXI.BaseTexture.html">BaseTexture</a>
2014-11-15 20:01:46 +00:00
</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.DisplayObject.html">DisplayObject</a>
</li>
<li class="class-depth-1">
<a href="PIXI.DisplayObjectContainer.html">DisplayObjectContainer</a>
</li>
<li class="class-depth-1">
<a href="PIXI.Event.html">Event</a>
</li>
<li class="class-depth-1">
<a href="PIXI.EventTarget.html">EventTarget</a>
</li>
<li class="class-depth-1">
<a href="PIXI.FilterTexture.html">FilterTexture</a>
</li>
<li class="class-depth-1">
<a href="PIXI.Graphics.html">Graphics</a>
</li>
<li class="class-depth-1">
<a href="PIXI.GraphicsData.html">GraphicsData</a>
</li>
<li class="class-depth-1">
<a href="PIXI.PIXI.html">PIXI</a>
</li>
<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">
2015-03-23 23:46:30 +00:00
<a href="PIXI.PolyK.html">PolyK</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.PrimitiveShader.html">PrimitiveShader</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.RenderTexture.html">RenderTexture</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.Rope.html">Rope</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.Sprite.html">Sprite</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.SpriteBatch.html">SpriteBatch</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.Stage.html">Stage</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.Strip.html">Strip</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.StripShader.html">StripShader</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.Texture.html">Texture</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.TilingSprite.html">TilingSprite</a>
2014-11-15 20:01:46 +00:00
</li>
2014-11-25 00:23:44 +00:00
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.WebGLBlendModeManager.html">WebGLBlendModeManager</a>
2014-11-25 00:23:44 +00:00
</li>
2014-11-15 20:01:46 +00:00
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.WebGLFastSpriteBatch.html">WebGLFastSpriteBatch</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.WebGLFilterManager.html">WebGLFilterManager</a>
2014-11-15 20:01:46 +00:00
</li>
<li class="class-depth-1">
2015-03-23 23:46:30 +00:00
<a href="PIXI.WebGLRenderer.html">WebGLRenderer</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
</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">
2015-07-22 14:31:30 +00:00
<a href="global.html#AUTO">AUTO</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
2015-07-22 14:31:30 +00:00
<a href="global.html#BITMAPDATA">BITMAPDATA</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
2015-07-22 14:31:30 +00:00
<a href="global.html#BITMAPTEXT">BITMAPTEXT</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
<a href="global.html#blendModes">blendModes</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
2015-07-22 14:31:30 +00:00
<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>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
2015-07-22 14:31:30 +00:00
<a href="global.html#CIRCLE">CIRCLE</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
2015-07-22 14:31:30 +00:00
<a href="global.html#CREATURE">CREATURE</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
2015-07-22 14:31:30 +00:00
<a href="global.html#DOWN">DOWN</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
2015-07-22 14:31:30 +00:00
<a href="global.html#ELLIPSE">ELLIPSE</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
2015-07-22 14:31:30 +00:00
<a href="global.html#EMITTER">EMITTER</a>
</li>
<li class="class-depth-0">
<a href="global.html#GAMES">GAMES</a>
</li>
<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#IMAGE">IMAGE</a>
</li>
<li class="class-depth-0">
<a href="global.html#LEFT">LEFT</a>
</li>
<li class="class-depth-0">
<a href="global.html#LINE">LINE</a>
</li>
<li class="class-depth-0">
<a href="global.html#MATRIX">MATRIX</a>
</li>
<li class="class-depth-0">
<a href="global.html#NONE">NONE</a>
</li>
<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#RECTANGLE">RECTANGLE</a>
</li>
<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#ROPE">ROPE</a>
</li>
<li class="class-depth-0">
<a href="global.html#ROUNDEDRECTANGLE">ROUNDEDRECTANGLE</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
<a href="global.html#scaleModes">scaleModes</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
2015-07-22 14:31:30 +00:00
<a href="global.html#SPRITE">SPRITE</a>
</li>
<li class="class-depth-0">
<a href="global.html#SPRITEBATCH">SPRITEBATCH</a>
</li>
<li class="class-depth-0">
<a href="global.html#TEXT">TEXT</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
2015-07-22 14:31:30 +00:00
<a href="global.html#TILEMAP">TILEMAP</a>
2014-11-15 20:01:46 +00:00
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-0">
2015-07-22 14:31:30 +00:00
<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#UP">UP</a>
</li>
<li class="class-depth-0">
<a href="global.html#VERSION">VERSION</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>
2014-11-15 20:01:46 +00:00
</li>
2013-10-02 00:16:40 +00:00
</ul>
</li>
2014-11-25 00:23:44 +00:00
2014-11-15 20:01:46 +00:00
<li class="dropdown">
2014-11-25 00:23:44 +00:00
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Core<b class="caret"></b></a>
<ul class="dropdown-menu ">
2014-12-03 10:39:11 +00:00
<li class="class-depth-1"><a href="Phaser.Game.html">Game</a></li>
2014-11-25 00:23:44 +00:00
<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>
2015-07-22 14:31:30 +00:00
<li class="class-depth-1"><a href="Phaser.Cache.html">Cache</a></li>
2014-11-25 00:23:44 +00:00
<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>
2015-01-06 06:57:25 +00:00
<li class="class-depth-1"><a href="Phaser.Input.html">Input Manager</a></li>
2014-11-25 00:23:44 +00:00
<li class="class-depth-1"><a href="Phaser.ScaleManager.html">Scale Manager</a></li>
</ul>
</li>
2014-11-15 20:01:46 +00:00
2014-11-25 00:23:44 +00:00
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Game Objects<b class="caret"></b></a>
2014-11-15 20:01:46 +00:00
<ul class="dropdown-menu ">
2014-11-25 00:23:44 +00:00
<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>
2015-07-22 14:31:30 +00:00
<li class="class-depth-1"><a href="Phaser.Video.html">Video</a></li>
2015-01-06 06:57:25 +00:00
<li class="class-depth-1"><a href="Phaser.Particles.Arcade.Emitter.html">Particle Emitter</a></li>
2014-12-03 10:39:11 +00:00
<li class="class-depth-1"><a href="Phaser.Particle.html">Particle</a></li>
2014-11-25 00:23:44 +00:00
<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>
2014-11-15 20:01:46 +00:00
2014-11-25 00:23:44 +00:00
<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>
2015-07-22 14:31:30 +00:00
<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>
2014-11-25 00:23:44 +00:00
<li class="class-depth-1"><a href="Phaser.Polygon.html">Polygon</a></li>
2015-07-22 14:31:30 +00:00
<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>
2014-11-15 20:01:46 +00:00
</ul>
</li>
2014-11-25 00:23:44 +00:00
<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-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>
2015-07-22 14:31:30 +00:00
<li class="class-depth-1"><a href="Phaser.DeviceButton.html">Device Button</a></li>
2014-11-25 00:23:44 +00:00
<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>
<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 ">
2015-03-26 02:55:18 +00:00
<li class="class-depth-1"><a href="http://phaser.io">Phaser Web Site</a></li>
2014-11-25 00:23:44 +00:00
<li class="class-depth-1"><a href="https://github.com/photonstorm/phaser">Phaser Github</a></li>
2015-03-26 02:55:18 +00:00
<li class="class-depth-1"><a href="http://phaser.io/examples">Phaser Examples</a></li>
2014-11-25 00:23:44 +00:00
<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>
2015-07-22 14:31:30 +00:00
<li class="class-depth-1"><a href="http://phaser.io/learn">Tutorials</a></li>
2014-11-25 00:23:44 +00:00
<li class="class-depth-1"><a href="https://confirmsubscription.com/h/r/369DE48E3E86AF1E">Newsletter</a></li>
2015-03-26 02:55:18 +00:00
<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/irc">IRC</a></li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-1"><a href="https://www.codeandweb.com/texturepacker/phaser">Texture Packer</a></li>
2014-11-25 00:23:44 +00:00
</ul>
</li>
2013-10-02 00:16:40 +00:00
</ul>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<div id="main">
2015-03-23 23:46:30 +00:00
<h1 class="page-title">Source: src/core/Group.js</h1>
2013-10-02 00:16:40 +00:00
<section>
<article>
<pre class="sunlight-highlight-javascript linenums">/**
* @author Richard Davey &lt;rich@photonstorm.com>
2015-03-23 23:46:30 +00:00
* @copyright 2015 Photon Storm Ltd.
2013-10-02 00:16:40 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
2014-12-03 10:39:11 +00:00
* A Group is a container for {@link DisplayObject display objects} including {@link Phaser.Sprite Sprites} and {@link Phaser.Image Images}.
*
* Groups form the logical tree structure of the display/scene graph where local transformations are applied to children.
* For instance, all children are also moved/rotated/scaled when the group is moved/rotated/scaled.
*
* In addition, Groups provides support for fast pooling and object recycling.
*
* Groups are also display objects and can be nested as children within other Groups.
2014-10-09 15:12:53 +00:00
*
2013-10-02 00:16:40 +00:00
* @class Phaser.Group
2014-10-22 20:49:44 +00:00
* @extends PIXI.DisplayObjectContainer
2013-10-02 00:16:40 +00:00
* @param {Phaser.Game} game - A reference to the currently running game.
2014-12-03 10:39:11 +00:00
* @param {DisplayObject|null} [parent=(game world)] - The parent Group (or other {@link DisplayObject}) that this group will be added to.
* If undefined/unspecified the Group will be added to the {@link Phaser.Game#world Game World}; if null the Group will not be added to any parent.
* @param {string} [name='group'] - A name for this group. Not used internally but useful for debugging.
* @param {boolean} [addToStage=false] - If true this group will be added directly to the Game.Stage instead of Game.World.
* @param {boolean} [enableBody=false] - If true all Sprites created with {@link #create} or {@link #createMulitple} will have a physics body created on them. Change the body type with {@link #physicsBodyType}.
* @param {integer} [physicsBodyType=0] - The physics body type to use when physics bodies are automatically added. See {@link #physicsBodyType} for values.
2013-10-02 00:16:40 +00:00
*/
Phaser.Group = function (game, parent, name, addToStage, enableBody, physicsBodyType) {
2013-10-02 00:16:40 +00:00
2015-07-22 14:31:30 +00:00
if (addToStage === undefined) { addToStage = false; }
if (enableBody === undefined) { enableBody = false; }
if (physicsBodyType === undefined) { physicsBodyType = Phaser.Physics.ARCADE; }
2013-11-28 15:57:09 +00:00
/**
2014-12-03 10:39:11 +00:00
* A reference to the currently running Game.
* @property {Phaser.Game} game
* @protected
2013-11-28 15:57:09 +00:00
*/
this.game = game;
2014-02-05 06:29:17 +00:00
2015-07-22 14:31:30 +00:00
if (parent === undefined)
2014-02-05 06:29:17 +00:00
{
parent = game.world;
}
2013-11-28 15:57:09 +00:00
/**
2014-12-03 10:39:11 +00:00
* A name for this group. Not used internally but useful for debugging.
* @property {string} name
2013-11-28 15:57:09 +00:00
*/
this.name = name || 'group';
2013-10-02 00:16:40 +00:00
2014-11-15 20:01:46 +00:00
/**
2014-12-03 10:39:11 +00:00
* The z-depth value of this object within its parent container/Group - the World is a Group as well.
* This value must be unique for each child in a Group.
* @property {integer} z
2014-11-15 20:01:46 +00:00
*/
this.z = 0;
PIXI.DisplayObjectContainer.call(this);
2014-02-05 06:29:17 +00:00
2015-03-23 23:46:30 +00:00
if (addToStage)
{
this.game.stage.addChild(this);
2014-11-15 20:01:46 +00:00
this.z = this.game.stage.children.length;
}
2015-03-23 23:46:30 +00:00
else
{
if (parent)
{
parent.addChild(this);
2014-11-15 20:01:46 +00:00
this.z = parent.children.length;
2013-11-28 15:57:09 +00:00
}
}
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Internal Phaser Type value.
* @property {integer} type
2013-11-28 15:57:09 +00:00
* @protected
*/
this.type = Phaser.GROUP;
2015-03-23 23:46:30 +00:00
/**
* @property {number} physicsType - The const physics body type of this object.
* @readonly
*/
this.physicsType = Phaser.GROUP;
2014-02-05 06:29:17 +00:00
/**
2014-12-03 10:39:11 +00:00
* The alive property is useful for Groups that are children of other Groups and need to be included/excluded in checks like forEachAlive.
* @property {boolean} alive
2014-02-05 06:29:17 +00:00
* @default
*/
this.alive = true;
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* If exists is true the group is updated, otherwise it is skipped.
* @property {boolean} exists
2013-11-28 15:57:09 +00:00
* @default
*/
this.exists = true;
2014-10-09 15:12:53 +00:00
/**
2014-12-03 10:39:11 +00:00
* A group with `ignoreDestroy` set to `true` ignores all calls to its `destroy` method.
* @property {boolean} ignoreDestroy
2014-10-09 15:12:53 +00:00
* @default
*/
this.ignoreDestroy = false;
2015-07-22 14:31:30 +00:00
/**
* A Group is that has `pendingDestroy` set to `true` is flagged to have its destroy method
* called on the next logic update.
* You can set it directly to flag the Group to be destroyed on its next update.
*
* This is extremely useful if you wish to destroy a Group from within one of its own callbacks
* or a callback of one of its children.
*
* @property {boolean} pendingDestroy
*/
this.pendingDestroy = false;
2014-04-29 14:39:02 +00:00
/**
2014-12-03 10:39:11 +00:00
* The type of objects that will be created when using {@link #create} or {@link #createMultiple}.
*
* Any object may be used but it should extend either Sprite or Image and accept the same constructor arguments:
* when a new object is created it is passed the following parameters to its constructor: `(game, x, y, key, frame)`.
*
2014-04-29 14:39:02 +00:00
* @property {object} classType
2014-12-03 10:39:11 +00:00
* @default {@link Phaser.Sprite}
2014-04-29 14:39:02 +00:00
*/
this.classType = Phaser.Sprite;
2013-11-01 18:16:52 +00:00
/**
2015-03-23 23:46:30 +00:00
* The current display object that the group cursor is pointing to, if any. (Can be set manually.)
2014-12-03 10:39:11 +00:00
*
* The cursor is a way to iterate through the children in a Group using {@link #next} and {@link #previous}.
* @property {?DisplayObject} cursor
2013-11-28 15:57:09 +00:00
*/
2013-11-01 18:16:52 +00:00
this.cursor = null;
/**
2014-12-03 10:39:11 +00:00
* If true all Sprites created by, or added to this group, will have a physics body enabled on them.
*
* The default body type is controlled with {@link #physicsBodyType}.
* @property {boolean} enableBody
*/
2014-03-24 12:41:45 +00:00
this.enableBody = enableBody;
/**
2014-12-03 10:39:11 +00:00
* If true when a physics body is created (via {@link #enableBody}) it will create a physics debug object as well.
*
* This only works for P2 bodies.
* @property {boolean} enableBodyDebug
* @default
*/
2014-03-24 12:41:45 +00:00
this.enableBodyDebug = false;
/**
2014-12-03 10:39:11 +00:00
* If {@link #enableBody} is true this is the type of physics body that is created on new Sprites.
*
* The valid values are {@link Phaser.Physics.ARCADE}, {@link Phaser.Physics.P2}, {@link Phaser.Physics.NINJA}, etc.
* @property {integer} physicsBodyType
*/
this.physicsBodyType = physicsBodyType;
2015-07-22 14:31:30 +00:00
/**
* If this Group contains Arcade Physics Sprites you can set a custom sort direction via this property.
*
* It should be set to one of the Phaser.Physics.Arcade sort direction constants:
*
* Phaser.Physics.Arcade.SORT_NONE
* Phaser.Physics.Arcade.LEFT_RIGHT
* Phaser.Physics.Arcade.RIGHT_LEFT
* Phaser.Physics.Arcade.TOP_BOTTOM
* Phaser.Physics.Arcade.BOTTOM_TOP
*
* If set to `null` the Group will use whatever Phaser.Physics.Arcade.sortDirection is set to. This is the default behavior.
*
* @property {integer} physicsSortDirection
* @default
*/
this.physicsSortDirection = null;
2014-09-09 14:36:56 +00:00
/**
2014-12-03 10:39:11 +00:00
* This signal is dispatched when the group is destroyed.
* @property {Phaser.Signal} onDestroy
2014-09-09 14:36:56 +00:00
*/
this.onDestroy = new Phaser.Signal();
/**
2015-03-23 23:46:30 +00:00
* @property {integer} cursorIndex - The current index of the Group cursor. Advance it with Group.next.
* @readOnly
*/
this.cursorIndex = 0;
/**
* A Group that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in Group.cameraOffset.
*
* Note that the cameraOffset values are in addition to any parent in the display list.
* So if this Group was in a Group that has x: 200, then this will be added to the cameraOffset.x
*
* @property {boolean} fixedToCamera
*/
this.fixedToCamera = false;
/**
* If this object is {@link #fixedToCamera} then this stores the x/y position offset relative to the top-left of the camera view.
* If the parent of this Group is also `fixedToCamera` then the offset here is in addition to that and should typically be disabled.
* @property {Phaser.Point} cameraOffset
*/
this.cameraOffset = new Phaser.Point();
/**
2015-07-22 14:31:30 +00:00
* The hash array is an array belonging to this Group into which you can add any of its children via Group.addToHash and Group.removeFromHash.
*
* Only children of this Group can be added to and removed from the hash.
*
* This hash is used automatically by Phaser Arcade Physics in order to perform non z-index based destructive sorting.
* However if you don't use Arcade Physics, or this isn't a physics enabled Group, then you can use the hash to perform your own
* sorting and filtering of Group children without touching their z-index (and therefore display draw order)
*
* @property {array} hash
*/
2015-07-22 14:31:30 +00:00
this.hash = [];
/**
2015-03-23 23:46:30 +00:00
* The property on which children are sorted.
* @property {string} _sortProperty
* @private
*/
2015-03-23 23:46:30 +00:00
this._sortProperty = 'z';
2013-10-02 00:16:40 +00:00
};
Phaser.Group.prototype = Object.create(PIXI.DisplayObjectContainer.prototype);
Phaser.Group.prototype.constructor = Phaser.Group;
/**
2014-12-03 10:39:11 +00:00
* A returnType value, as specified in {@link #iterate} eg.
* @constant
2014-12-03 10:39:11 +00:00
* @type {integer}
*/
Phaser.Group.RETURN_NONE = 0;
/**
2014-12-03 10:39:11 +00:00
* A returnType value, as specified in {@link #iterate} eg.
* @constant
2014-12-03 10:39:11 +00:00
* @type {integer}
*/
Phaser.Group.RETURN_TOTAL = 1;
/**
2014-12-03 10:39:11 +00:00
* A returnType value, as specified in {@link #iterate} eg.
* @constant
2014-12-03 10:39:11 +00:00
* @type {integer}
*/
Phaser.Group.RETURN_CHILD = 2;
/**
2014-12-03 10:39:11 +00:00
* A sort ordering value, as specified in {@link #sort} eg.
* @constant
2014-12-03 10:39:11 +00:00
* @type {integer}
*/
Phaser.Group.SORT_ASCENDING = -1;
/**
2014-12-03 10:39:11 +00:00
* A sort ordering value, as specified in {@link #sort} eg.
* @constant
2014-12-03 10:39:11 +00:00
* @type {integer}
*/
Phaser.Group.SORT_DESCENDING = 1;
/**
2014-12-03 10:39:11 +00:00
* Adds an existing object as the top child in this group.
*
* The child is automatically added to the top of the group and is displayed on top of every previous child.
*
2015-07-22 14:31:30 +00:00
* If Group.enableBody is set then a physics body will be created on the object, so long as one does not already exist.
*
2014-12-03 10:39:11 +00:00
* Use {@link #addAt} to control where a child is added. Use {@link #create} to create and add a new child.
*
* @method Phaser.Group#add
2014-12-03 10:39:11 +00:00
* @param {DisplayObject} child - The display object to add as a child.
* @param {boolean} [silent=false] - If true the child will not dispatch the `onAddedToGroup` event.
* @return {DisplayObject} The child that was added to the group.
*/
2014-07-10 19:31:11 +00:00
Phaser.Group.prototype.add = function (child, silent) {
2015-07-22 14:31:30 +00:00
if (silent === undefined) { silent = false; }
if (child.parent !== this)
{
this.addChild(child);
2013-10-02 00:16:40 +00:00
child.z = this.children.length;
2015-07-22 14:31:30 +00:00
if (this.enableBody &amp;&amp; child.body === null)
{
this.game.physics.enable(child, this.physicsBodyType);
}
else if (child.body)
{
this.addToHash(child);
}
2015-03-23 23:46:30 +00:00
if (!silent &amp;&amp; child.events)
2013-11-28 15:57:09 +00:00
{
2014-12-03 10:39:11 +00:00
child.events.onAddedToGroup$dispatch(child, this);
}
2014-02-05 06:29:17 +00:00
if (this.cursor === null)
{
this.cursor = child;
}
}
2014-02-05 06:29:17 +00:00
return child;
2013-10-02 00:16:40 +00:00
};
2013-10-25 15:54:40 +00:00
2014-09-09 14:36:56 +00:00
/**
2015-07-22 14:31:30 +00:00
* Adds a child of this Group into the hash array.
* This call will return false if the child is not a child of this Group, or is already in the hash.
*
* @method Phaser.Group#addToHash
* @param {DisplayObject} child - The display object to add to this Groups hash. Must be a member of this Group already and not present in the hash.
* @return {boolean} True if the child was successfully added to the hash, otherwise false.
*/
Phaser.Group.prototype.addToHash = function (child) {
if (child.parent === this)
{
var index = this.hash.indexOf(child);
if (index === -1)
{
this.hash.push(child);
return true;
}
}
return false;
};
/**
* Removes a child of this Group from the hash array.
* This call will return false if the child is not in the hash.
*
* @method Phaser.Group#removeFromHash
* @param {DisplayObject} child - The display object to remove from this Groups hash. Must be a member of this Group and in the hash.
* @return {boolean} True if the child was successfully removed from the hash, otherwise false.
*/
Phaser.Group.prototype.removeFromHash = function (child) {
if (child)
{
var index = this.hash.indexOf(child);
if (index !== -1)
{
this.hash.splice(index, 1);
return true;
}
}
return false;
};
/**
* Adds an array of existing Display Objects to this Group.
2014-12-03 10:39:11 +00:00
*
2015-07-22 14:31:30 +00:00
* The Display Objects are automatically added to the top of this Group, and will render on-top of everything already in this Group.
2014-12-03 10:39:11 +00:00
*
2015-07-22 14:31:30 +00:00
* As well as an array you can also pass another Group as the first argument. In this case all of the children from that
* Group will be removed from it and added into this Group.
2014-09-09 14:36:56 +00:00
*
* @method Phaser.Group#addMultiple
2015-07-22 14:31:30 +00:00
* @param {DisplayObject[]|Phaser.Group} children - An array of display objects or a Phaser.Group. If a Group is given then *all* children will be moved from it.
2014-12-03 10:39:11 +00:00
* @param {boolean} [silent=false] - If true the children will not dispatch the `onAddedToGroup` event.
2015-07-22 14:31:30 +00:00
* @return {DisplayObject[]|Phaser.Group} The array of children or Group of children that were added to this Group.
2014-09-09 14:36:56 +00:00
*/
Phaser.Group.prototype.addMultiple = function (children, silent) {
2015-07-22 14:31:30 +00:00
if (children instanceof Phaser.Group)
{
children.moveAll(this, silent);
}
else if (Array.isArray(children))
2014-09-09 14:36:56 +00:00
{
for (var i = 0; i &lt; children.length; i++)
{
this.add(children[i], silent);
}
}
return children;
};
/**
2014-12-03 10:39:11 +00:00
* Adds an existing object to this group.
*
* The child is added to the group at the location specified by the index value, this allows you to control child ordering.
*
* @method Phaser.Group#addAt
2014-12-03 10:39:11 +00:00
* @param {DisplayObject} child - The display object to add as a child.
* @param {integer} [index=0] - The index within the group to insert the child to.
* @param {boolean} [silent=false] - If true the child will not dispatch the `onAddedToGroup` event.
* @return {DisplayObject} The child that was added to the group.
*/
2014-07-10 19:31:11 +00:00
Phaser.Group.prototype.addAt = function (child, index, silent) {
2015-07-22 14:31:30 +00:00
if (silent === undefined) { silent = false; }
2014-02-05 06:29:17 +00:00
if (child.parent !== this)
{
this.addChildAt(child, index);
2013-11-01 18:16:52 +00:00
this.updateZ();
2015-07-22 14:31:30 +00:00
if (this.enableBody &amp;&amp; child.body === null)
{
this.game.physics.enable(child, this.physicsBodyType);
}
else if (child.body)
{
this.addToHash(child);
}
2015-03-23 23:46:30 +00:00
if (!silent &amp;&amp; child.events)
{
2014-12-03 10:39:11 +00:00
child.events.onAddedToGroup$dispatch(child, this);
2013-11-28 15:57:09 +00:00
}
2013-10-02 00:16:40 +00:00
if (this.cursor === null)
{
this.cursor = child;
}
}
2013-10-02 00:16:40 +00:00
return child;
2013-10-02 00:16:40 +00:00
};
2014-02-05 06:29:17 +00:00
/**
2014-12-03 10:39:11 +00:00
* Returns the child found at the given index within this group.
*
* @method Phaser.Group#getAt
2014-12-03 10:39:11 +00:00
* @param {integer} index - The index to return the child from.
2015-07-22 14:31:30 +00:00
* @return {DisplayObject|integer} The child that was found at the given index, or -1 for an invalid index.
*/
Phaser.Group.prototype.getAt = function (index) {
2014-02-05 06:29:17 +00:00
2014-03-24 12:41:45 +00:00
if (index &lt; 0 || index >= this.children.length)
{
return -1;
}
else
{
return this.getChildAt(index);
}
2013-10-02 00:16:40 +00:00
};
2013-10-25 15:54:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Creates a new Phaser.Sprite object and adds it to the top of this group.
*
* Use {@link #classType} to change the type of object creaded.
*
* @method Phaser.Group#create
2014-12-03 10:39:11 +00:00
* @param {number} x - The x coordinate to display the newly created Sprite at. The value is in relation to the group.x point.
* @param {number} y - The y coordinate to display the newly created Sprite at. The value is in relation to the group.y point.
* @param {string} key - The Game.cache key of the image that this Sprite will use.
2014-12-03 10:39:11 +00:00
* @param {integer|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here.
* @param {boolean} [exists=true] - The default exists state of the Sprite.
2014-12-03 10:39:11 +00:00
* @return {DisplayObject} The child that was created: will be a {@link Phaser.Sprite} unless {@link #classType} has been changed.
*/
Phaser.Group.prototype.create = function (x, y, key, frame, exists) {
2014-02-05 06:29:17 +00:00
2015-07-22 14:31:30 +00:00
if (exists === undefined) { exists = true; }
2013-11-01 18:16:52 +00:00
2014-04-29 14:39:02 +00:00
var child = new this.classType(this.game, x, y, key, frame);
2013-10-02 00:16:40 +00:00
child.exists = exists;
child.visible = exists;
child.alive = exists;
2013-10-02 00:16:40 +00:00
this.addChild(child);
child.z = this.children.length;
2015-07-22 14:31:30 +00:00
if (this.enableBody)
{
this.game.physics.enable(child, this.physicsBodyType, this.enableBodyDebug);
}
if (child.events)
{
2014-12-03 10:39:11 +00:00
child.events.onAddedToGroup$dispatch(child, this);
}
2013-10-02 00:16:40 +00:00
if (this.cursor === null)
{
this.cursor = child;
}
2013-10-02 00:16:40 +00:00
return child;
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Creates multiple Phaser.Sprite objects and adds them to the top of this group.
*
* Useful if you need to quickly generate a pool of identical sprites, such as bullets.
*
* By default the sprites will be set to not exist and will be positioned at 0, 0 (relative to the group.x/y).
2015-07-22 14:31:30 +00:00
* Use {@link #classType} to change the type of object created.
*
* @method Phaser.Group#createMultiple
2014-12-03 10:39:11 +00:00
* @param {integer} quantity - The number of Sprites to create.
* @param {string} key - The Game.cache key of the image that this Sprite will use.
2014-12-03 10:39:11 +00:00
* @param {integer|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here.
* @param {boolean} [exists=false] - The default exists state of the Sprite.
*/
Phaser.Group.prototype.createMultiple = function (quantity, key, frame, exists) {
2013-10-02 00:16:40 +00:00
2015-07-22 14:31:30 +00:00
if (exists === undefined) { exists = false; }
2013-10-02 00:16:40 +00:00
for (var i = 0; i &lt; quantity; i++)
{
this.create(0, 0, key, frame, exists);
}
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2015-07-22 14:31:30 +00:00
* Internal method that re-applies all of the children's Z values.
*
2014-12-03 10:39:11 +00:00
* This must be called whenever children ordering is altered so that their `z` indices are correctly updated.
*
* @method Phaser.Group#updateZ
* @protected
*/
Phaser.Group.prototype.updateZ = function () {
var i = this.children.length;
while (i--)
{
this.children[i].z = i;
}
};
2014-04-29 14:39:02 +00:00
/**
2014-12-03 10:39:11 +00:00
* Sets the group cursor to the first child in the group.
*
* If the optional index parameter is given it sets the cursor to the object at that index instead.
2014-04-29 14:39:02 +00:00
*
* @method Phaser.Group#resetCursor
2014-12-03 10:39:11 +00:00
* @param {integer} [index=0] - Set the cursor to point to a specific index.
* @return {any} The child the cursor now points to.
2014-04-29 14:39:02 +00:00
*/
Phaser.Group.prototype.resetCursor = function (index) {
2015-07-22 14:31:30 +00:00
if (index === undefined) { index = 0; }
2014-04-29 14:39:02 +00:00
if (index > this.children.length - 1)
{
index = 0;
}
if (this.cursor)
{
2015-03-23 23:46:30 +00:00
this.cursorIndex = index;
this.cursor = this.children[this.cursorIndex];
2014-04-29 14:39:02 +00:00
return this.cursor;
}
};
/**
2014-12-03 10:39:11 +00:00
* Advances the group cursor to the next (higher) object in the group.
*
* If the cursor is at the end of the group (top child) it is moved the start of the group (bottom child).
*
* @method Phaser.Group#next
2014-12-03 10:39:11 +00:00
* @return {any} The child the cursor now points to.
*/
Phaser.Group.prototype.next = function () {
2014-02-05 06:29:17 +00:00
if (this.cursor)
{
// Wrap the cursor?
2015-03-23 23:46:30 +00:00
if (this.cursorIndex >= this.children.length - 1)
2013-11-28 15:57:09 +00:00
{
2015-03-23 23:46:30 +00:00
this.cursorIndex = 0;
2013-11-28 15:57:09 +00:00
}
else
2013-11-28 15:57:09 +00:00
{
2015-03-23 23:46:30 +00:00
this.cursorIndex++;
2013-11-28 15:57:09 +00:00
}
2013-11-01 18:16:52 +00:00
2015-03-23 23:46:30 +00:00
this.cursor = this.children[this.cursorIndex];
2014-04-10 22:13:43 +00:00
return this.cursor;
}
2013-10-02 00:16:40 +00:00
};
/**
2014-12-03 10:39:11 +00:00
* Moves the group cursor to the previous (lower) child in the group.
*
* If the cursor is at the start of the group (bottom child) it is moved to the end (top child).
*
* @method Phaser.Group#previous
2014-12-03 10:39:11 +00:00
* @return {any} The child the cursor now points to.
*/
Phaser.Group.prototype.previous = function () {
if (this.cursor)
{
// Wrap the cursor?
2015-03-23 23:46:30 +00:00
if (this.cursorIndex === 0)
{
2015-03-23 23:46:30 +00:00
this.cursorIndex = this.children.length - 1;
}
else
2013-11-28 15:57:09 +00:00
{
2015-03-23 23:46:30 +00:00
this.cursorIndex--;
}
2015-03-23 23:46:30 +00:00
this.cursor = this.children[this.cursorIndex];
2014-04-10 22:13:43 +00:00
return this.cursor;
}
};
/**
2014-12-03 10:39:11 +00:00
* Swaps the position of two children in this group.
*
* Both children must be in this group, a child cannot be swapped with itself, and unparented children cannot be swapped.
*
* @method Phaser.Group#swap
2014-12-03 10:39:11 +00:00
* @param {any} child1 - The first child to swap.
* @param {any} child2 - The second child to swap.
*/
Phaser.Group.prototype.swap = function (child1, child2) {
2014-02-05 06:29:17 +00:00
2014-09-09 14:36:56 +00:00
this.swapChildren(child1, child2);
this.updateZ();
};
2014-02-05 06:29:17 +00:00
/**
2014-12-03 10:39:11 +00:00
* Brings the given child to the top of this group so it renders above all other children.
*
* @method Phaser.Group#bringToTop
2014-12-03 10:39:11 +00:00
* @param {any} child - The child to bring to the top of this group.
* @return {any} The child that was moved.
*/
Phaser.Group.prototype.bringToTop = function (child) {
2015-03-23 23:46:30 +00:00
if (child.parent === this &amp;&amp; this.getIndex(child) &lt; this.children.length)
{
2014-07-10 19:31:11 +00:00
this.remove(child, false, true);
this.add(child, true);
}
2013-11-01 18:16:52 +00:00
return child;
2013-11-01 18:16:52 +00:00
};
2013-11-01 18:16:52 +00:00
/**
2014-12-03 10:39:11 +00:00
* Sends the given child to the bottom of this group so it renders below all other children.
*
* @method Phaser.Group#sendToBack
2014-12-03 10:39:11 +00:00
* @param {any} child - The child to send to the bottom of this group.
* @return {any} The child that was moved.
*/
Phaser.Group.prototype.sendToBack = function (child) {
2015-03-23 23:46:30 +00:00
if (child.parent === this &amp;&amp; this.getIndex(child) > 0)
{
2014-07-10 19:31:11 +00:00
this.remove(child, false, true);
this.addAt(child, 0, true);
}
return child;
};
/**
2014-12-03 10:39:11 +00:00
* Moves the given child up one place in this group unless it's already at the top.
*
* @method Phaser.Group#moveUp
2014-12-03 10:39:11 +00:00
* @param {any} child - The child to move up in the group.
* @return {any} The child that was moved.
*/
Phaser.Group.prototype.moveUp = function (child) {
2015-03-23 23:46:30 +00:00
if (child.parent === this &amp;&amp; this.getIndex(child) &lt; this.children.length - 1)
{
var a = this.getIndex(child);
var b = this.getAt(a + 1);
if (b)
{
2014-04-10 22:13:43 +00:00
this.swap(child, b);
}
}
return child;
};
/**
2014-12-03 10:39:11 +00:00
* Moves the given child down one place in this group unless it's already at the bottom.
*
* @method Phaser.Group#moveDown
2014-12-03 10:39:11 +00:00
* @param {any} child - The child to move down in the group.
* @return {any} The child that was moved.
*/
Phaser.Group.prototype.moveDown = function (child) {
2015-03-23 23:46:30 +00:00
if (child.parent === this &amp;&amp; this.getIndex(child) > 0)
{
var a = this.getIndex(child);
var b = this.getAt(a - 1);
if (b)
{
2014-04-10 22:13:43 +00:00
this.swap(child, b);
}
}
return child;
};
/**
2014-12-03 10:39:11 +00:00
* Positions the child found at the given index within this group to the given x and y coordinates.
*
* @method Phaser.Group#xy
2014-12-03 10:39:11 +00:00
* @param {integer} index - The index of the child in the group to set the position of.
* @param {number} x - The new x position of the child.
* @param {number} y - The new y position of the child.
*/
Phaser.Group.prototype.xy = function (index, x, y) {
if (index &lt; 0 || index > this.children.length)
{
return -1;
}
else
{
this.getChildAt(index).x = x;
this.getChildAt(index).y = y;
}
};
/**
2014-12-03 10:39:11 +00:00
* Reverses all children in this group.
*
* This operaation applies only to immediate children and does not propagate to subgroups.
*
* @method Phaser.Group#reverse
*/
Phaser.Group.prototype.reverse = function () {
this.children.reverse();
this.updateZ();
};
/**
2014-12-03 10:39:11 +00:00
* Get the index position of the given child in this group, which should match the child's `z` property.
*
* @method Phaser.Group#getIndex
2014-12-03 10:39:11 +00:00
* @param {any} child - The child to get the index for.
* @return {integer} The index of the child or -1 if it's not a member of this group.
*/
Phaser.Group.prototype.getIndex = function (child) {
2013-11-28 15:57:09 +00:00
return this.children.indexOf(child);
2013-11-28 15:57:09 +00:00
};
2013-11-01 18:16:52 +00:00
/**
2014-12-03 10:39:11 +00:00
* Replaces a child of this group with the given newChild. The newChild cannot be a member of this group.
*
* @method Phaser.Group#replace
2014-12-03 10:39:11 +00:00
* @param {any} oldChild - The child in this group that will be replaced.
* @param {any} newChild - The child to be inserted into this group.
* @return {any} Returns the oldChild that was replaced within this group.
*/
Phaser.Group.prototype.replace = function (oldChild, newChild) {
2013-11-28 15:57:09 +00:00
var index = this.getIndex(oldChild);
if (index !== -1)
{
2015-01-06 06:57:25 +00:00
if (newChild.parent)
2013-11-28 15:57:09 +00:00
{
if (newChild.parent instanceof Phaser.Group)
{
2015-01-06 06:57:25 +00:00
newChild.parent.remove(newChild);
}
else
{
newChild.parent.removeChild(newChild);
}
2013-11-28 15:57:09 +00:00
}
2015-01-06 06:57:25 +00:00
this.remove(oldChild);
this.addAt(newChild, index);
2014-03-24 12:41:45 +00:00
2015-01-06 06:57:25 +00:00
return oldChild;
}
};
/**
2014-12-03 10:39:11 +00:00
* Checks if the child has the given property.
*
* Will scan up to 4 levels deep only.
2014-05-20 09:12:48 +00:00
*
* @method Phaser.Group#hasProperty
2014-12-03 10:39:11 +00:00
* @param {any} child - The child to check for the existance of the property on.
* @param {string[]} key - An array of strings that make up the property.
2014-05-20 09:12:48 +00:00
* @return {boolean} True if the child has the property, otherwise false.
*/
Phaser.Group.prototype.hasProperty = function (child, key) {
var len = key.length;
2015-03-23 23:46:30 +00:00
if (len === 1 &amp;&amp; key[0] in child)
2014-05-20 09:12:48 +00:00
{
return true;
}
2015-03-23 23:46:30 +00:00
else if (len === 2 &amp;&amp; key[0] in child &amp;&amp; key[1] in child[key[0]])
2014-05-20 09:12:48 +00:00
{
return true;
}
2015-03-23 23:46:30 +00:00
else if (len === 3 &amp;&amp; key[0] in child &amp;&amp; key[1] in child[key[0]] &amp;&amp; key[2] in child[key[0]][key[1]])
2014-05-20 09:12:48 +00:00
{
return true;
}
2015-03-23 23:46:30 +00:00
else if (len === 4 &amp;&amp; key[0] in child &amp;&amp; key[1] in child[key[0]] &amp;&amp; key[2] in child[key[0]][key[1]] &amp;&amp; key[3] in child[key[0]][key[1]][key[2]])
2014-05-20 09:12:48 +00:00
{
return true;
}
return false;
};
/**
* Sets a property to the given value on the child. The operation parameter controls how the value is set.
2014-12-03 10:39:11 +00:00
*
* The operations are:
* - 0: set the existing value to the given value; if force is `true` a new property will be created if needed
* - 1: will add the given value to the value already present.
* - 2: will subtract the given value from the value already present.
* - 3: will multiply the value already present by the given value.
* - 4: will divide the value already present by the given value.
*
* @method Phaser.Group#setProperty
2014-12-03 10:39:11 +00:00
* @param {any} child - The child to set the property value on.
* @param {array} key - An array of strings that make up the property that will be set.
2014-12-03 10:39:11 +00:00
* @param {any} value - The value that will be set.
* @param {integer} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
2014-05-20 09:12:48 +00:00
* @param {boolean} [force=false] - If `force` is true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set.
* @return {boolean} True if the property was set, false if not.
*/
2014-05-20 09:12:48 +00:00
Phaser.Group.prototype.setProperty = function (child, key, value, operation, force) {
2015-07-22 14:31:30 +00:00
if (force === undefined) { force = false; }
operation = operation || 0;
2014-04-29 14:39:02 +00:00
// As ugly as this approach looks, and although it's limited to a depth of only 4, it's much faster than a for loop or object iteration.
// 0 = Equals
// 1 = Add
// 2 = Subtract
// 3 = Multiply
// 4 = Divide
2014-05-20 09:12:48 +00:00
// We can't force a property in and the child doesn't have it, so abort.
// Equally we can't add, subtract, multiply or divide a property value if it doesn't exist, so abort in those cases too.
2015-03-23 23:46:30 +00:00
if (!this.hasProperty(child, key) &amp;&amp; (!force || operation > 0))
2014-05-20 09:12:48 +00:00
{
return false;
}
var len = key.length;
2014-05-20 09:12:48 +00:00
if (len === 1)
{
if (operation === 0) { child[key[0]] = value; }
else if (operation == 1) { child[key[0]] += value; }
else if (operation == 2) { child[key[0]] -= value; }
else if (operation == 3) { child[key[0]] *= value; }
else if (operation == 4) { child[key[0]] /= value; }
}
2014-05-20 09:12:48 +00:00
else if (len === 2)
{
if (operation === 0) { child[key[0]][key[1]] = value; }
else if (operation == 1) { child[key[0]][key[1]] += value; }
else if (operation == 2) { child[key[0]][key[1]] -= value; }
else if (operation == 3) { child[key[0]][key[1]] *= value; }
else if (operation == 4) { child[key[0]][key[1]] /= value; }
}
2014-05-20 09:12:48 +00:00
else if (len === 3)
{
if (operation === 0) { child[key[0]][key[1]][key[2]] = value; }
else if (operation == 1) { child[key[0]][key[1]][key[2]] += value; }
else if (operation == 2) { child[key[0]][key[1]][key[2]] -= value; }
else if (operation == 3) { child[key[0]][key[1]][key[2]] *= value; }
else if (operation == 4) { child[key[0]][key[1]][key[2]] /= value; }
}
2014-05-20 09:12:48 +00:00
else if (len === 4)
{
if (operation === 0) { child[key[0]][key[1]][key[2]][key[3]] = value; }
else if (operation == 1) { child[key[0]][key[1]][key[2]][key[3]] += value; }
else if (operation == 2) { child[key[0]][key[1]][key[2]][key[3]] -= value; }
else if (operation == 3) { child[key[0]][key[1]][key[2]][key[3]] *= value; }
else if (operation == 4) { child[key[0]][key[1]][key[2]][key[3]] /= value; }
}
2014-05-20 09:12:48 +00:00
return true;
};
2013-11-28 15:57:09 +00:00
2014-07-18 11:45:51 +00:00
/**
* Checks a property for the given value on the child.
*
* @method Phaser.Group#checkProperty
2014-12-03 10:39:11 +00:00
* @param {any} child - The child to check the property value on.
2014-07-18 11:45:51 +00:00
* @param {array} key - An array of strings that make up the property that will be set.
2014-12-03 10:39:11 +00:00
* @param {any} value - The value that will be checked.
2014-07-18 11:45:51 +00:00
* @param {boolean} [force=false] - If `force` is true then the property will be checked on the child regardless if it already exists or not. If true and the property doesn't exist, false will be returned.
* @return {boolean} True if the property was was equal to value, false if not.
*/
Phaser.Group.prototype.checkProperty = function (child, key, value, force) {
2015-07-22 14:31:30 +00:00
if (force === undefined) { force = false; }
2014-07-18 11:45:51 +00:00
// We can't force a property in and the child doesn't have it, so abort.
2015-03-23 23:46:30 +00:00
if (!Phaser.Utils.getProperty(child, key) &amp;&amp; force)
2014-07-18 11:45:51 +00:00
{
return false;
}
2014-10-09 15:12:53 +00:00
2014-07-18 11:45:51 +00:00
if (Phaser.Utils.getProperty(child, key) !== value)
{
return false;
}
return true;
};
/**
2014-12-03 10:39:11 +00:00
* Quickly set a property on a single child of this group to a new value.
*
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
*
* @method Phaser.Group#set
* @param {Phaser.Sprite} child - The child to set the property on.
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
2014-12-03 10:39:11 +00:00
* @param {any} value - The value that will be set.
* @param {boolean} [checkAlive=false] - If set then the child will only be updated if alive=true.
* @param {boolean} [checkVisible=false] - If set then the child will only be updated if visible=true.
2014-12-03 10:39:11 +00:00
* @param {integer} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
2014-05-20 09:12:48 +00:00
* @param {boolean} [force=false] - If `force` is true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set.
* @return {boolean} True if the property was set, false if not.
*/
2014-05-20 09:12:48 +00:00
Phaser.Group.prototype.set = function (child, key, value, checkAlive, checkVisible, operation, force) {
2015-07-22 14:31:30 +00:00
if (force === undefined) { force = false; }
2013-11-28 15:57:09 +00:00
key = key.split('.');
2013-11-28 15:57:09 +00:00
2015-07-22 14:31:30 +00:00
if (checkAlive === undefined) { checkAlive = false; }
if (checkVisible === undefined) { checkVisible = false; }
2013-11-28 15:57:09 +00:00
2015-03-23 23:46:30 +00:00
if ((checkAlive === false || (checkAlive &amp;&amp; child.alive)) &amp;&amp; (checkVisible === false || (checkVisible &amp;&amp; child.visible)))
{
2014-05-20 09:12:48 +00:00
return this.setProperty(child, key, value, operation, force);
}
2013-11-28 15:57:09 +00:00
};
2013-11-28 15:57:09 +00:00
/**
2014-12-03 10:39:11 +00:00
* Quickly set the same property across all children of this group to a new value.
*
* This call doesn't descend down children, so if you have a Group inside of this group, the property will be set on the group but not its children.
2014-03-24 12:41:45 +00:00
* If you need that ability please see `Group.setAllChildren`.
*
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
*
* @method Phaser.Group#setAll
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
2014-12-03 10:39:11 +00:00
* @param {any} value - The value that will be set.
2014-03-24 12:41:45 +00:00
* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be updated. This includes any Groups that are children.
* @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated. This includes any Groups that are children.
2014-12-03 10:39:11 +00:00
* @param {integer} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
2014-05-20 09:12:48 +00:00
* @param {boolean} [force=false] - If `force` is true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set.
*/
2014-05-20 09:12:48 +00:00
Phaser.Group.prototype.setAll = function (key, value, checkAlive, checkVisible, operation, force) {
2013-11-28 15:57:09 +00:00
2015-07-22 14:31:30 +00:00
if (checkAlive === undefined) { checkAlive = false; }
if (checkVisible === undefined) { checkVisible = false; }
if (force === undefined) { force = false; }
2013-11-28 15:57:09 +00:00
2014-05-20 09:12:48 +00:00
key = key.split('.');
operation = operation || 0;
2013-11-28 15:57:09 +00:00
2015-03-23 23:46:30 +00:00
for (var i = 0; i &lt; this.children.length; i++)
{
2015-03-23 23:46:30 +00:00
if ((!checkAlive || (checkAlive &amp;&amp; this.children[i].alive)) &amp;&amp; (!checkVisible || (checkVisible &amp;&amp; this.children[i].visible)))
2013-11-28 15:57:09 +00:00
{
2014-05-20 09:12:48 +00:00
this.setProperty(this.children[i], key, value, operation, force);
}
}
2013-11-28 15:57:09 +00:00
};
2013-11-28 15:57:09 +00:00
2014-03-24 12:41:45 +00:00
/**
2014-12-03 10:39:11 +00:00
* Quickly set the same property across all children of this group, and any child Groups, to a new value.
2014-03-24 12:41:45 +00:00
*
2014-12-03 10:39:11 +00:00
* If this group contains other Groups then the same property is set across their children as well, iterating down until it reaches the bottom.
* Unlike with `setAll` the property is NOT set on child Groups itself.
2014-03-24 12:41:45 +00:00
*
* The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication.
*
* @method Phaser.Group#setAllChildren
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
2014-12-03 10:39:11 +00:00
* @param {any} value - The value that will be set.
2014-03-24 12:41:45 +00:00
* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be updated. This includes any Groups that are children.
* @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated. This includes any Groups that are children.
2014-12-03 10:39:11 +00:00
* @param {integer} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it.
2014-05-20 09:12:48 +00:00
* @param {boolean} [force=false] - If `force` is true then the property will be set on the child regardless if it already exists or not. If false and the property doesn't exist, nothing will be set.
2014-03-24 12:41:45 +00:00
*/
2014-05-20 09:12:48 +00:00
Phaser.Group.prototype.setAllChildren = function (key, value, checkAlive, checkVisible, operation, force) {
2014-03-24 12:41:45 +00:00
2015-07-22 14:31:30 +00:00
if (checkAlive === undefined) { checkAlive = false; }
if (checkVisible === undefined) { checkVisible = false; }
if (force === undefined) { force = false; }
2014-03-24 12:41:45 +00:00
operation = operation || 0;
2015-03-23 23:46:30 +00:00
for (var i = 0; i &lt; this.children.length; i++)
2014-03-24 12:41:45 +00:00
{
2015-03-23 23:46:30 +00:00
if ((!checkAlive || (checkAlive &amp;&amp; this.children[i].alive)) &amp;&amp; (!checkVisible || (checkVisible &amp;&amp; this.children[i].visible)))
2014-03-24 12:41:45 +00:00
{
if (this.children[i] instanceof Phaser.Group)
{
2014-05-20 09:12:48 +00:00
this.children[i].setAllChildren(key, value, checkAlive, checkVisible, operation, force);
2014-03-24 12:41:45 +00:00
}
else
{
2014-05-20 09:12:48 +00:00
this.setProperty(this.children[i], key.split('.'), value, operation, force);
2014-03-24 12:41:45 +00:00
}
}
}
};
2014-03-24 12:41:45 +00:00
2014-07-18 11:45:51 +00:00
/**
2014-12-03 10:39:11 +00:00
* Quickly check that the same property across all children of this group is equal to the given value.
*
* This call doesn't descend down children, so if you have a Group inside of this group, the property will be checked on the group but not its children.
2014-07-18 11:45:51 +00:00
*
* @method Phaser.Group#checkAll
* @param {string} key - The property, as a string, to be set. For example: 'body.velocity.x'
2014-12-03 10:39:11 +00:00
* @param {any} value - The value that will be checked.
2014-07-18 11:45:51 +00:00
* @param {boolean} [checkAlive=false] - If set then only children with alive=true will be checked. This includes any Groups that are children.
* @param {boolean} [checkVisible=false] - If set then only children with visible=true will be checked. This includes any Groups that are children.
* @param {boolean} [force=false] - If `force` is true then the property will be checked on the child regardless if it already exists or not. If true and the property doesn't exist, false will be returned.
*/
Phaser.Group.prototype.checkAll = function (key, value, checkAlive, checkVisible, force) {
2015-07-22 14:31:30 +00:00
if (checkAlive === undefined) { checkAlive = false; }
if (checkVisible === undefined) { checkVisible = false; }
if (force === undefined) { force = false; }
2014-07-18 11:45:51 +00:00
2015-03-23 23:46:30 +00:00
for (var i = 0; i &lt; this.children.length; i++)
2014-07-18 11:45:51 +00:00
{
2015-03-23 23:46:30 +00:00
if ((!checkAlive || (checkAlive &amp;&amp; this.children[i].alive)) &amp;&amp; (!checkVisible || (checkVisible &amp;&amp; this.children[i].visible)))
2014-07-18 11:45:51 +00:00
{
if (!this.checkProperty(this.children[i], key, value, force))
{
return false;
}
}
}
return true;
};
/**
2014-12-03 10:39:11 +00:00
* Adds the amount to the given property on all children in this group.
*
* `Group.addAll('x', 10)` will add 10 to the child.x value for each child.
*
* @method Phaser.Group#addAll
* @param {string} property - The property to increment, for example 'body.velocity.x' or 'angle'.
* @param {number} amount - The amount to increment the property by. If child.x = 10 then addAll('x', 40) would make child.x = 50.
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
*/
Phaser.Group.prototype.addAll = function (property, amount, checkAlive, checkVisible) {
2013-11-28 15:57:09 +00:00
this.setAll(property, amount, checkAlive, checkVisible, 1);
2013-11-28 15:57:09 +00:00
};
2013-11-28 15:57:09 +00:00
/**
2014-12-03 10:39:11 +00:00
* Subtracts the amount from the given property on all children in this group.
*
* `Group.subAll('x', 10)` will minus 10 from the child.x value for each child.
*
* @method Phaser.Group#subAll
* @param {string} property - The property to decrement, for example 'body.velocity.x' or 'angle'.
* @param {number} amount - The amount to subtract from the property. If child.x = 50 then subAll('x', 40) would make child.x = 10.
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
*/
Phaser.Group.prototype.subAll = function (property, amount, checkAlive, checkVisible) {
2013-11-28 15:57:09 +00:00
this.setAll(property, amount, checkAlive, checkVisible, 2);
2013-11-28 15:57:09 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Multiplies the given property by the amount on all children in this group.
*
* `Group.multiplyAll('x', 2)` will x2 the child.x value for each child.
*
* @method Phaser.Group#multiplyAll
* @param {string} property - The property to multiply, for example 'body.velocity.x' or 'angle'.
* @param {number} amount - The amount to multiply the property by. If child.x = 10 then multiplyAll('x', 2) would make child.x = 20.
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
*/
Phaser.Group.prototype.multiplyAll = function (property, amount, checkAlive, checkVisible) {
2013-10-02 00:16:40 +00:00
this.setAll(property, amount, checkAlive, checkVisible, 3);
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Divides the given property by the amount on all children in this group.
*
* `Group.divideAll('x', 2)` will half the child.x value for each child.
*
* @method Phaser.Group#divideAll
* @param {string} property - The property to divide, for example 'body.velocity.x' or 'angle'.
* @param {number} amount - The amount to divide the property by. If child.x = 100 then divideAll('x', 2) would make child.x = 50.
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
*/
Phaser.Group.prototype.divideAll = function (property, amount, checkAlive, checkVisible) {
2013-10-02 00:16:40 +00:00
this.setAll(property, amount, checkAlive, checkVisible, 4);
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Calls a function, specified by name, on all children in the group who exist (or do not exist).
*
* After the existsValue parameter you can add as many parameters as you like, which will all be passed to the child callback.
*
* @method Phaser.Group#callAllExists
2014-12-03 10:39:11 +00:00
* @param {string} callback - Name of the function on the children to call.
* @param {boolean} existsValue - Only children with exists=existsValue will be called.
2014-12-03 10:39:11 +00:00
* @param {...any} parameter - Additional parameters that will be passed to the callback.
*/
Phaser.Group.prototype.callAllExists = function (callback, existsValue) {
2013-10-02 00:16:40 +00:00
2014-11-25 00:23:44 +00:00
var args;
2015-03-23 23:46:30 +00:00
2014-11-25 00:23:44 +00:00
if (arguments.length > 2)
{
args = [];
2015-03-23 23:46:30 +00:00
for (var i = 2; i &lt; arguments.length; i++)
{
args.push(arguments[i]);
}
2014-11-25 00:23:44 +00:00
}
2013-11-28 15:57:09 +00:00
2015-03-23 23:46:30 +00:00
for (var i = 0; i &lt; this.children.length; i++)
{
2015-03-23 23:46:30 +00:00
if (this.children[i].exists === existsValue &amp;&amp; this.children[i][callback])
2013-11-28 15:57:09 +00:00
{
this.children[i][callback].apply(this.children[i], args);
2013-11-28 15:57:09 +00:00
}
}
2013-10-02 00:16:40 +00:00
};
2013-11-28 15:57:09 +00:00
/**
2014-12-03 10:39:11 +00:00
* Returns a reference to a function that exists on a child of the group based on the given callback array.
*
* @method Phaser.Group#callbackFromArray
* @param {object} child - The object to inspect.
* @param {array} callback - The array of function names.
2014-12-03 10:39:11 +00:00
* @param {integer} length - The size of the array (pre-calculated in callAll).
* @protected
*/
Phaser.Group.prototype.callbackFromArray = function (child, callback, length) {
2013-11-28 15:57:09 +00:00
// Kinda looks like a Christmas tree
2013-11-28 15:57:09 +00:00
if (length == 1)
{
if (child[callback[0]])
2013-11-28 15:57:09 +00:00
{
return child[callback[0]];
2013-11-28 15:57:09 +00:00
}
}
else if (length == 2)
{
if (child[callback[0]][callback[1]])
2013-11-28 15:57:09 +00:00
{
return child[callback[0]][callback[1]];
2013-11-28 15:57:09 +00:00
}
}
else if (length == 3)
{
if (child[callback[0]][callback[1]][callback[2]])
2013-11-28 15:57:09 +00:00
{
return child[callback[0]][callback[1]][callback[2]];
2013-11-28 15:57:09 +00:00
}
}
else if (length == 4)
{
if (child[callback[0]][callback[1]][callback[2]][callback[3]])
2014-02-05 06:29:17 +00:00
{
return child[callback[0]][callback[1]][callback[2]][callback[3]];
2014-02-05 06:29:17 +00:00
}
}
else
{
if (child[callback])
2013-11-28 15:57:09 +00:00
{
return child[callback];
2013-11-28 15:57:09 +00:00
}
}
2013-11-28 15:57:09 +00:00
return false;
2013-11-28 15:57:09 +00:00
};
2013-11-28 15:57:09 +00:00
/**
2014-12-03 10:39:11 +00:00
* Calls a function, specified by name, on all on children.
*
* The function is called for all children regardless if they are dead or alive (see callAllExists for different options).
* After the method parameter and context you can add as many extra parameters as you like, which will all be passed to the child.
*
* @method Phaser.Group#callAll
2014-12-03 10:39:11 +00:00
* @param {string} method - Name of the function on the child to call. Deep property lookup is supported.
* @param {string} [context=null] - A string containing the context under which the method will be executed. Set to null to default to the child.
2014-12-03 10:39:11 +00:00
* @param {...any} args - Additional parameters that will be passed to the method.
*/
Phaser.Group.prototype.callAll = function (method, context) {
2013-11-28 15:57:09 +00:00
2015-07-22 14:31:30 +00:00
if (method === undefined)
{
return;
}
2013-11-28 15:57:09 +00:00
// Extract the method into an array
method = method.split('.');
2013-10-02 00:16:40 +00:00
var methodLength = method.length;
2013-10-02 00:16:40 +00:00
2015-07-22 14:31:30 +00:00
if (context === undefined || context === null || context === '')
{
context = null;
}
else
{
// Extract the context into an array
if (typeof context === 'string')
2013-11-28 15:57:09 +00:00
{
context = context.split('.');
var contextLength = context.length;
2013-11-28 15:57:09 +00:00
}
}
2013-10-02 00:16:40 +00:00
2014-11-25 00:23:44 +00:00
var args;
2015-03-23 23:46:30 +00:00
2014-11-25 00:23:44 +00:00
if (arguments.length > 2)
{
args = [];
2015-03-23 23:46:30 +00:00
for (var i = 2; i &lt; arguments.length; i++)
{
args.push(arguments[i]);
}
2014-11-25 00:23:44 +00:00
}
var callback = null;
var callbackContext = null;
2013-11-28 15:57:09 +00:00
2015-03-23 23:46:30 +00:00
for (var i = 0; i &lt; this.children.length; i++)
{
callback = this.callbackFromArray(this.children[i], method, methodLength);
2013-11-28 15:57:09 +00:00
2015-03-23 23:46:30 +00:00
if (context &amp;&amp; callback)
2013-11-28 15:57:09 +00:00
{
callbackContext = this.callbackFromArray(this.children[i], context, contextLength);
if (callback)
2013-11-28 15:57:09 +00:00
{
callback.apply(callbackContext, args);
2013-11-28 15:57:09 +00:00
}
}
else if (callback)
2013-11-28 15:57:09 +00:00
{
callback.apply(this.children[i], args);
2013-11-28 15:57:09 +00:00
}
}
2013-11-28 15:57:09 +00:00
};
2013-11-28 15:57:09 +00:00
/**
* The core preUpdate - as called by World.
* @method Phaser.Group#preUpdate
* @protected
*/
Phaser.Group.prototype.preUpdate = function () {
2015-07-22 14:31:30 +00:00
if (this.pendingDestroy)
{
this.destroy();
return false;
}
if (!this.exists || !this.parent.exists)
{
this.renderOrderID = -1;
return false;
}
var i = this.children.length;
while (i--)
{
this.children[i].preUpdate();
}
return true;
};
/**
* The core update - as called by World.
* @method Phaser.Group#update
* @protected
*/
Phaser.Group.prototype.update = function () {
var i = this.children.length;
while (i--)
{
this.children[i].update();
}
};
/**
* The core postUpdate - as called by World.
* @method Phaser.Group#postUpdate
* @protected
*/
Phaser.Group.prototype.postUpdate = function () {
// Fixed to Camera?
2015-03-23 23:46:30 +00:00
if (this.fixedToCamera)
{
this.x = this.game.camera.view.x + this.cameraOffset.x;
this.y = this.game.camera.view.y + this.cameraOffset.y;
}
var i = this.children.length;
while (i--)
{
this.children[i].postUpdate();
}
};
2014-10-09 15:12:53 +00:00
/**
2014-12-03 10:39:11 +00:00
* Find children matching a certain predicate.
*
2014-10-09 15:12:53 +00:00
* For example:
2014-11-25 00:23:44 +00:00
*
2014-10-09 15:12:53 +00:00
* var healthyList = Group.filter(function(child, index, children) {
* return child.health > 10 ? true : false;
* }, true);
* healthyList.callAll('attack');
2014-11-25 00:23:44 +00:00
*
2014-10-09 15:12:53 +00:00
* Note: Currently this will skip any children which are Groups themselves.
2014-11-25 00:23:44 +00:00
*
2014-10-09 15:12:53 +00:00
* @method Phaser.Group#filter
2014-12-03 10:39:11 +00:00
* @param {function} predicate - The function that each child will be evaluated against. Each child of the group will be passed to it as its first parameter, the index as the second, and the entire child array as the third
* @param {boolean} [checkExists=false] - If true, only existing can be selected; otherwise all children can be selected and will be passed to the predicate.
2014-11-25 00:23:44 +00:00
* @return {Phaser.ArraySet} Returns an array list containing all the children that the predicate returned true for
2014-10-09 15:12:53 +00:00
*/
2014-11-25 00:23:44 +00:00
Phaser.Group.prototype.filter = function (predicate, checkExists) {
2014-10-09 15:12:53 +00:00
2014-11-25 00:23:44 +00:00
var index = -1;
var length = this.children.length;
var results = [];
while (++index &lt; length)
{
2014-10-09 15:12:53 +00:00
var child = this.children[index];
2014-11-25 00:23:44 +00:00
2015-03-23 23:46:30 +00:00
if (!checkExists || (checkExists &amp;&amp; child.exists))
2014-11-25 00:23:44 +00:00
{
if (predicate(child, index, this.children))
{
results.push(child);
2014-10-09 15:12:53 +00:00
}
}
}
2014-11-25 00:23:44 +00:00
return new Phaser.ArraySet(results);
2014-10-09 15:12:53 +00:00
};
/**
2014-12-03 10:39:11 +00:00
* Call a function on each child in this group.
*
* Additional arguments for the callback can be specified after the `checkExists` parameter. For example,
*
* Group.forEach(awardBonusGold, this, true, 100, 500)
*
2015-03-23 23:46:30 +00:00
* would invoke `awardBonusGold` function with the parameters `(child, 100, 500)`.
2014-12-03 10:39:11 +00:00
*
2015-03-23 23:46:30 +00:00
* Note: This check will skip any children which are Groups themselves.
*
* @method Phaser.Group#forEach
2014-12-03 10:39:11 +00:00
* @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 {boolean} [checkExists=false] - If set only children matching for which `exists` is true will be passed to the callback, otherwise all children will be passed.
* @param {...any} [args=(none)] - Additional arguments to pass to the callback function, after the child item.
*/
Phaser.Group.prototype.forEach = function (callback, callbackContext, checkExists) {
2013-11-28 15:57:09 +00:00
2015-07-22 14:31:30 +00:00
if (checkExists === undefined) { checkExists = false; }
2013-11-28 15:57:09 +00:00
2014-11-25 00:23:44 +00:00
if (arguments.length &lt;= 3)
{
2015-03-23 23:46:30 +00:00
for (var i = 0; i &lt; this.children.length; i++)
2013-11-28 15:57:09 +00:00
{
2015-03-23 23:46:30 +00:00
if (!checkExists || (checkExists &amp;&amp; this.children[i].exists))
2014-11-25 00:23:44 +00:00
{
callback.call(callbackContext, this.children[i]);
}
}
}
else
{
// Assigning to arguments properties causes Extreme Deoptimization in Chrome, FF, and IE.
// Using an array and pushing each element (not a slice!) is _significantly_ faster.
var args = [null];
2015-03-23 23:46:30 +00:00
2015-07-22 14:31:30 +00:00
for (var i = 3; i &lt; arguments.length; i++)
{
args.push(arguments[i]);
}
2014-11-25 00:23:44 +00:00
2015-03-23 23:46:30 +00:00
for (var i = 0; i &lt; this.children.length; i++)
2014-11-25 00:23:44 +00:00
{
2015-03-23 23:46:30 +00:00
if (!checkExists || (checkExists &amp;&amp; this.children[i].exists))
2014-11-25 00:23:44 +00:00
{
args[0] = this.children[i];
callback.apply(callbackContext, args);
}
2013-11-28 15:57:09 +00:00
}
}
2013-11-28 15:57:09 +00:00
};
2013-11-01 18:16:52 +00:00
/**
2014-12-03 10:39:11 +00:00
* Call a function on each existing child in this group.
*
* See {@link Phaser.Group#forEach forEach} for details.
*
* @method Phaser.Group#forEachExists
2014-12-03 10:39:11 +00:00
* @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.
*/
Phaser.Group.prototype.forEachExists = function (callback, callbackContext) {
2013-11-28 15:57:09 +00:00
2014-11-25 00:23:44 +00:00
var args;
2015-03-23 23:46:30 +00:00
2014-11-25 00:23:44 +00:00
if (arguments.length > 2)
{
args = [null];
2015-03-23 23:46:30 +00:00
for (var i = 2; i &lt; arguments.length; i++)
{
args.push(arguments[i]);
}
2014-11-25 00:23:44 +00:00
}
2013-11-28 15:57:09 +00:00
this.iterate('exists', true, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args);
2013-11-28 15:57:09 +00:00
};
2013-11-28 15:57:09 +00:00
/**
2014-12-03 10:39:11 +00:00
* Call a function on each alive child in this group.
*
* See {@link Phaser.Group#forEach forEach} for details.
*
* @method Phaser.Group#forEachAlive
2014-12-03 10:39:11 +00:00
* @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.
*/
Phaser.Group.prototype.forEachAlive = function (callback, callbackContext) {
2013-11-28 15:57:09 +00:00
2014-11-25 00:23:44 +00:00
var args;
2015-03-23 23:46:30 +00:00
2014-11-25 00:23:44 +00:00
if (arguments.length > 2)
{
args = [null];
2015-03-23 23:46:30 +00:00
for (var i = 2; i &lt; arguments.length; i++)
{
args.push(arguments[i]);
}
2014-11-25 00:23:44 +00:00
}
2013-11-28 15:57:09 +00:00
this.iterate('alive', true, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args);
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Call a function on each dead child in this group.
*
* See {@link Phaser.Group#forEach forEach} for details.
*
* @method Phaser.Group#forEachDead
2014-12-03 10:39:11 +00:00
* @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.
*/
Phaser.Group.prototype.forEachDead = function (callback, callbackContext) {
2013-10-02 00:16:40 +00:00
2014-11-25 00:23:44 +00:00
var args;
2015-03-23 23:46:30 +00:00
2014-11-25 00:23:44 +00:00
if (arguments.length > 2)
{
args = [null];
2015-03-23 23:46:30 +00:00
for (var i = 2; i &lt; arguments.length; i++)
{
args.push(arguments[i]);
}
2014-11-25 00:23:44 +00:00
}
2013-10-02 00:16:40 +00:00
this.iterate('alive', false, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args);
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Sort the children in the group according to a particular key and ordering.
*
* Call this function to sort the group according to a particular key value and order.
* For example to depth sort Sprites for Zelda-style game you might call `group.sort('y', Phaser.Group.SORT_ASCENDING)` at the bottom of your `State.update()`.
*
* @method Phaser.Group#sort
2014-12-03 10:39:11 +00:00
* @param {string} [key='z'] - The name of the property to sort on. Defaults to the objects z-depth value.
* @param {integer} [order=Phaser.Group.SORT_ASCENDING] - Order ascending ({@link Phaser.Group.SORT_ASCENDING SORT_ASCENDING}) or descending ({@link Phaser.Group.SORT_DESCENDING SORT_DESCENDING}).
*/
2014-12-03 10:39:11 +00:00
Phaser.Group.prototype.sort = function (key, order) {
if (this.children.length &lt; 2)
{
// Nothing to swap
return;
}
2015-07-22 14:31:30 +00:00
if (key === undefined) { key = 'z'; }
if (order === undefined) { order = Phaser.Group.SORT_ASCENDING; }
2014-12-03 10:39:11 +00:00
this._sortProperty = key;
if (order === Phaser.Group.SORT_ASCENDING)
{
this.children.sort(this.ascendingSortHandler.bind(this));
}
else
{
this.children.sort(this.descendingSortHandler.bind(this));
}
this.updateZ();
};
2014-04-10 22:13:43 +00:00
/**
2014-12-03 10:39:11 +00:00
* Sort the children in the group according to custom sort function.
*
* The `sortHandler` is provided the two parameters: the two children involved in the comparison (a and b).
* It should return -1 if `a > b`, 1 if `a &lt; b` or 0 if `a === b`.
2014-04-10 22:13:43 +00:00
*
* @method Phaser.Group#customSort
2014-12-03 10:39:11 +00:00
* @param {function} sortHandler - The custom sort function.
* @param {object} [context=undefined] - The context in which the sortHandler is called.
2014-04-10 22:13:43 +00:00
*/
Phaser.Group.prototype.customSort = function (sortHandler, context) {
if (this.children.length &lt; 2)
{
// Nothing to swap
return;
}
this.children.sort(sortHandler.bind(context));
this.updateZ();
};
/**
* An internal helper function for the sort process.
*
* @method Phaser.Group#ascendingSortHandler
2014-12-03 10:39:11 +00:00
* @protected
* @param {object} a - The first object being sorted.
* @param {object} b - The second object being sorted.
*/
Phaser.Group.prototype.ascendingSortHandler = function (a, b) {
if (a[this._sortProperty] &lt; b[this._sortProperty])
{
return -1;
}
else if (a[this._sortProperty] > b[this._sortProperty])
{
return 1;
}
else
{
if (a.z &lt; b.z)
{
return -1;
}
else
{
return 1;
}
}
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
* An internal helper function for the sort process.
*
* @method Phaser.Group#descendingSortHandler
2014-12-03 10:39:11 +00:00
* @protected
* @param {object} a - The first object being sorted.
* @param {object} b - The second object being sorted.
*/
Phaser.Group.prototype.descendingSortHandler = function (a, b) {
if (a[this._sortProperty] &lt; b[this._sortProperty])
{
return 1;
}
else if (a[this._sortProperty] > b[this._sortProperty])
{
return -1;
}
else
{
return 0;
}
};
/**
2014-12-03 10:39:11 +00:00
* Iterates over the children of the group performing one of several actions for matched children.
*
* A child is considered a match when it has a property, named `key`, whose value is equal to `value`
* according to a strict equality comparison.
*
* The result depends on the `returnType`:
*
* - {@link Phaser.Group.RETURN_TOTAL RETURN_TOTAL}:
* The callback, if any, is applied to all matching children. The number of matched children is returned.
* - {@link Phaser.Group.RETURN_NONE RETURN_NONE}:
* The callback, if any, is applied to all matching children. No value is returned.
* - {@link Phaser.Group.RETURN_CHILD RETURN_CHILD}:
* The callback, if any, is applied to the *first* matching child and the *first* matched child is returned.
* If there is no matching child then null is returned.
*
* If `args` is specified it must be an array. The matched child will be assigned to the first
* element and the entire array will be applied to the callback function.
*
* @method Phaser.Group#iterate
* @param {string} key - The child property to check, i.e. 'exists', 'alive', 'health'
2014-12-03 10:39:11 +00:00
* @param {any} value - A child matches if `child[key] === value` is true.
2015-03-23 23:46:30 +00:00
* @param {integer} returnType - How to iterate the children and what to return.
2014-12-03 10:39:11 +00:00
* @param {function} [callback=null] - Optional function that will be called on each matching child. The matched child is supplied as the first argument.
* @param {object} [callbackContext] - The context in which the function should be called (usually 'this').
* @param {any[]} [args=(none)] - The arguments supplied to to the callback; the first array index (argument) will be replaced with the matched child.
* @return {any} Returns either an integer (for RETURN_TOTAL), the first matched child (for RETURN_CHILD), or null.
*/
Phaser.Group.prototype.iterate = function (key, value, returnType, callback, callbackContext, args) {
2013-11-28 15:57:09 +00:00
2015-03-23 23:46:30 +00:00
if (returnType === Phaser.Group.RETURN_TOTAL &amp;&amp; this.children.length === 0)
{
return 0;
}
2013-11-28 15:57:09 +00:00
var total = 0;
2013-11-28 15:57:09 +00:00
2015-03-23 23:46:30 +00:00
for (var i = 0; i &lt; this.children.length; i++)
{
if (this.children[i][key] === value)
{
total++;
2013-11-28 15:57:09 +00:00
if (callback)
2013-11-28 15:57:09 +00:00
{
2014-11-25 00:23:44 +00:00
if (args)
{
args[0] = this.children[i];
callback.apply(callbackContext, args);
}
else
{
callback.call(callbackContext, this.children[i]);
}
2013-11-28 15:57:09 +00:00
}
if (returnType === Phaser.Group.RETURN_CHILD)
2013-11-28 15:57:09 +00:00
{
return this.children[i];
2013-11-28 15:57:09 +00:00
}
}
}
2013-11-28 15:57:09 +00:00
if (returnType === Phaser.Group.RETURN_TOTAL)
{
return total;
}
2014-11-25 00:23:44 +00:00
// RETURN_CHILD or RETURN_NONE
return null;
2013-11-28 15:57:09 +00:00
};
2013-11-28 15:57:09 +00:00
/**
2014-12-03 10:39:11 +00:00
* Get the first display object that exists, or doesn't exist.
*
* @method Phaser.Group#getFirstExists
2014-12-03 10:39:11 +00:00
* @param {boolean} [exists=true] - If true, find the first existing child; otherwise find the first non-existing child.
* @return {any} The first child, or null if none found.
*/
2014-12-03 10:39:11 +00:00
Phaser.Group.prototype.getFirstExists = function (exists) {
2013-10-02 00:16:40 +00:00
2014-12-03 10:39:11 +00:00
if (typeof exists !== 'boolean')
{
2014-12-03 10:39:11 +00:00
exists = true;
}
2013-10-02 00:16:40 +00:00
2014-12-03 10:39:11 +00:00
return this.iterate('exists', exists, Phaser.Group.RETURN_CHILD);
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Get the first child that is alive (`child.alive === true`).
*
* This is handy for checking if everything has been wiped out, or choosing a squad leader, etc.
*
* @method Phaser.Group#getFirstAlive
2014-12-03 10:39:11 +00:00
* @return {any} The first alive child, or null if none found.
*/
Phaser.Group.prototype.getFirstAlive = function () {
2013-10-02 00:16:40 +00:00
return this.iterate('alive', true, Phaser.Group.RETURN_CHILD);
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Get the first child that is dead (`child.alive === false`).
*
* This is handy for checking if everything has been wiped out, or choosing a squad leader, etc.
*
* @method Phaser.Group#getFirstDead
2014-12-03 10:39:11 +00:00
* @return {any} The first dead child, or null if none found.
*/
Phaser.Group.prototype.getFirstDead = function () {
2013-10-02 00:16:40 +00:00
return this.iterate('alive', false, Phaser.Group.RETURN_CHILD);
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Return the child at the top of this group.
*
* The top child is the child displayed (rendered) above every other child.
*
* @method Phaser.Group#getTop
2014-12-03 10:39:11 +00:00
* @return {any} The child at the top of the Group.
*/
Phaser.Group.prototype.getTop = function () {
if (this.children.length > 0)
{
return this.children[this.children.length - 1];
}
};
/**
2014-12-03 10:39:11 +00:00
* Returns the child at the bottom of this group.
*
* The bottom child the child being displayed (rendered) below every other child.
*
* @method Phaser.Group#getBottom
2014-12-03 10:39:11 +00:00
* @return {any} The child at the bottom of the Group.
*/
Phaser.Group.prototype.getBottom = function () {
if (this.children.length > 0)
{
return this.children[0];
}
};
/**
2014-12-03 10:39:11 +00:00
* Get the number of living children in this group.
*
* @method Phaser.Group#countLiving
2014-12-03 10:39:11 +00:00
* @return {integer} The number of children flagged as alive.
*/
Phaser.Group.prototype.countLiving = function () {
2013-10-02 00:16:40 +00:00
return this.iterate('alive', true, Phaser.Group.RETURN_TOTAL);
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Get the number of dead children in this group.
*
* @method Phaser.Group#countDead
2014-12-03 10:39:11 +00:00
* @return {integer} The number of children flagged as dead.
*/
Phaser.Group.prototype.countDead = function () {
2013-10-02 00:16:40 +00:00
return this.iterate('alive', false, Phaser.Group.RETURN_TOTAL);
2013-10-02 00:16:40 +00:00
};
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Returns a random child from the group.
*
* @method Phaser.Group#getRandom
2014-12-03 10:39:11 +00:00
* @param {integer} [startIndex=0] - Offset from the front of the front of the group (lowest child).
* @param {integer} [length=(to top)] - Restriction on the number of values you want to randomly select from.
* @return {any} A random child of this Group.
*/
Phaser.Group.prototype.getRandom = function (startIndex, length) {
2013-10-02 00:16:40 +00:00
if (this.children.length === 0)
{
return null;
}
2013-10-02 00:16:40 +00:00
startIndex = startIndex || 0;
length = length || this.children.length;
2013-10-02 00:16:40 +00:00
2014-11-15 20:01:46 +00:00
return Phaser.ArrayUtils.getRandomItem(this.children, startIndex, length);
2013-10-02 00:16:40 +00:00
};
2013-11-28 15:57:09 +00:00
/**
2014-12-03 10:39:11 +00:00
* Removes the given child from this group.
*
* This will dispatch an `onRemovedFromGroup` event from the child (if it has one), and optionally destroy the child.
*
* If the group cursor was referring to the removed child it is updated to refer to the next child.
*
* @method Phaser.Group#remove
2014-12-03 10:39:11 +00:00
* @param {any} child - The child to remove.
* @param {boolean} [destroy=false] - If true `destroy` will be invoked on the removed child.
* @param {boolean} [silent=false] - If true the the child will not dispatch the `onRemovedFromGroup` event.
* @return {boolean} true if the child was removed from this group, otherwise false.
*/
2014-07-10 19:31:11 +00:00
Phaser.Group.prototype.remove = function (child, destroy, silent) {
2015-07-22 14:31:30 +00:00
if (destroy === undefined) { destroy = false; }
if (silent === undefined) { silent = false; }
2013-11-28 15:57:09 +00:00
2014-04-29 14:39:02 +00:00
if (this.children.length === 0 || this.children.indexOf(child) === -1)
{
return false;
}
2013-11-28 15:57:09 +00:00
2015-03-23 23:46:30 +00:00
if (!silent &amp;&amp; child.events &amp;&amp; !child.destroyPhase)
{
2014-12-03 10:39:11 +00:00
child.events.onRemovedFromGroup$dispatch(child, this);
}
2013-11-28 15:57:09 +00:00
2014-04-15 14:39:23 +00:00
var removed = this.removeChild(child);
2013-11-28 15:57:09 +00:00
2015-07-22 14:31:30 +00:00
this.removeFromHash(child);
2015-03-23 23:46:30 +00:00
this.updateZ();
if (this.cursor === child)
{
this.next();
}
2013-11-28 15:57:09 +00:00
2015-03-23 23:46:30 +00:00
if (destroy &amp;&amp; removed)
{
2014-04-29 14:39:02 +00:00
removed.destroy(true);
}
return true;
2013-11-28 15:57:09 +00:00
};
2013-11-28 15:57:09 +00:00
2015-07-22 14:31:30 +00:00
/**
* Moves all children from this Group to the Group given.
*
* @method Phaser.Group#moveAll
* @param {Phaser.Group} group - The new Group to which the children will be moved to.
* @param {boolean} [silent=false] - If true the children will not dispatch the `onAddedToGroup` event for the new Group.
* @return {Phaser.Group} The Group to which all the children were moved.
*/
Phaser.Group.prototype.moveAll = function (group, silent) {
if (silent === undefined) { silent = false; }
if (this.children.length > 0 &amp;&amp; group instanceof Phaser.Group)
{
do
{
group.add(this.children[0], silent);
}
while (this.children.length > 0);
this.hash = [];
this.cursor = null;
}
return group;
};
/**
2014-12-03 10:39:11 +00:00
* Removes all children from this group, but does not remove the group from its parent.
*
* @method Phaser.Group#removeAll
2014-12-03 10:39:11 +00:00
* @param {boolean} [destroy=false] - If true `destroy` will be invoked on each removed child.
* @param {boolean} [silent=false] - If true the children will not dispatch their `onRemovedFromGroup` events.
*/
2014-07-10 19:31:11 +00:00
Phaser.Group.prototype.removeAll = function (destroy, silent) {
2015-07-22 14:31:30 +00:00
if (destroy === undefined) { destroy = false; }
if (silent === undefined) { silent = false; }
2013-11-28 15:57:09 +00:00
if (this.children.length === 0)
{
return;
}
2013-11-28 15:57:09 +00:00
do
{
2015-03-23 23:46:30 +00:00
if (!silent &amp;&amp; this.children[0].events)
2013-11-28 15:57:09 +00:00
{
2014-12-03 10:39:11 +00:00
this.children[0].events.onRemovedFromGroup$dispatch(this.children[0], this);
2013-11-28 15:57:09 +00:00
}
2014-04-15 14:39:23 +00:00
var removed = this.removeChild(this.children[0]);
2015-07-22 14:31:30 +00:00
this.removeFromHash(removed);
2015-03-23 23:46:30 +00:00
if (destroy &amp;&amp; removed)
{
2014-04-29 14:39:02 +00:00
removed.destroy(true);
}
}
while (this.children.length > 0);
2013-11-28 15:57:09 +00:00
2015-07-22 14:31:30 +00:00
this.hash = [];
2015-03-23 23:46:30 +00:00
this.cursor = null;
2013-11-28 15:57:09 +00:00
};
2013-11-28 15:57:09 +00:00
/**
2014-12-03 10:39:11 +00:00
* Removes all children from this group whose index falls beteen the given startIndex and endIndex values.
*
* @method Phaser.Group#removeBetween
2014-12-03 10:39:11 +00:00
* @param {integer} startIndex - The index to start removing children from.
* @param {integer} [endIndex] - The index to stop removing children at. Must be higher than startIndex. If undefined this method will remove all children between startIndex and the end of the group.
* @param {boolean} [destroy=false] - If true `destroy` will be invoked on each removed child.
* @param {boolean} [silent=false] - If true the children will not dispatch their `onRemovedFromGroup` events.
*/
2014-07-10 19:31:11 +00:00
Phaser.Group.prototype.removeBetween = function (startIndex, endIndex, destroy, silent) {
2013-11-28 15:57:09 +00:00
2015-07-22 14:31:30 +00:00
if (endIndex === undefined) { endIndex = this.children.length - 1; }
if (destroy === undefined) { destroy = false; }
if (silent === undefined) { silent = false; }
2014-04-10 22:13:43 +00:00
if (this.children.length === 0)
{
return;
}
2013-11-28 15:57:09 +00:00
if (startIndex > endIndex || startIndex &lt; 0 || endIndex > this.children.length)
{
return false;
}
2013-11-28 15:57:09 +00:00
2014-04-10 22:13:43 +00:00
var i = endIndex;
while (i >= startIndex)
{
2015-03-23 23:46:30 +00:00
if (!silent &amp;&amp; this.children[i].events)
2013-11-28 15:57:09 +00:00
{
2014-12-03 10:39:11 +00:00
this.children[i].events.onRemovedFromGroup$dispatch(this.children[i], this);
2013-11-28 15:57:09 +00:00
}
2014-04-15 14:39:23 +00:00
var removed = this.removeChild(this.children[i]);
2013-11-28 15:57:09 +00:00
2015-07-22 14:31:30 +00:00
this.removeFromHash(removed);
2015-03-23 23:46:30 +00:00
if (destroy &amp;&amp; removed)
{
2014-04-29 14:39:02 +00:00
removed.destroy(true);
}
if (this.cursor === this.children[i])
2014-02-05 06:29:17 +00:00
{
this.cursor = null;
2014-02-05 06:29:17 +00:00
}
2014-04-10 22:13:43 +00:00
i--;
}
2013-11-28 15:57:09 +00:00
this.updateZ();
};
2013-11-28 15:57:09 +00:00
/**
2014-12-03 10:39:11 +00:00
* Destroys this group.
*
* Removes all children, then removes this group from its parent and nulls references.
*
* @method Phaser.Group#destroy
2014-12-03 10:39:11 +00:00
* @param {boolean} [destroyChildren=true] - If true `destroy` will be invoked on each removed child.
* @param {boolean} [soft=false] - A 'soft destroy' (set to true) doesn't remove this group from its parent or null the game reference. Set to false and it does.
*/
2014-03-24 12:41:45 +00:00
Phaser.Group.prototype.destroy = function (destroyChildren, soft) {
2013-11-28 15:57:09 +00:00
2014-10-09 15:12:53 +00:00
if (this.game === null || this.ignoreDestroy) { return; }
2015-07-22 14:31:30 +00:00
if (destroyChildren === undefined) { destroyChildren = true; }
if (soft === undefined) { soft = false; }
2013-11-28 15:57:09 +00:00
2014-09-09 14:36:56 +00:00
this.onDestroy.dispatch(this, destroyChildren, soft);
2014-04-15 14:39:23 +00:00
this.removeAll(destroyChildren);
2013-11-28 15:57:09 +00:00
2014-03-24 12:41:45 +00:00
this.cursor = null;
2014-07-10 19:31:11 +00:00
this.filters = null;
2015-07-22 14:31:30 +00:00
this.pendingDestroy = false;
2013-11-28 15:57:09 +00:00
2014-03-24 12:41:45 +00:00
if (!soft)
{
2014-04-29 14:39:02 +00:00
if (this.parent)
{
this.parent.removeChild(this);
}
2013-10-02 00:16:40 +00:00
2014-03-24 12:41:45 +00:00
this.game = null;
this.exists = false;
}
};
2014-02-05 06:29:17 +00:00
/**
2014-12-03 10:39:11 +00:00
* Total number of existing children in the group.
*
* @name Phaser.Group#total
2014-12-03 10:39:11 +00:00
* @property {integer} total
* @readonly
*/
Object.defineProperty(Phaser.Group.prototype, "total", {
get: function () {
2014-02-05 06:29:17 +00:00
return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL);
2014-02-05 06:29:17 +00:00
}
});
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* Total number of children in this group, regardless of exists/alive status.
*
2013-10-02 00:16:40 +00:00
* @name Phaser.Group#length
2014-12-03 10:39:11 +00:00
* @property {integer} length
2013-10-02 11:11:22 +00:00
* @readonly
2013-10-02 00:16:40 +00:00
*/
Object.defineProperty(Phaser.Group.prototype, "length", {
get: function () {
2014-02-05 06:29:17 +00:00
return this.children.length;
2014-02-05 06:29:17 +00:00
2013-10-02 00:16:40 +00:00
}
});
/**
2014-12-03 10:39:11 +00:00
* The angle of rotation of the group container, in degrees.
*
* This adjusts the group itself by modifying its local rotation transform.
*
* This has no impact on the rotation/angle properties of the children, but it will update their worldTransform
* and on-screen orientation and position.
*
2013-10-02 00:16:40 +00:00
* @name Phaser.Group#angle
2014-12-03 10:39:11 +00:00
* @property {number} angle
2013-10-02 00:16:40 +00:00
*/
Object.defineProperty(Phaser.Group.prototype, "angle", {
get: function() {
return Phaser.Math.radToDeg(this.rotation);
2013-10-02 00:16:40 +00:00
},
set: function(value) {
this.rotation = Phaser.Math.degToRad(value);
2013-10-02 00:16:40 +00:00
}
});
2014-12-03 10:39:11 +00:00
/**
* A display object is any object that can be rendered in the Phaser/pixi.js scene graph.
*
* This includes {@link Phaser.Group} (groups are display objects!),
* {@link Phaser.Sprite}, {@link Phaser.Button}, {@link Phaser.Text}
* as well as {@link PIXI.DisplayObject} and all derived types.
*
* @typedef {object} DisplayObject
*/
// Documentation stub for linking.
/**
2014-12-03 10:39:11 +00:00
* The x coordinate of the group container.
*
* You can adjust the group container itself by modifying its coordinates.
* This will have no impact on the x/y coordinates of its children, but it will update their worldTransform and on-screen position.
* @name Phaser.Group#x
2014-12-03 10:39:11 +00:00
* @property {number} x
*/
/**
2014-12-03 10:39:11 +00:00
* The y coordinate of the group container.
*
* You can adjust the group container itself by modifying its coordinates.
* This will have no impact on the x/y coordinates of its children, but it will update their worldTransform and on-screen position.
* @name Phaser.Group#y
2014-12-03 10:39:11 +00:00
* @property {number} y
*/
2013-10-02 00:16:40 +00:00
/**
2014-12-03 10:39:11 +00:00
* The angle of rotation of the group container, in radians.
*
* This will adjust the group container itself by modifying its rotation.
2013-10-02 00:16:40 +00:00
* This will have no impact on the rotation value of its children, but it will update their worldTransform and on-screen position.
* @name Phaser.Group#rotation
2014-12-03 10:39:11 +00:00
* @property {number} rotation
2013-10-02 00:16:40 +00:00
*/
/**
2014-12-03 10:39:11 +00:00
* The visible state of the group. Non-visible Groups and all of their children are not rendered.
*
2013-10-02 00:16:40 +00:00
* @name Phaser.Group#visible
2014-12-03 10:39:11 +00:00
* @property {boolean} visible
2013-10-02 00:16:40 +00:00
*/
/**
2014-12-03 10:39:11 +00:00
* The alpha value of the group container.
*
* @name Phaser.Group#alpha
2014-12-03 10:39:11 +00:00
* @property {number} alpha
*/
2013-10-02 00:16:40 +00:00
</pre>
</article>
</section>
</div>
<div class="clearfix"></div>
<footer>
<span class="copyright">
2015-03-23 23:46:30 +00:00
Phaser Copyright © 2012-2015 Photon Storm Ltd.
2013-10-02 00:16:40 +00:00
</span>
<br />
<span class="jsdoc-message">
2015-03-23 23:46:30 +00:00
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha10</a>
2015-07-29 14:01:04 +00:00
on Wed Jul 29 2015 14:57:50 GMT+0100 (GMT Daylight Time) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
2013-10-02 00:16:40 +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( {
2014-04-10 22:13:43 +00:00
anchorName : function(i, heading, prefix) {
return $(heading).attr("id") || ( prefix + i );
},
2013-10-02 00:16:40 +00:00
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>