phaser/docs/src_gameobjects_Text.js.html

3333 lines
95 KiB
HTML
Raw Normal View History

2014-11-15 20:01:46 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
2015-03-23 23:46:30 +00:00
<title>Phaser Source: src/gameobjects/Text.js</title>
2014-11-15 20:01:46 +00:00
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/default.css">
<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">
<link type="text/css" rel="stylesheet" href="styles/site.cerulean.css">
</head>
<body>
2014-11-25 00:23:44 +00:00
2014-11-15 20:01:46 +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>
2014-11-15 20:01:46 +00:00
<div class="navbar-inner">
2014-11-25 00:23:44 +00:00
<a class="brand" href="index.html">Phaser API</a>
2014-11-15 20:01:46 +00:00
<ul class="nav">
2014-11-25 00:23:44 +00:00
2014-11-15 20:01:46 +00:00
<li class="dropdown">
<a href="namespaces.list.html" class="dropdown-toggle" data-toggle="dropdown">Namespaces<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li class="class-depth-0">
<a href="Phaser.html">Phaser</a>
</li>
2015-10-15 11:06:38 +00:00
<li class="class-depth-0">
<a href="Phaser.KeyCode.html">KeyCode</a>
</li>
2014-11-15 20:01:46 +00:00
<li class="class-depth-0">
<a href="PIXI.html">PIXI</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="classes.list.html" class="dropdown-toggle" data-toggle="dropdown">Classes<b
class="caret"></b></a>
<ul class="dropdown-menu ">
<li class="class-depth-1">
<a href="Phaser.Animation.html">Animation</a>
</li>
<li class="class-depth-1">
<a href="Phaser.AnimationManager.html">AnimationManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.AnimationParser.html">AnimationParser</a>
</li>
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>
<li class="class-depth-1">
<a href="Phaser.AudioSprite.html">AudioSprite</a>
</li>
<li class="class-depth-1">
<a href="Phaser.BitmapData.html">BitmapData</a>
</li>
<li class="class-depth-1">
<a href="Phaser.BitmapText.html">BitmapText</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Button.html">Button</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Cache.html">Cache</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Camera.html">Camera</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Canvas.html">Canvas</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Circle.html">Circle</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Color.html">Color</a>
</li>
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-11-15 20:01:46 +00:00
<li class="class-depth-1">
<a href="Phaser.Device.html">Device</a>
</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>
<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-11-15 20:01:46 +00:00
<li class="class-depth-1">
<a href="Phaser.Ellipse.html">Ellipse</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Events.html">Events</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Filter.html">Filter</a>
</li>
<li class="class-depth-1">
<a href="Phaser.FlexGrid.html">FlexGrid</a>
</li>
<li class="class-depth-1">
<a href="Phaser.FlexLayer.html">FlexLayer</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Frame.html">Frame</a>
</li>
<li class="class-depth-1">
<a href="Phaser.FrameData.html">FrameData</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Game.html">Game</a>
</li>
<li class="class-depth-1">
<a href="Phaser.GameObjectCreator.html">GameObjectCreator</a>
</li>
<li class="class-depth-1">
<a href="Phaser.GameObjectFactory.html">GameObjectFactory</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Gamepad.html">Gamepad</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Graphics.html">Graphics</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Group.html">Group</a>
</li>
<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-11-15 20:01:46 +00:00
<li class="class-depth-1">
<a href="Phaser.Input.html">Input</a>
</li>
<li class="class-depth-1">
<a href="Phaser.InputHandler.html">InputHandler</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Key.html">Key</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Keyboard.html">Keyboard</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Line.html">Line</a>
</li>
<li class="class-depth-1">
<a href="Phaser.LinkedList.html">LinkedList</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Loader.html">Loader</a>
</li>
<li class="class-depth-1">
<a href="Phaser.LoaderParser.html">LoaderParser</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Math.html">Math</a>
</li>
2015-07-22 14:31:30 +00:00
<li class="class-depth-1">
<a href="Phaser.Matrix.html">Matrix</a>
</li>
2014-11-15 20:01:46 +00:00
<li class="class-depth-1">
<a href="Phaser.Mouse.html">Mouse</a>
</li>
<li class="class-depth-1">
<a href="Phaser.MSPointer.html">MSPointer</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Net.html">Net</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Particle.html">Particle</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Particles.html">Particles</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Particles.Arcade.html">Arcade</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Particles.Arcade.Emitter.html">Emitter</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Physics.html">Physics</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Physics.Arcade.html">Arcade</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.Arcade.Body.html">Body</a>
</li>
2015-03-23 23:46:30 +00:00
<li class="class-depth-3">
2015-08-24 14:43:45 +00:00
<a href="Phaser.Physics.Arcade.TilemapCollision.html">TilemapCollision</a>
2015-03-23 23:46:30 +00:00
</li>
2014-11-15 20:01:46 +00:00
<li class="class-depth-2">
<a href="Phaser.Physics.Ninja.html">Ninja</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.AABB.html">AABB</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Body.html">Body</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Circle.html">Circle</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.Ninja.Tile.html">Tile</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Physics.P2.html">P2</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Body.html">Body</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.BodyDebug.html">BodyDebug</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.CollisionGroup.html">CollisionGroup</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.ContactMaterial.html">ContactMaterial</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.DistanceConstraint.html">DistanceConstraint</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.FixtureList.html">FixtureList</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.GearConstraint.html">GearConstraint</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.InversePointProxy.html">InversePointProxy</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.LockConstraint.html">LockConstraint</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Material.html">Material</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.PointProxy.html">PointProxy</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.PrismaticConstraint.html">PrismaticConstraint</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.RevoluteConstraint.html">RevoluteConstraint</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.RotationalSpring.html">RotationalSpring</a>
</li>
<li class="class-depth-3">
<a href="Phaser.Physics.P2.Spring.html">Spring</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Plugin.html">Plugin</a>
</li>
<li class="class-depth-1">
<a href="Phaser.PluginManager.html">PluginManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Point.html">Point</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Pointer.html">Pointer</a>
</li>
2015-10-15 11:06:38 +00:00
<li class="class-depth-1">
<a href="Phaser.PointerMode.html">PointerMode</a>
</li>
2014-11-15 20:01:46 +00:00
<li class="class-depth-1">
<a href="Phaser.Polygon.html">Polygon</a>
</li>
<li class="class-depth-1">
<a href="Phaser.QuadTree.html">QuadTree</a>
</li>
<li class="class-depth-1">
<a href="Phaser.RandomDataGenerator.html">RandomDataGenerator</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Rectangle.html">Rectangle</a>
</li>
<li class="class-depth-1">
<a href="Phaser.RenderTexture.html">RenderTexture</a>
</li>
<li class="class-depth-1">
<a href="Phaser.RequestAnimationFrame.html">RequestAnimationFrame</a>
</li>
<li class="class-depth-1">
<a href="Phaser.RetroFont.html">RetroFont</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Rope.html">Rope</a>
</li>
2015-07-22 14:31:30 +00:00
<li class="class-depth-1">
<a href="Phaser.RoundedRectangle.html">RoundedRectangle</a>
</li>
2014-11-15 20:01:46 +00:00
<li class="class-depth-1">
<a href="Phaser.ScaleManager.html">ScaleManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Signal.html">Signal</a>
</li>
<li class="class-depth-1">
<a href="Phaser.SignalBinding.html">SignalBinding</a>
</li>
<li class="class-depth-1">
<a href="Phaser.SinglePad.html">SinglePad</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Sound.html">Sound</a>
</li>
<li class="class-depth-1">
<a href="Phaser.SoundManager.html">SoundManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Sprite.html">Sprite</a>
</li>
<li class="class-depth-1">
<a href="Phaser.SpriteBatch.html">SpriteBatch</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Stage.html">Stage</a>
</li>
<li class="class-depth-1">
<a href="Phaser.State.html">State</a>
</li>
<li class="class-depth-1">
<a href="Phaser.StateManager.html">StateManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Text.html">Text</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Tile.html">Tile</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Tilemap.html">Tilemap</a>
</li>
<li class="class-depth-1">
<a href="Phaser.TilemapLayer.html">TilemapLayer</a>
</li>
<li class="class-depth-1">
<a href="Phaser.TilemapParser.html">TilemapParser</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Tileset.html">Tileset</a>
</li>
<li class="class-depth-1">
<a href="Phaser.TileSprite.html">TileSprite</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Time.html">Time</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Timer.html">Timer</a>
</li>
<li class="class-depth-1">
<a href="Phaser.TimerEvent.html">TimerEvent</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Touch.html">Touch</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Tween.html">Tween</a>
</li>
2014-11-25 00:23:44 +00:00
<li class="class-depth-1">
<a href="Phaser.TweenData.html">TweenData</a>
</li>
2014-11-15 20:01:46 +00:00
<li class="class-depth-1">
<a href="Phaser.TweenManager.html">TweenManager</a>
</li>
<li class="class-depth-1">
<a href="Phaser.Utils.html">Utils</a>
</li>
<li class="class-depth-2">
<a href="Phaser.Utils.Debug.html">Debug</a>
</li>
<li class="class-depth-1">
2015-07-22 14:31:30 +00:00
<a href="Phaser.Video.html">Video</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="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>
2015-08-24 14:43:45 +00:00
<li class="class-depth-1">
<a href="PIXI.CanvasPool.html">CanvasPool</a>
</li>
2014-11-15 20:01:46 +00:00
<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>
2016-02-08 17:01:36 +00:00
<li class="class-depth-1">
<a href="PIXI.EarCut.html">EarCut</a>
</li>
2014-11-15 20:01:46 +00:00
<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.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>
</li>
<li class="class-depth-0">
<a href="global.html#CIRCLE">CIRCLE</a>
</li>
<li class="class-depth-0">
<a href="global.html#CREATURE">CREATURE</a>
</li>
<li class="class-depth-0">
<a href="global.html#DOWN">DOWN</a>
</li>
<li class="class-depth-0">
<a href="global.html#ELLIPSE">ELLIPSE</a>
</li>
<li class="class-depth-0">
<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>
2016-02-08 17:01:36 +00:00
<li class="class-depth-0">
<a href="global.html#PENDING_ATLAS">PENDING_ATLAS</a>
</li>
2015-07-22 14:31:30 +00:00
<li class="class-depth-0">
<a href="global.html#POINT">POINT</a>
</li>
<li class="class-depth-0">
<a href="global.html#POINTER">POINTER</a>
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#POLYGON">POLYGON</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#RECTANGLE">RECTANGLE</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#RENDERTEXTURE">RENDERTEXTURE</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#RETROFONT">RETROFONT</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#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>
</li>
<li class="class-depth-0">
<a href="global.html#TILEMAP">TILEMAP</a>
</li>
<li class="class-depth-0">
<a href="global.html#TILEMAPLAYER">TILEMAPLAYER</a>
</li>
<li class="class-depth-0">
<a href="global.html#TILESPRITE">TILESPRITE</a>
</li>
<li class="class-depth-0">
<a href="global.html#UP">UP</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#VERSION">VERSION</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#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>
</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>
<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-25 00:23:44 +00:00
</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">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>
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">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>
2014-11-15 20:01:46 +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/gameobjects/Text.js</h1>
2014-11-15 20:01:46 +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.
2014-11-15 20:01:46 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
2015-03-23 23:46:30 +00:00
* Create a new game object for displaying Text.
*
* This uses a local hidden Canvas object and renders the type into it. It then makes a texture from this for rendering to the view.
* Because of this you can only display fonts that are currently loaded and available to the browser: fonts must be pre-loaded.
*
* See {@link http://www.jordanm.co.uk/tinytype this compatibility table} for the available default fonts across mobile browsers.
2014-11-15 20:01:46 +00:00
*
* @class Phaser.Text
2015-07-22 14:31:30 +00:00
* @extends Phaser.Sprite
2014-11-15 20:01:46 +00:00
* @constructor
* @param {Phaser.Game} game - Current game instance.
* @param {number} x - X position of the new text object.
* @param {number} y - Y position of the new text object.
* @param {string} text - The actual text that will be written.
2015-07-22 14:31:30 +00:00
* @param {object} [style] - The style properties to be set on the Text.
* @param {string} [style.font='bold 20pt Arial'] - The style and size of the font.
* @param {string} [style.fontStyle=(from font)] - The style of the font (eg. 'italic'): overrides the value in `style.font`.
* @param {string} [style.fontVariant=(from font)] - The variant of the font (eg. 'small-caps'): overrides the value in `style.font`.
* @param {string} [style.fontWeight=(from font)] - The weight of the font (eg. 'bold'): overrides the value in `style.font`.
* @param {string|number} [style.fontSize=(from font)] - The size of the font (eg. 32 or '32px'): overrides the value in `style.font`.
* @param {string} [style.backgroundColor=null] - A canvas fillstyle that will be used as the background for the whole Text object. Set to `null` to disable.
* @param {string} [style.fill='black'] - A canvas fillstyle that will be used on the text eg 'red', '#00FF00'.
* @param {string} [style.align='left'] - Horizontal alignment of each line in multiline text. Can be: 'left', 'center' or 'right'. Does not affect single lines of text (see `textBounds` and `boundsAlignH` for that).
* @param {string} [style.boundsAlignH='left'] - Horizontal alignment of the text within the `textBounds`. Can be: 'left', 'center' or 'right'.
* @param {string} [style.boundsAlignV='top'] - Vertical alignment of the text within the `textBounds`. Can be: 'top', 'middle' or 'bottom'.
* @param {string} [style.stroke='black'] - A canvas stroke style that will be used on the text stroke eg 'blue', '#FCFF00'.
* @param {number} [style.strokeThickness=0] - A number that represents the thickness of the stroke. Default is 0 (no stroke).
* @param {boolean} [style.wordWrap=false] - Indicates if word wrap should be used.
* @param {number} [style.wordWrapWidth=100] - The width in pixels at which text will wrap.
* @param {number} [style.tabs=0] - The size (in pixels) of the tabs, for when text includes tab characters. 0 disables. Can be an array of varying tab sizes, one per tab stop.
2014-11-15 20:01:46 +00:00
*/
Phaser.Text = function (game, x, y, text, style) {
x = x || 0;
y = y || 0;
2015-08-24 14:43:45 +00:00
if (text === undefined || text === null)
{
text = '';
}
else
{
text = text.toString();
}
2016-02-08 17:01:36 +00:00
style = Phaser.Utils.extend({}, style);
2014-11-15 20:01:46 +00:00
/**
* @property {number} type - The const type of this object.
* @default
*/
this.type = Phaser.TEXT;
/**
2015-03-23 23:46:30 +00:00
* @property {number} physicsType - The const physics body type of this object.
* @readonly
2014-11-15 20:01:46 +00:00
*/
2015-03-23 23:46:30 +00:00
this.physicsType = Phaser.SPRITE;
2014-11-15 20:01:46 +00:00
/**
2015-03-23 23:46:30 +00:00
* Specify a padding value which is added to the line width and height when calculating the Text size.
* ALlows you to add extra spacing if Phaser is unable to accurately determine the true font dimensions.
* @property {Phaser.Point} padding
2014-11-15 20:01:46 +00:00
*/
2015-03-23 23:46:30 +00:00
this.padding = new Phaser.Point();
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
/**
* The textBounds property allows you to specify a rectangular region upon which text alignment is based.
* See `Text.setTextBounds` for more details.
* @property {Phaser.Rectangle} textBounds
* @readOnly
*/
this.textBounds = null;
/**
* @property {HTMLCanvasElement} canvas - The canvas element that the text is rendered.
*/
2015-08-24 14:43:45 +00:00
this.canvas = PIXI.CanvasPool.create(this);
2015-07-22 14:31:30 +00:00
/**
* @property {HTMLCanvasElement} context - The context of the canvas element that the text is rendered to.
*/
this.context = this.canvas.getContext('2d');
/**
* @property {array} colors - An array of the color values as specified by {@link Phaser.Text#addColor addColor}.
*/
this.colors = [];
/**
* @property {array} strokeColors - An array of the stroke color values as specified by {@link Phaser.Text#addStrokeColor addStrokeColor}.
*/
this.strokeColors = [];
2015-08-24 14:43:45 +00:00
/**
* @property {array} fontStyles - An array of the font styles values as specified by {@link Phaser.Text#addFontStyle addFontStyle}.
*/
this.fontStyles = [];
/**
* @property {array} fontWeights - An array of the font weights values as specified by {@link Phaser.Text#addFontWeight addFontWeight}.
*/
this.fontWeights = [];
2015-07-22 14:31:30 +00:00
/**
* Should the linePositionX and Y values be automatically rounded before rendering the Text?
* You may wish to enable this if you want to remove the effect of sub-pixel aliasing from text.
* @property {boolean} autoRound
* @default
*/
this.autoRound = false;
2016-02-08 17:01:36 +00:00
/**
* Will this Text object use Basic or Advanced Word Wrapping?
*
* Advanced wrapping breaks long words if they are the first of a line, and repeats the process as necessary.
* White space is condensed (e.g., consecutive spaces are replaced with one).
* Lines are trimmed of white space before processing.
*
* It throws an error if wordWrapWidth is less than a single character.
* @property {boolean} useAdvancedWrap
* @default
*/
this.useAdvancedWrap = false;
2015-07-22 14:31:30 +00:00
/**
* @property {number} _res - Internal canvas resolution var.
* @private
*/
this._res = game.renderer.resolution;
2014-11-15 20:01:46 +00:00
/**
* @property {string} _text - Internal cache var.
* @private
*/
this._text = text;
/**
2015-03-23 23:46:30 +00:00
* @property {object} _fontComponents - The font, broken down into components, set in `setStyle`.
2014-11-15 20:01:46 +00:00
* @private
*/
2015-03-23 23:46:30 +00:00
this._fontComponents = null;
2014-11-15 20:01:46 +00:00
/**
* @property {number} lineSpacing - Additional spacing (in pixels) between each line of text if multi-line.
* @private
*/
this._lineSpacing = 0;
/**
* @property {number} _charCount - Internal character counter used by the text coloring.
* @private
*/
2015-03-23 23:46:30 +00:00
this._charCount = 0;
2014-11-15 20:01:46 +00:00
/**
2015-07-22 14:31:30 +00:00
* @property {number} _width - Internal width var.
* @private
2014-11-15 20:01:46 +00:00
*/
2015-07-22 14:31:30 +00:00
this._width = 0;
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
/**
* @property {number} _height - Internal height var.
* @private
*/
this._height = 0;
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
Phaser.Sprite.call(this, game, x, y, PIXI.Texture.fromCanvas(this.canvas));
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
this.setStyle(style);
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
if (text !== '')
2014-11-15 20:01:46 +00:00
{
this.updateText();
}
};
2015-07-22 14:31:30 +00:00
Phaser.Text.prototype = Object.create(Phaser.Sprite.prototype);
2014-11-15 20:01:46 +00:00
Phaser.Text.prototype.constructor = Phaser.Text;
/**
* Automatically called by World.preUpdate.
2014-12-03 10:39:11 +00:00
*
* @method Phaser.Text#preUpdate
2015-03-23 23:46:30 +00:00
* @protected
2014-11-15 20:01:46 +00:00
*/
Phaser.Text.prototype.preUpdate = function () {
2015-03-23 23:46:30 +00:00
if (!this.preUpdatePhysics() || !this.preUpdateLifeSpan() || !this.preUpdateInWorld())
2014-11-15 20:01:46 +00:00
{
return false;
}
2015-03-23 23:46:30 +00:00
return this.preUpdateCore();
2014-11-15 20:01:46 +00:00
};
/**
2015-03-23 23:46:30 +00:00
* Override this function to handle any special update requirements.
2014-11-15 20:01:46 +00:00
*
* @method Phaser.Text#update
2015-03-23 23:46:30 +00:00
* @protected
2014-11-15 20:01:46 +00:00
*/
Phaser.Text.prototype.update = function() {
};
/**
2015-03-23 23:46:30 +00:00
* Destroy this Text object, removing it from the group it belongs to.
*
2014-12-03 10:39:11 +00:00
* @method Phaser.Text#destroy
2014-11-15 20:01:46 +00:00
* @param {boolean} [destroyChildren=true] - Should every child of this object have its destroy method called?
*/
Phaser.Text.prototype.destroy = function (destroyChildren) {
this.texture.destroy(true);
2015-08-24 14:43:45 +00:00
PIXI.CanvasPool.remove(this);
2015-03-23 23:46:30 +00:00
Phaser.Component.Destroy.prototype.destroy.call(this, destroyChildren);
2014-11-15 20:01:46 +00:00
};
/**
2014-12-03 10:39:11 +00:00
* Sets a drop shadow effect on the Text. You can specify the horizontal and vertical distance of the drop shadow with the `x` and `y` parameters.
* The color controls the shade of the shadow (default is black) and can be either an `rgba` or `hex` value.
* The blur is the strength of the shadow. A value of zero means a hard shadow, a value of 10 means a very soft shadow.
* To remove a shadow already in place you can call this method with no parameters set.
*
* @method Phaser.Text#setShadow
2014-11-15 20:01:46 +00:00
* @param {number} [x=0] - The shadowOffsetX value in pixels. This is how far offset horizontally the shadow effect will be.
* @param {number} [y=0] - The shadowOffsetY value in pixels. This is how far offset vertically the shadow effect will be.
2014-12-03 10:39:11 +00:00
* @param {string} [color='rgba(0,0,0,1)'] - The color of the shadow, as given in CSS rgba or hex format. Set the alpha component to 0 to disable the shadow.
2014-11-15 20:01:46 +00:00
* @param {number} [blur=0] - The shadowBlur value. Make the shadow softer by applying a Gaussian blur to it. A number from 0 (no blur) up to approx. 10 (depending on scene).
2015-07-22 14:31:30 +00:00
* @param {boolean} [shadowStroke=true] - Apply the drop shadow to the Text stroke (if set).
* @param {boolean} [shadowFill=true] - Apply the drop shadow to the Text fill (if set).
* @return {Phaser.Text} This Text instance.
2014-11-15 20:01:46 +00:00
*/
2015-07-22 14:31:30 +00:00
Phaser.Text.prototype.setShadow = function (x, y, color, blur, shadowStroke, shadowFill) {
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
if (color === undefined) { color = 'rgba(0, 0, 0, 1)'; }
if (blur === undefined) { blur = 0; }
if (shadowStroke === undefined) { shadowStroke = true; }
if (shadowFill === undefined) { shadowFill = true; }
2014-12-03 10:39:11 +00:00
this.style.shadowOffsetX = x;
this.style.shadowOffsetY = y;
this.style.shadowColor = color;
this.style.shadowBlur = blur;
2015-07-22 14:31:30 +00:00
this.style.shadowStroke = shadowStroke;
this.style.shadowFill = shadowFill;
2014-11-15 20:01:46 +00:00
this.dirty = true;
2015-07-22 14:31:30 +00:00
return this;
2014-11-15 20:01:46 +00:00
};
/**
* Set the style of the text by passing a single style object to it.
*
2014-12-03 10:39:11 +00:00
* @method Phaser.Text#setStyle
* @param {object} [style] - The style properties to be set on the Text.
2014-11-15 20:01:46 +00:00
* @param {string} [style.font='bold 20pt Arial'] - The style and size of the font.
2015-03-23 23:46:30 +00:00
* @param {string} [style.fontStyle=(from font)] - The style of the font (eg. 'italic'): overrides the value in `style.font`.
* @param {string} [style.fontVariant=(from font)] - The variant of the font (eg. 'small-caps'): overrides the value in `style.font`.
* @param {string} [style.fontWeight=(from font)] - The weight of the font (eg. 'bold'): overrides the value in `style.font`.
* @param {string|number} [style.fontSize=(from font)] - The size of the font (eg. 32 or '32px'): overrides the value in `style.font`.
* @param {string} [style.backgroundColor=null] - A canvas fillstyle that will be used as the background for the whole Text object. Set to `null` to disable.
2014-11-15 20:01:46 +00:00
* @param {string} [style.fill='black'] - A canvas fillstyle that will be used on the text eg 'red', '#00FF00'.
2015-07-22 14:31:30 +00:00
* @param {string} [style.align='left'] - Horizontal alignment of each line in multiline text. Can be: 'left', 'center' or 'right'. Does not affect single lines of text (see `textBounds` and `boundsAlignH` for that).
* @param {string} [style.boundsAlignH='left'] - Horizontal alignment of the text within the `textBounds`. Can be: 'left', 'center' or 'right'.
* @param {string} [style.boundsAlignV='top'] - Vertical alignment of the text within the `textBounds`. Can be: 'top', 'middle' or 'bottom'.
2014-11-15 20:01:46 +00:00
* @param {string} [style.stroke='black'] - A canvas stroke style that will be used on the text stroke eg 'blue', '#FCFF00'.
* @param {number} [style.strokeThickness=0] - A number that represents the thickness of the stroke. Default is 0 (no stroke).
* @param {boolean} [style.wordWrap=false] - Indicates if word wrap should be used.
* @param {number} [style.wordWrapWidth=100] - The width in pixels at which text will wrap.
2015-07-22 14:31:30 +00:00
* @param {number|array} [style.tabs=0] - The size (in pixels) of the tabs, for when text includes tab characters. 0 disables. Can be an array of varying tab sizes, one per tab stop.
* @return {Phaser.Text} This Text instance.
2014-11-15 20:01:46 +00:00
*/
Phaser.Text.prototype.setStyle = function (style) {
style = style || {};
style.font = style.font || 'bold 20pt Arial';
2015-03-23 23:46:30 +00:00
style.backgroundColor = style.backgroundColor || null;
2014-11-15 20:01:46 +00:00
style.fill = style.fill || 'black';
style.align = style.align || 'left';
2015-07-22 14:31:30 +00:00
style.boundsAlignH = style.boundsAlignH || 'left';
style.boundsAlignV = style.boundsAlignV || 'top';
2014-11-15 20:01:46 +00:00
style.stroke = style.stroke || 'black'; //provide a default, see: https://github.com/GoodBoyDigital/pixi.js/issues/136
style.strokeThickness = style.strokeThickness || 0;
style.wordWrap = style.wordWrap || false;
style.wordWrapWidth = style.wordWrapWidth || 100;
style.shadowOffsetX = style.shadowOffsetX || 0;
style.shadowOffsetY = style.shadowOffsetY || 0;
style.shadowColor = style.shadowColor || 'rgba(0,0,0,0)';
style.shadowBlur = style.shadowBlur || 0;
2015-07-22 14:31:30 +00:00
style.tabs = style.tabs || 0;
2014-11-15 20:01:46 +00:00
2015-03-23 23:46:30 +00:00
var components = this.fontToComponents(style.font);
if (style.fontStyle)
{
components.fontStyle = style.fontStyle;
}
if (style.fontVariant)
{
components.fontVariant = style.fontVariant;
}
if (style.fontWeight)
{
components.fontWeight = style.fontWeight;
}
if (style.fontSize)
{
if (typeof style.fontSize === 'number')
{
style.fontSize = style.fontSize + 'px';
}
components.fontSize = style.fontSize;
}
this._fontComponents = components;
style.font = this.componentsToFont(this._fontComponents);
2014-11-15 20:01:46 +00:00
this.style = style;
this.dirty = true;
2015-07-22 14:31:30 +00:00
return this;
2014-11-15 20:01:46 +00:00
};
/**
* Renders text. This replaces the Pixi.Text.updateText function as we need a few extra bits in here.
*
2014-12-03 10:39:11 +00:00
* @method Phaser.Text#updateText
2014-11-15 20:01:46 +00:00
* @private
*/
Phaser.Text.prototype.updateText = function () {
2015-07-22 14:31:30 +00:00
this.texture.baseTexture.resolution = this._res;
2014-11-15 20:01:46 +00:00
this.context.font = this.style.font;
var outputText = this.text;
if (this.style.wordWrap)
{
outputText = this.runWordWrap(this.text);
}
2015-07-22 14:31:30 +00:00
// Split text into lines
2014-11-15 20:01:46 +00:00
var lines = outputText.split(/(?:\r\n|\r|\n)/);
2015-07-22 14:31:30 +00:00
// Calculate text width
var tabs = this.style.tabs;
2014-11-15 20:01:46 +00:00
var lineWidths = [];
var maxLineWidth = 0;
var fontProperties = this.determineFontProperties(this.style.font);
for (var i = 0; i &lt; lines.length; i++)
{
2015-07-22 14:31:30 +00:00
if (tabs === 0)
{
// Simple layout (no tabs)
var lineWidth = this.context.measureText(lines[i]).width + this.style.strokeThickness + this.padding.x;
2015-10-15 11:06:38 +00:00
// Adjust for wrapped text
if (this.style.wordWrap)
{
lineWidth -= this.context.measureText(' ').width;
}
2015-07-22 14:31:30 +00:00
}
else
{
// Complex layout (tabs)
var line = lines[i].split(/(?:\t)/);
var lineWidth = this.padding.x + this.style.strokeThickness;
if (Array.isArray(tabs))
{
var tab = 0;
for (var c = 0; c &lt; line.length; c++)
{
var section = Math.ceil(this.context.measureText(line[c]).width);
if (c > 0)
{
tab += tabs[c - 1];
}
lineWidth = tab + section;
}
}
else
{
for (var c = 0; c &lt; line.length; c++)
{
// How far to the next tab?
lineWidth += Math.ceil(this.context.measureText(line[c]).width);
var diff = this.game.math.snapToCeil(lineWidth, tabs) - lineWidth;
lineWidth += diff;
}
}
}
lineWidths[i] = Math.ceil(lineWidth);
maxLineWidth = Math.max(maxLineWidth, lineWidths[i]);
2014-11-15 20:01:46 +00:00
}
2015-10-15 11:06:38 +00:00
this.canvas.width = maxLineWidth * this._res;
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
// Calculate text height
2015-03-23 23:46:30 +00:00
var lineHeight = fontProperties.fontSize + this.style.strokeThickness + this.padding.y;
var height = lineHeight * lines.length;
var lineSpacing = this._lineSpacing;
if (lineSpacing &lt; 0 &amp;&amp; Math.abs(lineSpacing) > lineHeight)
{
lineSpacing = -lineHeight;
}
2014-12-03 10:39:11 +00:00
2015-03-23 23:46:30 +00:00
// Adjust for line spacing
if (lineSpacing !== 0)
{
2016-02-17 13:27:09 +00:00
height += lineSpacing * lines.length;
2015-03-23 23:46:30 +00:00
}
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
this.canvas.height = height * this._res;
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
this.context.scale(this._res, this._res);
2014-11-15 20:01:46 +00:00
if (navigator.isCocoonJS)
{
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
}
2015-03-23 23:46:30 +00:00
if (this.style.backgroundColor)
{
this.context.fillStyle = this.style.backgroundColor;
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
}
2014-11-15 20:01:46 +00:00
this.context.fillStyle = this.style.fill;
this.context.font = this.style.font;
this.context.strokeStyle = this.style.stroke;
this.context.textBaseline = 'alphabetic';
2015-07-22 14:31:30 +00:00
2014-11-15 20:01:46 +00:00
this.context.lineWidth = this.style.strokeThickness;
this.context.lineCap = 'round';
this.context.lineJoin = 'round';
var linePositionX;
var linePositionY;
this._charCount = 0;
2015-03-23 23:46:30 +00:00
// Draw text line by line
2014-11-15 20:01:46 +00:00
for (i = 0; i &lt; lines.length; i++)
{
2015-07-22 14:31:30 +00:00
// Split the line by
2014-11-15 20:01:46 +00:00
linePositionX = this.style.strokeThickness / 2;
linePositionY = (this.style.strokeThickness / 2 + i * lineHeight) + fontProperties.ascent;
2015-03-23 23:46:30 +00:00
if (i > 0)
{
linePositionY += (lineSpacing * i);
}
2014-11-15 20:01:46 +00:00
if (this.style.align === 'right')
{
linePositionX += maxLineWidth - lineWidths[i];
}
else if (this.style.align === 'center')
{
linePositionX += (maxLineWidth - lineWidths[i]) / 2;
}
2015-07-22 14:31:30 +00:00
if (this.autoRound)
{
linePositionX = Math.round(linePositionX);
linePositionY = Math.round(linePositionY);
}
2015-08-24 14:43:45 +00:00
if (this.colors.length > 0 || this.strokeColors.length > 0 || this.fontWeights.length > 0 || this.fontStyles.length > 0)
2014-11-15 20:01:46 +00:00
{
this.updateLine(lines[i], linePositionX, linePositionY);
}
else
{
2015-03-23 23:46:30 +00:00
if (this.style.stroke &amp;&amp; this.style.strokeThickness)
2014-11-15 20:01:46 +00:00
{
2015-07-22 14:31:30 +00:00
this.updateShadow(this.style.shadowStroke);
if (tabs === 0)
{
this.context.strokeText(lines[i], linePositionX, linePositionY);
}
else
{
this.renderTabLine(lines[i], linePositionX, linePositionY, false);
}
2014-11-15 20:01:46 +00:00
}
if (this.style.fill)
{
2015-07-22 14:31:30 +00:00
this.updateShadow(this.style.shadowFill);
if (tabs === 0)
{
this.context.fillText(lines[i], linePositionX, linePositionY);
}
else
{
this.renderTabLine(lines[i], linePositionX, linePositionY, true);
}
2014-11-15 20:01:46 +00:00
}
}
}
this.updateTexture();
};
2014-12-03 10:39:11 +00:00
/**
2015-07-22 14:31:30 +00:00
* Renders a line of text that contains tab characters if Text.tab > 0.
* Called automatically by updateText.
2014-12-03 10:39:11 +00:00
*
2015-07-22 14:31:30 +00:00
* @method Phaser.Text#renderTabLine
2014-12-03 10:39:11 +00:00
* @private
2015-07-22 14:31:30 +00:00
* @param {string} line - The line of text to render.
* @param {integer} x - The x position to start rendering from.
* @param {integer} y - The y position to start rendering from.
* @param {boolean} fill - If true uses fillText, if false uses strokeText.
2014-12-03 10:39:11 +00:00
*/
2015-07-22 14:31:30 +00:00
Phaser.Text.prototype.renderTabLine = function (line, x, y, fill) {
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
var text = line.split(/(?:\t)/);
var tabs = this.style.tabs;
var snap = 0;
if (Array.isArray(tabs))
2014-11-15 20:01:46 +00:00
{
2015-07-22 14:31:30 +00:00
var tab = 0;
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
for (var c = 0; c &lt; text.length; c++)
2014-11-15 20:01:46 +00:00
{
2015-07-22 14:31:30 +00:00
if (c > 0)
{
tab += tabs[c - 1];
}
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
snap = x + tab;
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
if (fill)
{
this.context.fillText(text[c], snap, y);
}
else
{
this.context.strokeText(text[c], snap, y);
}
2014-11-15 20:01:46 +00:00
}
2015-07-22 14:31:30 +00:00
}
else
{
for (var c = 0; c &lt; text.length; c++)
{
var section = Math.ceil(this.context.measureText(text[c]).width);
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
// How far to the next tab?
snap = this.game.math.snapToCeil(x, tabs);
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
if (fill)
{
this.context.fillText(text[c], snap, y);
}
else
{
this.context.strokeText(text[c], snap, y);
}
x = snap + section;
}
2014-11-15 20:01:46 +00:00
}
};
/**
2015-07-22 14:31:30 +00:00
* Sets the Shadow on the Text.context based on the Style settings, or disables it if not enabled.
* This is called automatically by Text.updateText.
2014-11-15 20:01:46 +00:00
*
2015-07-22 14:31:30 +00:00
* @method Phaser.Text#updateShadow
* @param {boolean} state - If true the shadow will be set to the Style values, otherwise it will be set to zero.
2014-11-15 20:01:46 +00:00
*/
2015-07-22 14:31:30 +00:00
Phaser.Text.prototype.updateShadow = function (state) {
2014-11-15 20:01:46 +00:00
2015-07-22 14:31:30 +00:00
if (state)
{
this.context.shadowOffsetX = this.style.shadowOffsetX;
this.context.shadowOffsetY = this.style.shadowOffsetY;
this.context.shadowColor = this.style.shadowColor;
this.context.shadowBlur = this.style.shadowBlur;
}
else
{
this.context.shadowOffsetX = 0;
this.context.shadowOffsetY = 0;
this.context.shadowColor = 0;
this.context.shadowBlur = 0;
}
};
/**
2015-08-24 14:43:45 +00:00
* Updates a line of text, applying fill and stroke per-character colors or style and weight per-character font if applicable.
2015-07-22 14:31:30 +00:00
*
* @method Phaser.Text#updateLine
* @private
*/
Phaser.Text.prototype.updateLine = function (line, x, y) {
for (var i = 0; i &lt; line.length; i++)
{
var letter = line[i];
2015-08-24 14:43:45 +00:00
if (this.fontWeights.length > 0 || this.fontStyles.length > 0)
{
var components = this.fontToComponents(this.context.font);
if (this.fontStyles[this._charCount])
{
components.fontStyle = this.fontStyles[this._charCount];
}
if (this.fontWeights[this._charCount])
{
components.fontWeight = this.fontWeights[this._charCount];
}
this.context.font = this.componentsToFont(components);
}
2015-07-22 14:31:30 +00:00
if (this.style.stroke &amp;&amp; this.style.strokeThickness)
{
if (this.strokeColors[this._charCount])
{
this.context.strokeStyle = this.strokeColors[this._charCount];
}
this.updateShadow(this.style.shadowStroke);
this.context.strokeText(letter, x, y);
}
if (this.style.fill)
{
if (this.colors[this._charCount])
{
this.context.fillStyle = this.colors[this._charCount];
}
this.updateShadow(this.style.shadowFill);
this.context.fillText(letter, x, y);
}
x += this.context.measureText(letter).width;
this._charCount++;
}
};
/**
* Clears any text fill or stroke colors that were set by `addColor` or `addStrokeColor`.
*
* @method Phaser.Text#clearColors
* @return {Phaser.Text} This Text instance.
*/
Phaser.Text.prototype.clearColors = function () {
this.colors = [];
this.strokeColors = [];
this.dirty = true;
return this;
2014-11-15 20:01:46 +00:00
};
2015-08-24 14:43:45 +00:00
/**
* Clears any text styles or weights font that were set by `addFontStyle` or `addFontWeight`.
*
* @method Phaser.Text#clearFontValues
* @return {Phaser.Text} This Text instance.
*/
Phaser.Text.prototype.clearFontValues = function () {
this.fontStyles = [];
this.fontWeights = [];
this.dirty = true;
return this;
};
2014-11-15 20:01:46 +00:00
/**
2015-03-23 23:46:30 +00:00
* Set specific colors for certain characters within the Text.
*
2014-11-15 20:01:46 +00:00
* It works by taking a color value, which is a typical HTML string such as `#ff0000` or `rgb(255,0,0)` and a position.
* The position value is the index of the character in the Text string to start applying this color to.
* Once set the color remains in use until either another color or the end of the string is encountered.
* For example if the Text was `Photon Storm` and you did `Text.addColor('#ffff00', 6)` it would color in the word `Storm` in yellow.
*
2015-07-22 14:31:30 +00:00
* If you wish to change the stroke color see addStrokeColor instead.
*
2014-12-03 10:39:11 +00:00
* @method Phaser.Text#addColor
2014-11-15 20:01:46 +00:00
* @param {string} color - A canvas fillstyle that will be used on the text eg `red`, `#00FF00`, `rgba()`.
* @param {number} position - The index of the character in the string to start applying this color value from.
2015-07-22 14:31:30 +00:00
* @return {Phaser.Text} This Text instance.
2014-11-15 20:01:46 +00:00
*/
Phaser.Text.prototype.addColor = function (color, position) {
this.colors[position] = color;
this.dirty = true;
2015-07-22 14:31:30 +00:00
return this;
};
/**
* Set specific stroke colors for certain characters within the Text.
*
* It works by taking a color value, which is a typical HTML string such as `#ff0000` or `rgb(255,0,0)` and a position.
* The position value is the index of the character in the Text string to start applying this color to.
* Once set the color remains in use until either another color or the end of the string is encountered.
* For example if the Text was `Photon Storm` and you did `Text.addColor('#ffff00', 6)` it would color in the word `Storm` in yellow.
*
* This has no effect if stroke is disabled or has a thickness of 0.
*
* If you wish to change the text fill color see addColor instead.
*
* @method Phaser.Text#addStrokeColor
* @param {string} color - A canvas fillstyle that will be used on the text stroke eg `red`, `#00FF00`, `rgba()`.
* @param {number} position - The index of the character in the string to start applying this color value from.
* @return {Phaser.Text} This Text instance.
*/
Phaser.Text.prototype.addStrokeColor = function (color, position) {
this.strokeColors[position] = color;
this.dirty = true;
return this;
2014-11-15 20:01:46 +00:00
};
2015-08-24 14:43:45 +00:00
/**
* Set specific font styles for certain characters within the Text.
*
* It works by taking a font style value, which is a typical string such as `normal`, `italic` or `oblique`.
* The position value is the index of the character in the Text string to start applying this font style to.
* Once set the font style remains in use until either another font style or the end of the string is encountered.
* For example if the Text was `Photon Storm` and you did `Text.addFontStyle('italic', 6)` it would font style in the word `Storm` in italic.
*
* If you wish to change the text font weight see addFontWeight instead.
*
* @method Phaser.Text#addFontStyle
* @param {string} style - A canvas font-style that will be used on the text style eg `normal`, `italic`, `oblique`.
* @param {number} position - The index of the character in the string to start applying this font style value from.
* @return {Phaser.Text} This Text instance.
*/
Phaser.Text.prototype.addFontStyle = function (style, position) {
this.fontStyles[position] = style;
this.dirty = true;
return this;
};
/**
* Set specific font weights for certain characters within the Text.
*
* It works by taking a font weight value, which is a typical string such as `normal`, `bold`, `bolder`, etc.
* The position value is the index of the character in the Text string to start applying this font weight to.
* Once set the font weight remains in use until either another font weight or the end of the string is encountered.
* For example if the Text was `Photon Storm` and you did `Text.addFontWeight('bold', 6)` it would font weight in the word `Storm` in bold.
*
* If you wish to change the text font style see addFontStyle instead.
*
* @method Phaser.Text#addFontWeight
* @param {string} style - A canvas font-weight that will be used on the text weight eg `normal`, `bold`, `bolder`, `lighter`, etc.
* @param {number} position - The index of the character in the string to start applying this font weight value from.
* @return {Phaser.Text} This Text instance.
*/
Phaser.Text.prototype.addFontWeight = function (weight, position) {
this.fontWeights[position] = weight;
this.dirty = true;
return this;
};
2016-02-08 17:01:36 +00:00
/**
* Runs the given text through the Text.runWordWrap function and returns
* the results as an array, where each element of the array corresponds to a wrapped
* line of text.
*
* Useful if you wish to control pagination on long pieces of content.
*
* @method Phaser.Text#precalculateWordWrap
* @param {string} text - The text for which the wrapping will be calculated.
* @return {array} An array of strings with the pieces of wrapped text.
*/
Phaser.Text.prototype.precalculateWordWrap = function (text) {
this.texture.baseTexture.resolution = this._res;
this.context.font = this.style.font;
var wrappedLines = this.runWordWrap(text);
return wrappedLines.split(/(?:\r\n|\r|\n)/);
};
2014-11-15 20:01:46 +00:00
/**
* Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal bounds.
*
2014-12-03 10:39:11 +00:00
* @method Phaser.Text#runWordWrap
2014-11-15 20:01:46 +00:00
* @param {string} text - The text to perform word wrap detection against.
* @private
*/
Phaser.Text.prototype.runWordWrap = function (text) {
2016-02-08 17:01:36 +00:00
if (this.useAdvancedWrap)
{
return this.advancedWordWrap(text);
}
else
{
return this.basicWordWrap(text);
}
};
/**
* Advanced wrapping algorithm that will wrap words as the line grows longer than its horizontal bounds.
* White space is condensed (e.g., consecutive spaces are replaced with one).
* Lines are trimmed of white space before processing.
* Throws an error if the user was smart enough to specify a wordWrapWidth less than a single character.
*
* @method Phaser.Text#advancedWordWrap
* @param {string} text - The text to perform word wrap detection against.
* @private
*/
Phaser.Text.prototype.advancedWordWrap = function (text) {
var context = this.context;
var wordWrapWidth = this.style.wordWrapWidth;
var output = '';
// (1) condense whitespace
// (2) split into lines
var lines = text
.replace(/ +/gi, ' ')
.split(/\r?\n/gi);
var linesCount = lines.length;
for (var i = 0; i &lt; linesCount; i++)
{
var line = lines[i];
var out = '';
// trim whitespace
line = line.replace(/^ *|\s*$/gi, '');
// if entire line is less than wordWrapWidth
// append the entire line and exit early
var lineWidth = context.measureText(line).width;
if (lineWidth &lt; wordWrapWidth)
{
output += line + '\n';
continue;
}
// otherwise, calculate new lines
var currentLineWidth = wordWrapWidth;
// split into words
var words = line.split(' ');
for (var j = 0; j &lt; words.length; j++)
{
var word = words[j];
var wordWithSpace = word + ' ';
var wordWidth = context.measureText(wordWithSpace).width;
if (wordWidth > currentLineWidth)
{
// break word
if (j === 0)
{
// shave off letters from word until it's small enough
var newWord = wordWithSpace;
while (newWord.length)
{
newWord = newWord.slice(0, -1);
wordWidth = context.measureText(newWord).width;
if (wordWidth &lt;= currentLineWidth)
{
break;
}
}
// if wordWrapWidth is too small for even a single
// letter, shame user failure with a fatal error
if (!newWord.length)
{
throw new Error('This text\'s wordWrapWidth setting is less than a single character!');
}
// replace current word in array with remainder
var secondPart = word.substr(newWord.length);
words[j] = secondPart;
// append first piece to output
out += newWord;
}
// if existing word length is 0, don't include it
var offset = (words[j].length) ? j : j + 1;
// collapse rest of sentence
var remainder = words.slice(offset).join(' ')
// remove any trailing white space
.replace(/[ \n]*$/gi, '');
// prepend remainder to next line
lines[i + 1] = remainder + ' ' + (lines[i + 1] || '');
linesCount = lines.length;
break; // processing on this line
// append word with space to output
}
else
{
out += wordWithSpace;
currentLineWidth -= wordWidth;
}
}
// append processed line to output
output += out.replace(/[ \n]*$/gi, '') + '\n';
}
// trim the end of the string
output = output.replace(/[\s|\n]*$/gi, '');
return output;
};
/**
* Greedy wrapping algorithm that will wrap words as the line grows longer than its horizontal bounds.
*
* @method Phaser.Text#basicWordWrap
* @param {string} text - The text to perform word wrap detection against.
* @private
*/
Phaser.Text.prototype.basicWordWrap = function (text) {
2014-11-15 20:01:46 +00:00
var result = '';
var lines = text.split('\n');
for (var i = 0; i &lt; lines.length; i++)
{
var spaceLeft = this.style.wordWrapWidth;
var words = lines[i].split(' ');
for (var j = 0; j &lt; words.length; j++)
{
var wordWidth = this.context.measureText(words[j]).width;
var wordWidthWithSpace = wordWidth + this.context.measureText(' ').width;
if (wordWidthWithSpace > spaceLeft)
{
// Skip printing the newline if it's the first word of the line that is greater than the word wrap width.
if (j > 0)
{
result += '\n';
}
result += words[j] + ' ';
spaceLeft = this.style.wordWrapWidth - wordWidth;
}
else
{
spaceLeft -= wordWidthWithSpace;
result += words[j] + ' ';
}
}
if (i &lt; lines.length-1)
{
result += '\n';
}
}
return result;
};
/**
2015-03-23 23:46:30 +00:00
* Updates the internal `style.font` if it now differs according to generation from components.
*
* @method Phaser.Text#updateFont
* @private
* @param {object} components - Font components.
2014-11-15 20:01:46 +00:00
*/
2015-03-23 23:46:30 +00:00
Phaser.Text.prototype.updateFont = function (components) {
2014-11-15 20:01:46 +00:00
2015-03-23 23:46:30 +00:00
var font = this.componentsToFont(components);
2014-11-15 20:01:46 +00:00
2015-03-23 23:46:30 +00:00
if (this.style.font !== font)
{
this.style.font = font;
this.dirty = true;
if (this.parent)
{
this.updateTransform();
}
2014-11-15 20:01:46 +00:00
}
2015-03-23 23:46:30 +00:00
};
/**
* Converting a short CSS-font string into the relevant components.
*
* @method Phaser.Text#fontToComponents
* @private
* @param {string} font - a CSS font string
*/
Phaser.Text.prototype.fontToComponents = function (font) {
// The format is specified in http://www.w3.org/TR/CSS2/fonts.html#font-shorthand:
// style - normal | italic | oblique | inherit
// variant - normal | small-caps | inherit
// weight - normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
// size - xx-small | x-small | small | medium | large | x-large | xx-large,
// larger | smaller
// {number} (em | ex | ch | rem | vh | vw | vmin | vmax | px | mm | cm | in | pt | pc | %)
// font-family - rest (but identifiers or quoted with comma separation)
var m = font.match(/^\s*(?:\b(normal|italic|oblique|inherit)?\b)\s*(?:\b(normal|small-caps|inherit)?\b)\s*(?:\b(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900|inherit)?\b)\s*(?:\b(xx-small|x-small|small|medium|large|x-large|xx-large|larger|smaller|0|\d*(?:[.]\d*)?(?:%|[a-z]{2,5}))?\b)\s*(.*)\s*$/);
if (m)
{
return {
font: font,
fontStyle: m[1] || 'normal',
fontVariant: m[2] || 'normal',
fontWeight: m[3] || 'normal',
fontSize: m[4] || 'medium',
fontFamily: m[5]
};
}
else
{
console.warn("Phaser.Text - unparsable CSS font: " + font);
return {
font: font
};
}
};
/**
* Converts individual font components (see `fontToComponents`) to a short CSS font string.
*
* @method Phaser.Text#componentsToFont
* @private
* @param {object} components - Font components.
*/
Phaser.Text.prototype.componentsToFont = function (components) {
var parts = [];
var v;
v = components.fontStyle;
if (v &amp;&amp; v !== 'normal') { parts.push(v); }
v = components.fontVariant;
if (v &amp;&amp; v !== 'normal') { parts.push(v); }
v = components.fontWeight;
if (v &amp;&amp; v !== 'normal') { parts.push(v); }
v = components.fontSize;
if (v &amp;&amp; v !== 'medium') { parts.push(v); }
v = components.fontFamily;
if (v) { parts.push(v); }
if (!parts.length)
{
// Fallback to whatever value the 'font' was
parts.push(components.font);
}
return parts.join(" ");
};
2014-11-15 20:01:46 +00:00
/**
2015-07-22 14:31:30 +00:00
* The text to be displayed by this Text object.
* Use a \n to insert a carriage return and split the text.
* The text will be rendered with any style currently set.
*
* @method Phaser.Text#setText
* @param {string} [text] - The text to be displayed. Set to an empty string to clear text that is already present.
* @return {Phaser.Text} This Text instance.
*/
Phaser.Text.prototype.setText = function (text) {
this.text = text.toString() || '';
this.dirty = true;
return this;
};
/**
* Converts the given array into a tab delimited string and then updates this Text object.
* This is mostly used when you want to display external data using tab stops.
*
* The array can be either single or multi dimensional depending on the result you need:
*
* `[ 'a', 'b', 'c' ]` would convert in to `"a\tb\tc"`.
*
* Where as:
*
* `[
* [ 'a', 'b', 'c' ],
* [ 'd', 'e', 'f']
* ]`
*
* would convert in to: `"a\tb\tc\nd\te\tf"`
*
* @method Phaser.Text#parseList
* @param {array} list - The array of data to convert into a string.
* @return {Phaser.Text} This Text instance.
*/
Phaser.Text.prototype.parseList = function (list) {
if (!Array.isArray(list))
{
return this;
}
else
{
var s = "";
for (var i = 0; i &lt; list.length; i++)
{
if (Array.isArray(list[i]))
{
s += list[i].join("\t");
if (i &lt; list.length - 1)
{
s += "\n";
}
}
else
{
s += list[i];
if (i &lt; list.length - 1)
{
s += "\t";
}
}
}
}
this.text = s;
this.dirty = true;
return this;
};
/**
* The Text Bounds is a rectangular region that you control the dimensions of into which the Text object itself is positioned,
* regardless of the number of lines in the text, the font size or any other attribute.
*
* Alignment is controlled via the properties `boundsAlignH` and `boundsAlignV` within the Text.style object, or can be directly
* set through the setters `Text.boundsAlignH` and `Text.boundsAlignV`. Bounds alignment is independent of text alignment.
*
* For example: If your game is 800x600 in size and you set the text bounds to be 0,0,800,600 then by setting boundsAlignH to
* 'center' and boundsAlignV to 'bottom' the text will render in the center and at the bottom of your game window, regardless of
* how many lines of text there may be. Even if you adjust the text content or change the style it will remain at the bottom center
* of the text bounds.
*
* This is especially powerful when you need to align text against specific coordinates in your game, but the actual text dimensions
* may vary based on font (say for multi-lingual games).
*
* If `Text.wordWrapWidth` is greater than the width of the text bounds it is clamped to match the bounds width.
*
* Call this method with no arguments given to reset an existing textBounds.
*
* It works by calculating the final position based on the Text.canvas size, which is modified as the text is updated. Some fonts
* have additional padding around them which you can mitigate by tweaking the Text.padding property. It then adjusts the `pivot`
* property based on the given bounds and canvas size. This means if you need to set the pivot property directly in your game then
* you either cannot use `setTextBounds` or you must place the Text object inside another DisplayObject on which you set the pivot.
*
* @method Phaser.Text#setTextBounds
* @param {number} [x] - The x coordinate of the Text Bounds region.
* @param {number} [y] - The y coordinate of the Text Bounds region.
* @param {number} [width] - The width of the Text Bounds region.
* @param {number} [height] - The height of the Text Bounds region.
* @return {Phaser.Text} This Text instance.
*/
Phaser.Text.prototype.setTextBounds = function (x, y, width, height) {
if (x === undefined)
{
this.textBounds = null;
}
else
{
if (!this.textBounds)
{
this.textBounds = new Phaser.Rectangle(x, y, width, height);
}
else
{
this.textBounds.setTo(x, y, width, height);
}
if (this.style.wordWrapWidth > width)
{
this.style.wordWrapWidth = width;
}
}
this.updateTexture();
return this;
};
/**
* Updates the texture based on the canvas dimensions.
*
* @method Phaser.Text#updateTexture
* @private
*/
Phaser.Text.prototype.updateTexture = function () {
var base = this.texture.baseTexture;
var crop = this.texture.crop;
var frame = this.texture.frame;
var w = this.canvas.width;
var h = this.canvas.height;
base.width = w;
base.height = h;
crop.width = w;
crop.height = h;
frame.width = w;
frame.height = h;
this.texture.width = w;
this.texture.height = h;
this._width = w;
this._height = h;
if (this.textBounds)
{
var x = this.textBounds.x;
var y = this.textBounds.y;
// Align the canvas based on the bounds
if (this.style.boundsAlignH === 'right')
{
2015-08-24 14:43:45 +00:00
x += this.textBounds.width - this.canvas.width;
2015-07-22 14:31:30 +00:00
}
else if (this.style.boundsAlignH === 'center')
{
2015-08-24 14:43:45 +00:00
x += this.textBounds.halfWidth - (this.canvas.width / 2);
2015-07-22 14:31:30 +00:00
}
if (this.style.boundsAlignV === 'bottom')
{
2015-08-24 14:43:45 +00:00
y += this.textBounds.height - this.canvas.height;
2015-07-22 14:31:30 +00:00
}
else if (this.style.boundsAlignV === 'middle')
{
2015-08-24 14:43:45 +00:00
y += this.textBounds.halfHeight - (this.canvas.height / 2);
2015-07-22 14:31:30 +00:00
}
this.pivot.x = -x;
this.pivot.y = -y;
}
// Can't render something with a zero sized dimension
this.renderable = (w !== 0 &amp;&amp; h !== 0);
2015-08-24 14:43:45 +00:00
this.texture.requiresReTint = true;
2015-07-22 14:31:30 +00:00
this.texture.baseTexture.dirty();
};
/**
* Renders the object using the WebGL renderer
*
* @method Phaser.Text#_renderWebGL
* @private
* @param {RenderSession} renderSession - The Render Session to render the Text on.
*/
Phaser.Text.prototype._renderWebGL = function (renderSession) {
if (this.dirty)
{
this.updateText();
this.dirty = false;
}
PIXI.Sprite.prototype._renderWebGL.call(this, renderSession);
};
/**
* Renders the object using the Canvas renderer.
*
* @method Phaser.Text#_renderCanvas
* @private
* @param {RenderSession} renderSession - The Render Session to render the Text on.
*/
Phaser.Text.prototype._renderCanvas = function (renderSession) {
if (this.dirty)
{
this.updateText();
this.dirty = false;
}
PIXI.Sprite.prototype._renderCanvas.call(this, renderSession);
};
/**
* Calculates the ascent, descent and fontSize of a given font style.
*
* @method Phaser.Text#determineFontProperties
* @private
* @param {object} fontStyle
*/
Phaser.Text.prototype.determineFontProperties = function (fontStyle) {
var properties = Phaser.Text.fontPropertiesCache[fontStyle];
if (!properties)
{
properties = {};
var canvas = Phaser.Text.fontPropertiesCanvas;
var context = Phaser.Text.fontPropertiesContext;
context.font = fontStyle;
var width = Math.ceil(context.measureText('|MÉq').width);
var baseline = Math.ceil(context.measureText('|MÉq').width);
var height = 2 * baseline;
baseline = baseline * 1.4 | 0;
canvas.width = width;
canvas.height = height;
context.fillStyle = '#f00';
context.fillRect(0, 0, width, height);
context.font = fontStyle;
context.textBaseline = 'alphabetic';
context.fillStyle = '#000';
context.fillText('|MÉq', 0, baseline);
if (!context.getImageData(0, 0, width, height))
{
properties.ascent = baseline;
properties.descent = baseline + 6;
properties.fontSize = properties.ascent + properties.descent;
Phaser.Text.fontPropertiesCache[fontStyle] = properties;
return properties;
}
var imagedata = context.getImageData(0, 0, width, height).data;
var pixels = imagedata.length;
var line = width * 4;
var i, j;
var idx = 0;
var stop = false;
// ascent. scan from top to bottom until we find a non red pixel
for (i = 0; i &lt; baseline; i++)
{
for (j = 0; j &lt; line; j += 4)
{
if (imagedata[idx + j] !== 255)
{
stop = true;
break;
}
}
if (!stop)
{
idx += line;
}
else
{
break;
}
}
properties.ascent = baseline - i;
idx = pixels - line;
stop = false;
// descent. scan from bottom to top until we find a non red pixel
for (i = height; i > baseline; i--)
{
for (j = 0; j &lt; line; j += 4)
{
if (imagedata[idx + j] !== 255)
{
stop = true;
break;
}
}
if (!stop)
{
idx -= line;
}
else
{
break;
}
}
properties.descent = i - baseline;
//TODO might need a tweak. kind of a temp fix!
properties.descent += 6;
properties.fontSize = properties.ascent + properties.descent;
Phaser.Text.fontPropertiesCache[fontStyle] = properties;
}
return properties;
};
/**
* Returns the bounds of the Text as a rectangle.
* The bounds calculation takes the worldTransform into account.
*
* @method Phaser.Text#getBounds
* @param {Phaser.Matrix} matrix - The transformation matrix of the Text.
* @return {Phaser.Rectangle} The framing rectangle
*/
Phaser.Text.prototype.getBounds = function (matrix) {
if (this.dirty)
{
this.updateText();
this.dirty = false;
}
return PIXI.Sprite.prototype.getBounds.call(this, matrix);
};
/**
* The text to be displayed by this Text object.
* Use a \n to insert a carriage return and split the text.
* The text will be rendered with any style currently set.
2015-03-23 23:46:30 +00:00
*
2014-11-15 20:01:46 +00:00
* @name Phaser.Text#text
2015-03-23 23:46:30 +00:00
* @property {string} text
2014-11-15 20:01:46 +00:00
*/
Object.defineProperty(Phaser.Text.prototype, 'text', {
get: function() {
return this._text;
},
set: function(value) {
if (value !== this._text)
{
2015-07-22 14:31:30 +00:00
this._text = value.toString() || '';
2014-11-15 20:01:46 +00:00
this.dirty = true;
if (this.parent)
{
this.updateTransform();
}
}
}
});
/**
2015-03-23 23:46:30 +00:00
* Change the font used.
*
* This is equivalent of the `font` property specified to {@link Phaser.Text#setStyle setStyle}, except
* that unlike using `setStyle` this will not change any current font fill/color settings.
*
* The CSS font string can also be individually altered with the `font`, `fontSize`, `fontWeight`, `fontStyle`, and `fontVariant` properties.
*
* @name Phaser.Text#cssFont
* @property {string} cssFont
*/
Object.defineProperty(Phaser.Text.prototype, 'cssFont', {
get: function() {
return this.componentsToFont(this._fontComponents);
},
set: function (value)
{
value = value || 'bold 20pt Arial';
this._fontComponents = this.fontToComponents(value);
this.updateFont(this._fontComponents);
}
});
/**
* Change the font family that the text will be rendered in, such as 'Arial'.
*
* Multiple CSS font families and generic fallbacks can be specified as long as
* {@link http://www.w3.org/TR/CSS2/fonts.html#propdef-font-family CSS font-family rules} are followed.
*
* To change the entire font string use {@link Phaser.Text#cssFont cssFont} instead: eg. `text.cssFont = 'bold 20pt Arial'`.
*
2014-11-15 20:01:46 +00:00
* @name Phaser.Text#font
2015-03-23 23:46:30 +00:00
* @property {string} font
2014-11-15 20:01:46 +00:00
*/
Object.defineProperty(Phaser.Text.prototype, 'font', {
get: function() {
2015-03-23 23:46:30 +00:00
return this._fontComponents.fontFamily;
2014-11-15 20:01:46 +00:00
},
set: function(value) {
2015-03-23 23:46:30 +00:00
value = value || 'Arial';
value = value.trim();
2014-11-15 20:01:46 +00:00
2015-03-23 23:46:30 +00:00
// If it looks like the value should be quoted, but isn't, then quote it.
if (!/^(?:inherit|serif|sans-serif|cursive|fantasy|monospace)$/.exec(value) &amp;&amp; !/['",]/.exec(value))
{
value = "'" + value + "'";
2014-11-15 20:01:46 +00:00
}
2015-03-23 23:46:30 +00:00
this._fontComponents.fontFamily = value;
this.updateFont(this._fontComponents);
2014-11-15 20:01:46 +00:00
}
});
/**
2015-03-23 23:46:30 +00:00
* The size of the font.
*
* If the font size is specified in pixels (eg. `32` or `'32px`') then a number (ie. `32`) representing
* the font size in pixels is returned; otherwise the value with CSS unit is returned as a string (eg. `'12pt'`).
*
2014-11-15 20:01:46 +00:00
* @name Phaser.Text#fontSize
2015-03-23 23:46:30 +00:00
* @property {number|string} fontSize
2014-11-15 20:01:46 +00:00
*/
Object.defineProperty(Phaser.Text.prototype, 'fontSize', {
get: function() {
2015-03-23 23:46:30 +00:00
var size = this._fontComponents.fontSize;
if (size &amp;&amp; /(?:^0$|px$)/.exec(size))
{
return parseInt(size, 10);
}
else
{
return size;
}
2014-11-15 20:01:46 +00:00
},
set: function(value) {
2015-03-23 23:46:30 +00:00
value = value || '0';
if (typeof value === 'number')
2014-11-15 20:01:46 +00:00
{
2015-03-23 23:46:30 +00:00
value = value + 'px';
2014-11-15 20:01:46 +00:00
}
2015-03-23 23:46:30 +00:00
this._fontComponents.fontSize = value;
this.updateFont(this._fontComponents);
2014-11-15 20:01:46 +00:00
}
});
/**
2015-03-23 23:46:30 +00:00
* The weight of the font: 'normal', 'bold', or {@link http://www.w3.org/TR/CSS2/fonts.html#propdef-font-weight a valid CSS font weight}.
2014-11-15 20:01:46 +00:00
* @name Phaser.Text#fontWeight
2015-03-23 23:46:30 +00:00
* @property {string} fontWeight
2014-11-15 20:01:46 +00:00
*/
Object.defineProperty(Phaser.Text.prototype, 'fontWeight', {
get: function() {
2015-03-23 23:46:30 +00:00
return this._fontComponents.fontWeight || 'normal';
2014-11-15 20:01:46 +00:00
},
set: function(value) {
2015-03-23 23:46:30 +00:00
value = value || 'normal';
this._fontComponents.fontWeight = value;
this.updateFont(this._fontComponents);
2014-11-15 20:01:46 +00:00
2015-03-23 23:46:30 +00:00
}
});
/**
* The style of the font: 'normal', 'italic', 'oblique'
* @name Phaser.Text#fontStyle
* @property {string} fontStyle
*/
Object.defineProperty(Phaser.Text.prototype, 'fontStyle', {
get: function() {
return this._fontComponents.fontStyle || 'normal';
},
set: function(value) {
value = value || 'normal';
this._fontComponents.fontStyle = value;
this.updateFont(this._fontComponents);
}
});
/**
* The variant the font: 'normal', 'small-caps'
* @name Phaser.Text#fontVariant
* @property {string} fontVariant
*/
Object.defineProperty(Phaser.Text.prototype, 'fontVariant', {
get: function() {
return this._fontComponents.fontVariant || 'normal';
},
set: function(value) {
value = value || 'normal';
this._fontComponents.fontVariant = value;
this.updateFont(this._fontComponents);
2014-11-15 20:01:46 +00:00
}
});
/**
* @name Phaser.Text#fill
* @property {object} fill - A canvas fillstyle that will be used on the text eg 'red', '#00FF00'.
*/
Object.defineProperty(Phaser.Text.prototype, 'fill', {
get: function() {
return this.style.fill;
},
set: function(value) {
if (value !== this.style.fill)
{
this.style.fill = value;
this.dirty = true;
}
}
});
/**
2015-07-22 14:31:30 +00:00
* Controls the horizontal alignment for multiline text.
* Can be: 'left', 'center' or 'right'.
* Does not affect single lines of text. For that please see `setTextBounds`.
2014-11-15 20:01:46 +00:00
* @name Phaser.Text#align
2015-07-22 14:31:30 +00:00
* @property {string} align
2014-11-15 20:01:46 +00:00
*/
Object.defineProperty(Phaser.Text.prototype, 'align', {
get: function() {
return this.style.align;
},
set: function(value) {
if (value !== this.style.align)
{
this.style.align = value;
this.dirty = true;
}
}
});
2015-07-22 14:31:30 +00:00
/**
* The resolution of the canvas the text is rendered to.
* This defaults to match the resolution of the renderer, but can be changed on a per Text object basis.
* @name Phaser.Text#resolution
* @property {integer} resolution
*/
Object.defineProperty(Phaser.Text.prototype, 'resolution', {
get: function() {
return this._res;
},
set: function(value) {
if (value !== this._res)
{
this._res = value;
this.dirty = true;
}
}
});
/**
* The size (in pixels) of the tabs, for when text includes tab characters. 0 disables.
* Can be an integer or an array of varying tab sizes, one tab per element.
* For example if you set tabs to 100 then when Text encounters a tab it will jump ahead 100 pixels.
* If you set tabs to be `[100,200]` then it will set the first tab at 100px and the second at 200px.
*
* @name Phaser.Text#tabs
* @property {integer|array} tabs
*/
Object.defineProperty(Phaser.Text.prototype, 'tabs', {
get: function() {
return this.style.tabs;
},
set: function(value) {
if (value !== this.style.tabs)
{
this.style.tabs = value;
this.dirty = true;
}
}
});
/**
* Horizontal alignment of the text within the `textBounds`. Can be: 'left', 'center' or 'right'.
* @name Phaser.Text#boundsAlignH
* @property {string} boundsAlignH
*/
Object.defineProperty(Phaser.Text.prototype, 'boundsAlignH', {
get: function() {
return this.style.boundsAlignH;
},
set: function(value) {
if (value !== this.style.boundsAlignH)
{
this.style.boundsAlignH = value;
this.dirty = true;
}
}
});
/**
* Vertical alignment of the text within the `textBounds`. Can be: 'top', 'middle' or 'bottom'.
* @name Phaser.Text#boundsAlignV
* @property {string} boundsAlignV
*/
Object.defineProperty(Phaser.Text.prototype, 'boundsAlignV', {
get: function() {
return this.style.boundsAlignV;
},
set: function(value) {
if (value !== this.style.boundsAlignV)
{
this.style.boundsAlignV = value;
this.dirty = true;
}
}
});
2014-11-15 20:01:46 +00:00
/**
* @name Phaser.Text#stroke
* @property {string} stroke - A canvas fillstyle that will be used on the text stroke eg 'blue', '#FCFF00'.
*/
Object.defineProperty(Phaser.Text.prototype, 'stroke', {
get: function() {
return this.style.stroke;
},
set: function(value) {
if (value !== this.style.stroke)
{
this.style.stroke = value;
this.dirty = true;
}
}
});
/**
* @name Phaser.Text#strokeThickness
* @property {number} strokeThickness - A number that represents the thickness of the stroke. Default is 0 (no stroke)
*/
Object.defineProperty(Phaser.Text.prototype, 'strokeThickness', {
get: function() {
return this.style.strokeThickness;
},
set: function(value) {
if (value !== this.style.strokeThickness)
{
this.style.strokeThickness = value;
this.dirty = true;
}
}
});
/**
* @name Phaser.Text#wordWrap
* @property {boolean} wordWrap - Indicates if word wrap should be used.
*/
Object.defineProperty(Phaser.Text.prototype, 'wordWrap', {
get: function() {
return this.style.wordWrap;
},
set: function(value) {
if (value !== this.style.wordWrap)
{
this.style.wordWrap = value;
this.dirty = true;
}
}
});
/**
* @name Phaser.Text#wordWrapWidth
* @property {number} wordWrapWidth - The width at which text will wrap.
*/
Object.defineProperty(Phaser.Text.prototype, 'wordWrapWidth', {
get: function() {
return this.style.wordWrapWidth;
},
set: function(value) {
if (value !== this.style.wordWrapWidth)
{
this.style.wordWrapWidth = value;
this.dirty = true;
}
}
});
/**
* @name Phaser.Text#lineSpacing
* @property {number} lineSpacing - Additional spacing (in pixels) between each line of text if multi-line.
*/
Object.defineProperty(Phaser.Text.prototype, 'lineSpacing', {
get: function() {
return this._lineSpacing;
},
set: function(value) {
if (value !== this._lineSpacing)
{
this._lineSpacing = parseFloat(value);
this.dirty = true;
if (this.parent)
{
this.updateTransform();
}
}
}
});
/**
* @name Phaser.Text#shadowOffsetX
* @property {number} shadowOffsetX - The shadowOffsetX value in pixels. This is how far offset horizontally the shadow effect will be.
*/
Object.defineProperty(Phaser.Text.prototype, 'shadowOffsetX', {
get: function() {
return this.style.shadowOffsetX;
},
set: function(value) {
if (value !== this.style.shadowOffsetX)
{
this.style.shadowOffsetX = value;
this.dirty = true;
}
}
});
/**
* @name Phaser.Text#shadowOffsetY
* @property {number} shadowOffsetY - The shadowOffsetY value in pixels. This is how far offset vertically the shadow effect will be.
*/
Object.defineProperty(Phaser.Text.prototype, 'shadowOffsetY', {
get: function() {
return this.style.shadowOffsetY;
},
set: function(value) {
if (value !== this.style.shadowOffsetY)
{
this.style.shadowOffsetY = value;
this.dirty = true;
}
}
});
/**
* @name Phaser.Text#shadowColor
* @property {string} shadowColor - The color of the shadow, as given in CSS rgba format. Set the alpha component to 0 to disable the shadow.
*/
Object.defineProperty(Phaser.Text.prototype, 'shadowColor', {
get: function() {
return this.style.shadowColor;
},
set: function(value) {
if (value !== this.style.shadowColor)
{
this.style.shadowColor = value;
this.dirty = true;
}
}
});
/**
* @name Phaser.Text#shadowBlur
* @property {number} shadowBlur - The shadowBlur value. Make the shadow softer by applying a Gaussian blur to it. A number from 0 (no blur) up to approx. 10 (depending on scene).
*/
Object.defineProperty(Phaser.Text.prototype, 'shadowBlur', {
get: function() {
return this.style.shadowBlur;
},
set: function(value) {
if (value !== this.style.shadowBlur)
{
this.style.shadowBlur = value;
this.dirty = true;
}
}
});
2015-07-22 14:31:30 +00:00
/**
* @name Phaser.Text#shadowStroke
* @property {boolean} shadowStroke - Sets if the drop shadow is applied to the Text stroke.
*/
Object.defineProperty(Phaser.Text.prototype, 'shadowStroke', {
get: function() {
return this.style.shadowStroke;
},
set: function(value) {
if (value !== this.style.shadowStroke)
{
this.style.shadowStroke = value;
this.dirty = true;
}
}
});
/**
* @name Phaser.Text#shadowFill
* @property {boolean} shadowFill - Sets if the drop shadow is applied to the Text fill.
*/
Object.defineProperty(Phaser.Text.prototype, 'shadowFill', {
get: function() {
return this.style.shadowFill;
},
set: function(value) {
if (value !== this.style.shadowFill)
{
this.style.shadowFill = value;
this.dirty = true;
}
}
});
/**
* @name Phaser.Text#width
* @property {number} width - The width of the Text. Setting this will modify the scale to achieve the value requested.
*/
Object.defineProperty(Phaser.Text.prototype, 'width', {
get: function() {
if (this.dirty)
{
this.updateText();
this.dirty = false;
}
return this.scale.x * this.texture.frame.width;
},
set: function(value) {
this.scale.x = value / this.texture.frame.width;
this._width = value;
}
});
/**
* @name Phaser.Text#height
* @property {number} height - The height of the Text. Setting this will modify the scale to achieve the value requested.
*/
Object.defineProperty(Phaser.Text.prototype, 'height', {
get: function() {
if (this.dirty)
{
this.updateText();
this.dirty = false;
}
return this.scale.y * this.texture.frame.height;
},
set: function(value) {
this.scale.y = value / this.texture.frame.height;
this._height = value;
}
});
Phaser.Text.fontPropertiesCache = {};
2015-08-24 14:43:45 +00:00
Phaser.Text.fontPropertiesCanvas = PIXI.CanvasPool.create(Phaser.Text.fontPropertiesCanvas);
2015-07-22 14:31:30 +00:00
Phaser.Text.fontPropertiesContext = Phaser.Text.fontPropertiesCanvas.getContext('2d');
2014-11-15 20:01:46 +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.
2014-11-15 20:01:46 +00:00
</span>
<br />
<span class="jsdoc-message">
2015-08-24 14:43:45 +00:00
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.2</a>
2016-02-18 14:41:53 +00:00
on Thu Feb 18 2016 14:40:58 GMT+0000 (GMT Standard Time) using the <a href="https://github.com/terryweiss/docstrap">DocStrap template</a>.
2014-11-15 20:01:46 +00:00
</span>
</footer>
</div>
<br clear="both">
</div>
</div>
<script src="scripts/sunlight.js"></script>
<script src="scripts/sunlight.javascript.js"></script>
<script src="scripts/sunlight-plugin.doclinks.js"></script>
<script src="scripts/sunlight-plugin.linenumbers.js"></script>
<script src="scripts/sunlight-plugin.menu.js"></script>
<script src="scripts/jquery.min.js"></script>
<script src="scripts/jquery.scrollTo.js"></script>
<script src="scripts/jquery.localScroll.js"></script>
<script src="scripts/bootstrap-dropdown.js"></script>
<script src="scripts/toc.js"></script>
<script> Sunlight.highlightAll({lineNumbers:true, showMenu: true, enableDoclinks :true}); </script>
<script>
$( function () {
$( "#toc" ).toc( {
anchorName : function(i, heading, prefix) {
return $(heading).attr("id") || ( prefix + i );
},
selectors : "h1,h2,h3,h4",
showAndHide : false,
scrollTo : 60
} );
$( "#toc>ul" ).addClass( "nav nav-pills nav-stacked" );
$( "#main span[id^='toc']" ).addClass( "toc-shim" );
} );
</script>
</body>
</html>