mirror of
https://github.com/photonstorm/phaser
synced 2024-11-10 07:04:31 +00:00
BitmapData.text will render the given string to the BitmapData, with optional font, color and shadow settings.
This commit is contained in:
parent
3c2725addc
commit
a67d2df6f0
2 changed files with 40 additions and 0 deletions
|
@ -64,6 +64,7 @@ Version 2.3.0 - "Tarabon" - in dev
|
|||
|
||||
* `Physics.Arcade.isPaused` allows you to toggle Arcade Physics processing on and off. If `true` the `Body.preUpdate` method will be skipped, halting all motion for all bodies. Note that other methods such as `collide` will still work, so be careful not to call them on paused bodies.
|
||||
* `Arcade.Body.friction` allows you to have more fine-grained control over the amount of velocity passed between bodies on collision.
|
||||
* BitmapData.text will render the given string to the BitmapData, with optional font, color and shadow settings.
|
||||
|
||||
### Updates
|
||||
|
||||
|
|
|
@ -1354,6 +1354,45 @@ Phaser.BitmapData.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Draws text to the BitmapData in the given font and color.
|
||||
* The default font is 14px Courier, so useful for quickly drawing debug text.
|
||||
* If you need to do a lot of font work to this BitmapData we'd recommend implementing your own text draw method.
|
||||
*
|
||||
* @method Phaser.BitmapData#text
|
||||
* @param {string} text - The text to write to the BitmapData.
|
||||
* @param {number} x - The x coordinate of the top-left of the text string.
|
||||
* @param {number} y - The y coordinate of the top-left of the text string.
|
||||
* @param {string} [font='14px Courier'] - The font. This is passed directly to Context.font, so anything that can support, this can.
|
||||
* @param {string} [color='rgb(255,255,255)'] - The color the text will be drawn in.
|
||||
* @param {boolean} [shadow=true] - Draw a single pixel black shadow below the text (offset by text.x/y + 1)
|
||||
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
|
||||
*/
|
||||
text: function (text, x, y, font, color, shadow) {
|
||||
|
||||
if (typeof x === 'undefined') { x = 0; }
|
||||
if (typeof y === 'undefined') { y = 0; }
|
||||
if (typeof font === 'undefined') { font = '14px Courier'; }
|
||||
if (typeof color === 'undefined') { color = 'rgb(255,255,255)'; }
|
||||
if (typeof shadow === 'undefined') { shadow = true; }
|
||||
|
||||
var prevFont = this.context.font;
|
||||
|
||||
this.context.font = font;
|
||||
|
||||
if (shadow)
|
||||
{
|
||||
this.context.fillStyle = 'rgb(0,0,0)';
|
||||
this.context.fillText(text, x + 1, y + 1);
|
||||
}
|
||||
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillText(text, x, y);
|
||||
|
||||
this.context.font = prevFont;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Draws a filled Circle to the BitmapData at the given x, y coordinates and radius in size.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue