mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Loader.script now has callback (and callbackContext) parameters, so you can specify a function to run once the JS has been injected into the body.
This commit is contained in:
parent
1aea08d0f7
commit
5ab104ad4b
5 changed files with 161 additions and 2 deletions
|
@ -117,6 +117,7 @@ New features:
|
|||
* Stage.smoothed allows you to set if sprites will be smoothed when rendered. Set to false if you're using pixel art in your game. Default is true. Works in Canvas and WebGL.
|
||||
* Sprite.smoothed and Image.smoothed allows you to set per-Sprite smoothing, perfect if you just want to keep a few sprites smoothed (or not)
|
||||
* StateManager.start can now have as many parameters as you like. The order is: start(key, clearWorld, clearCache, ...) - they are passed to State.init() (NOT create!)
|
||||
* Loader.script now has callback (and callbackContext) parameters, so you can specify a function to run once the JS has been injected into the body.
|
||||
|
||||
|
||||
Updates:
|
||||
|
|
72
examples/text/google webfonts.js
Normal file
72
examples/text/google webfonts.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });
|
||||
|
||||
// The Google WebFont Loader will look for this object, so create it before loading the script.
|
||||
WebFontConfig = {
|
||||
|
||||
// 'active' means all requested fonts have finished loading
|
||||
// We set a 1 second delay before calling 'createText'.
|
||||
// For some reason if we don't the browser cannot render the text the first time it's created.
|
||||
active: function() { game.time.events.add(Phaser.Timer.SECOND, createText, this); },
|
||||
|
||||
// The Google Fonts we want to load (specify as many as you like in the array)
|
||||
google: {
|
||||
families: ['Revalia']
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function preload() {
|
||||
|
||||
// Load the Google WebFont Loader script
|
||||
game.load.script('webfont', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js');
|
||||
|
||||
}
|
||||
|
||||
var text = null;
|
||||
var grd;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.setBackgroundColor(0x2d2d2d);
|
||||
|
||||
}
|
||||
|
||||
function createText() {
|
||||
|
||||
text = game.add.text(game.world.centerX, game.world.centerY, "- phaser -\nrocking with\ngoogle web fonts");
|
||||
text.anchor.setTo(0.5);
|
||||
|
||||
text.font = 'Revalia';
|
||||
text.fontSize = 60;
|
||||
|
||||
// x0, y0 - x1, y1
|
||||
grd = text.context.createLinearGradient(0, 0, 0, text.canvas.height);
|
||||
grd.addColorStop(0, '#8ED6FF');
|
||||
grd.addColorStop(1, '#004CB3');
|
||||
text.fill = grd;
|
||||
|
||||
text.align = 'center';
|
||||
text.stroke = '#000000';
|
||||
text.strokeThickness = 2;
|
||||
text.setShadow(5, 5, 'rgba(0,0,0,0.5)', 5);
|
||||
|
||||
text.inputEnabled = true;
|
||||
text.input.enableDrag();
|
||||
|
||||
text.events.onInputOver.add(over, this);
|
||||
text.events.onInputOut.add(out, this);
|
||||
|
||||
}
|
||||
|
||||
function out() {
|
||||
|
||||
text.fill = grd;
|
||||
|
||||
}
|
||||
|
||||
function over() {
|
||||
|
||||
text.fill = '#ff00ff';
|
||||
|
||||
}
|
72
examples/wip/google webfont.js
Normal file
72
examples/wip/google webfont.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });
|
||||
|
||||
// The Google WebFont Loader will look for this object, so create it before loading the script.
|
||||
WebFontConfig = {
|
||||
|
||||
// 'active' means all requested fonts have finished loading
|
||||
// We set a 1 second delay before calling 'createText'.
|
||||
// For some reason if we don't the browser cannot render the text the first time it's created.
|
||||
active: function() { game.time.events.add(Phaser.Timer.SECOND, createText, this); },
|
||||
|
||||
// The Google Fonts we want to load
|
||||
google: {
|
||||
families: ['Revalia', 'Droid Sans', 'Droid Serif']
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function preload() {
|
||||
|
||||
// Load the Google WebFont Loader script
|
||||
game.load.script('webfont', '//ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js');
|
||||
|
||||
}
|
||||
|
||||
var text = null;
|
||||
var grd;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.setBackgroundColor(0x2d2d2d);
|
||||
|
||||
}
|
||||
|
||||
function createText() {
|
||||
|
||||
text = game.add.text(game.world.centerX, game.world.centerY, "- phaser -\nrocking with\ngoogle web fonts");
|
||||
text.anchor.setTo(0.5);
|
||||
|
||||
text.font = 'Revalia';
|
||||
text.fontSize = 60;
|
||||
|
||||
// x0, y0 - x1, y1
|
||||
grd = text.context.createLinearGradient(0, 0, 0, text.canvas.height);
|
||||
grd.addColorStop(0, '#8ED6FF');
|
||||
grd.addColorStop(1, '#004CB3');
|
||||
text.fill = grd;
|
||||
|
||||
text.align = 'center';
|
||||
text.stroke = '#000000';
|
||||
text.strokeThickness = 2;
|
||||
text.setShadow(5, 5, 'rgba(0,0,0,0.5)', 5);
|
||||
|
||||
text.inputEnabled = true;
|
||||
text.input.enableDrag();
|
||||
|
||||
text.events.onInputOver.add(over, this);
|
||||
text.events.onInputOut.add(out, this);
|
||||
|
||||
}
|
||||
|
||||
function out() {
|
||||
|
||||
text.fill = grd;
|
||||
|
||||
}
|
||||
|
||||
function over() {
|
||||
|
||||
text.fill = '#ff00ff';
|
||||
|
||||
}
|
|
@ -85,6 +85,10 @@ Phaser.Group = function (game, parent, name, addToStage) {
|
|||
*/
|
||||
this.cursor = null;
|
||||
|
||||
/**
|
||||
* @property {number} _cursorIndex - Internal pointer.
|
||||
* @private
|
||||
*/
|
||||
this._cursorIndex = 0;
|
||||
|
||||
/**
|
||||
|
|
|
@ -389,15 +389,21 @@ Phaser.Loader.prototype = {
|
|||
|
||||
/**
|
||||
* Add a JavaScript file to the Loader. Once loaded the JavaScript file will be automatically turned into a script tag (and executed), so be careful what you load!
|
||||
* You can also specify a callback. This will be executed as soon as the script tag has been created.
|
||||
*
|
||||
* @method Phaser.Loader#script
|
||||
* @param {string} key - Unique asset key of the script file.
|
||||
* @param {string} url - URL of the JavaScript file.
|
||||
* @param {function} [callback] - Optional callback that will be called after the script tag has loaded, so you can perform additional processing.
|
||||
* @param {function} [callbackContext] - The context under which the callback will be applied. If not specified it will use the callback itself as the context.
|
||||
* @return {Phaser.Loader} This Loader instance.
|
||||
*/
|
||||
script: function (key, url) {
|
||||
script: function (key, url, callback, callbackContext) {
|
||||
|
||||
this.addToFileList('script', key, url);
|
||||
if (typeof callback === 'undefined') { callback = false; }
|
||||
if (callback !== false && typeof callbackContext === 'undefined') { callbackContext = callback; }
|
||||
|
||||
this.addToFileList('script', key, url, { callback: callback, callbackContext: callbackContext });
|
||||
|
||||
return this;
|
||||
|
||||
|
@ -1164,6 +1170,10 @@ Phaser.Loader.prototype = {
|
|||
file.data.defer = false;
|
||||
file.data.text = this._xhr.responseText;
|
||||
document.head.appendChild(file.data);
|
||||
if (file.callback)
|
||||
{
|
||||
file.data = file.callback.call(file.callbackContext, file.key, this._xhr.responseText);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'binary':
|
||||
|
|
Loading…
Add table
Reference in a new issue