mirror of
https://github.com/wassname/phaser.git
synced 2026-06-27 16:10:15 +08:00
More TypeScript updates.
This commit is contained in:
@@ -91,6 +91,7 @@ Updates:
|
||||
* ArcadePhysics.overlap and collide now recognise TileSprites in the collision checks.
|
||||
* Lots of documentation fixes in the Tween class.
|
||||
* Tweens fire an onLoop event if they are set to repeat. onComplete is now only fired for the final repeat (or never if the repeat is infinite)
|
||||
* Pointer used to un-pause a paused game every time it was clicked/touched (this avoided some rogue browser plugins). Now only happens if Stage.disableVisibilityChange is true.
|
||||
|
||||
|
||||
Bug Fixes:
|
||||
|
||||
Vendored
+57
-54
@@ -93,7 +93,7 @@ declare module Phaser {
|
||||
onPausedCallback(): void;
|
||||
onShutDownCallback(): void;
|
||||
boot(): void;
|
||||
add(key: string, state: Phaser.State, autoStart?: boolean): void;
|
||||
add(key: string, state: any, autoStart?: boolean): void;
|
||||
remove(key: string): void;
|
||||
start(key: string, clearWorld?: boolean, clearCache?: boolean): void;
|
||||
dummy(): void;
|
||||
@@ -677,57 +677,60 @@ declare module Phaser {
|
||||
renderTexture(key: string, width: number, height: number): Phaser.RenderTexture;
|
||||
}
|
||||
|
||||
class Sprite {
|
||||
constructor(game: Phaser.Game, x: number, y: number, key: string, frame: number);
|
||||
game: Phaser.Game;
|
||||
exists: boolean;
|
||||
alive: boolean;
|
||||
group: Phaser.Group;
|
||||
name: string;
|
||||
type: number;
|
||||
renderOrderID: number;
|
||||
lifespan: number;
|
||||
events: Phaser.Events;
|
||||
animations: Phaser.AnimationManager;
|
||||
input: Phaser.InputHandler;
|
||||
key: string;
|
||||
currentFrame: number;
|
||||
anchor: Phaser.Point;
|
||||
x: number;
|
||||
y: number;
|
||||
position: Phaser.Point;
|
||||
autoCull: boolean;
|
||||
scale: Phaser.Point;
|
||||
scrollFactor: Phaser.Point;
|
||||
offset: Phaser.Point;
|
||||
center: Phaser.Point;
|
||||
topLeft: Phaser.Point;
|
||||
topRight: Phaser.Point;
|
||||
bottomRight: Phaser.Point;
|
||||
bottomLeft: Phaser.Point;
|
||||
bounds: Phaser.Rectangle;
|
||||
body: Phaser.Physics.Arcade.Body;
|
||||
inWorld: boolean;
|
||||
inWorldThreshold: number;
|
||||
angle: number;
|
||||
frame: number;
|
||||
frameName: string;
|
||||
inCamera: boolean;
|
||||
crop: boolean;
|
||||
cropEnabled: boolean;
|
||||
inputEnabled: boolean;
|
||||
preUpdate(): void;
|
||||
postUpdate(): void;
|
||||
centerOn(x: number, y: number): void;
|
||||
revive(): void;
|
||||
kill(): void;
|
||||
reset(x: number, y: number): void;
|
||||
updateBounds(): void;
|
||||
getLocalPosition(p: Phaser.Point, x: number, y: number): Phaser.Point;
|
||||
getLocalUnmodifiedPosition(p: Phaser.Point, x: number, y: number): Phaser.Point;
|
||||
bringToTop(): void;
|
||||
getBounds(rect: Phaser.Rectangle): Phaser.Rectangle;
|
||||
}
|
||||
class Sprite {
|
||||
constructor(game: Phaser.Game, x: number, y: number, key: string, frame: number);
|
||||
game: Phaser.Game;
|
||||
exists: boolean;
|
||||
alive: boolean;
|
||||
group: Phaser.Group;
|
||||
name: string;
|
||||
type: number;
|
||||
renderOrderID: number;
|
||||
lifespan: number;
|
||||
events: Phaser.Events;
|
||||
animations: Phaser.AnimationManager;
|
||||
input: Phaser.InputHandler;
|
||||
key: string;
|
||||
currentFrame: number;
|
||||
anchor: Phaser.Point;
|
||||
x: number;
|
||||
y: number;
|
||||
position: Phaser.Point;
|
||||
autoCull: boolean;
|
||||
scale: Phaser.Point;
|
||||
scrollFactor: Phaser.Point;
|
||||
offset: Phaser.Point;
|
||||
center: Phaser.Point;
|
||||
topLeft: Phaser.Point;
|
||||
topRight: Phaser.Point;
|
||||
bottomRight: Phaser.Point;
|
||||
bottomLeft: Phaser.Point;
|
||||
bounds: Phaser.Rectangle;
|
||||
body: Phaser.Physics.Arcade.Body;
|
||||
inWorld: boolean;
|
||||
inWorldThreshold: number;
|
||||
angle: number;
|
||||
frame: number;
|
||||
frameName: string;
|
||||
inCamera: boolean;
|
||||
crop: boolean;
|
||||
cropEnabled: boolean;
|
||||
inputEnabled: boolean;
|
||||
preUpdate(): void;
|
||||
postUpdate(): void;
|
||||
centerOn(x: number, y: number): void;
|
||||
revive(): void;
|
||||
kill(): void;
|
||||
reset(x: number, y: number): void;
|
||||
updateBounds(): void;
|
||||
getLocalPosition(p: Phaser.Point, x: number, y: number): Phaser.Point;
|
||||
getLocalUnmodifiedPosition(p: Phaser.Point, x: number, y: number): Phaser.Point;
|
||||
bringToTop(): void;
|
||||
getBounds(rect: Phaser.Rectangle): Phaser.Rectangle;
|
||||
alpha: number;
|
||||
visible: boolean;
|
||||
renderable: boolean;
|
||||
}
|
||||
|
||||
class Events {
|
||||
parent: Phaser.Sprite;
|
||||
@@ -1424,8 +1427,8 @@ declare module Phaser {
|
||||
addToFileList(type: string, key: string, url: string, properties: Array<any>): void;
|
||||
image(key: string, url: string, overwrite?: boolean): void;
|
||||
text(key: string, url: string, overwrite?: boolean): void;
|
||||
spritesheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax?: number, margin?: number, spacing?: number): void;
|
||||
audio(key: string, urls: string[], autoDecode?: boolean): void;
|
||||
spritesheet(key: string, url: string, frameWidth: number, frameHeight: number, frameMax: number): void;
|
||||
audio(key: string, urls: any, autoDecode?: boolean): void;
|
||||
tilemap(key: string, tilesetURL: string, mapDataURL?: string, mapData?: Object, format?: string): void;
|
||||
tileset(key: string, url: string, tileWidth: number, tileHeight: number, tileMargin?: number, tileSpacing?: number, rows?: number, columns?: number, limit?: number): void;
|
||||
bitmapFont(key: string, textureURL: string, xmlURL?: string, xmlData?: Object): void;
|
||||
|
||||
+1
-3
@@ -179,15 +179,13 @@ Phaser.Cache.prototype = {
|
||||
* @method Phaser.Cache#addTilemap
|
||||
* @param {string} key - The unique key by which you will reference this object.
|
||||
* @param {string} url - URL of the tilemap image.
|
||||
* @param {object} mapData - The tilemap data object.
|
||||
* @param {object} mapData - The tilemap data object (either a CSV or JSON file).
|
||||
* @param {number} format - The format of the tilemap data.
|
||||
*/
|
||||
addTilemap: function (key, url, mapData, format) {
|
||||
|
||||
this._tilemaps[key] = { url: url, data: mapData, format: format };
|
||||
|
||||
this._tilemaps[key].layers = Phaser.TilemapParser.parse(this.game, mapData, format);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
+23
-17
@@ -21,28 +21,38 @@ Phaser.Tilemap = function (game, key, tilesets) {
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {string} key - The key of this map data in the Phaser.Cache.
|
||||
*/
|
||||
this.key = key;
|
||||
|
||||
var data = Phaser.TilemapParser.parse(this.game, key);
|
||||
|
||||
/**
|
||||
* @property {array} layers - An array of Tilemap layer data.
|
||||
*/
|
||||
this.layers = [];
|
||||
this.layers = data.layers;
|
||||
|
||||
if (typeof key === 'string')
|
||||
{
|
||||
this.key = key;
|
||||
/**
|
||||
* @property {array} tilesets - An array of Tilesets.
|
||||
*/
|
||||
this.tilesets = data.tilesets;
|
||||
|
||||
this.layers = game.cache.getTilemapData(key).layers;
|
||||
}
|
||||
/**
|
||||
* @property {array} objects - An array of Tiled Object Layers.
|
||||
*/
|
||||
this.objects = data.objects;
|
||||
|
||||
/**
|
||||
* @property {array} images - An array of Tiled Image Layers.
|
||||
*/
|
||||
this.images = data.images;
|
||||
|
||||
/**
|
||||
* @property {number} currentLayer - The current layer.
|
||||
*/
|
||||
this.currentLayer = 0;
|
||||
|
||||
/**
|
||||
* @property {array} tilesets - An array of Tilesets.
|
||||
*/
|
||||
this.tilesets = [];
|
||||
|
||||
/**
|
||||
* @property {array} debugMap - Map data used for debug values only.
|
||||
*/
|
||||
@@ -66,11 +76,6 @@ Phaser.Tilemap = function (game, key, tilesets) {
|
||||
*/
|
||||
this._tempB = 0;
|
||||
|
||||
if (this.layers.length > 0)
|
||||
{
|
||||
this.addTilesets(tilesets);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -87,6 +92,8 @@ Phaser.Tilemap.TILED_JSON = 1;
|
||||
|
||||
Phaser.Tilemap.prototype = {
|
||||
|
||||
|
||||
|
||||
addTilesets: function (tilesets) {
|
||||
|
||||
// { "TiledKey": "TilesetKey" }
|
||||
@@ -128,7 +135,6 @@ Phaser.Tilemap.prototype = {
|
||||
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Creates an empty map of the given dimensions.
|
||||
*
|
||||
|
||||
@@ -69,19 +69,27 @@ Phaser.TilemapParser = {
|
||||
* Parse tileset data from the cache and creates a Tileset object.
|
||||
* @method Phaser.TilemapParser.parse
|
||||
* @param {Phaser.Game} game - Game reference to the currently running game.
|
||||
* @param {object} data
|
||||
* @param {string} format
|
||||
* @return {Phaser.Tileset} Generated Tileset object.
|
||||
* @param {string} key - The key of the tilemap in the Cache.
|
||||
* @return {object} The parsed map object.
|
||||
*/
|
||||
parse: function (game, data, format) {
|
||||
parse: function (game, key) {
|
||||
|
||||
if (format === Phaser.Tilemap.CSV)
|
||||
var map = game.cache.getTilemapData(key);
|
||||
|
||||
if (map)
|
||||
{
|
||||
return this.parseCSV(data);
|
||||
if (map.format === Phaser.Tilemap.CSV)
|
||||
{
|
||||
return this.parseCSV(map.data);
|
||||
}
|
||||
else if (map.format === Phaser.Tilemap.TILED_JSON)
|
||||
{
|
||||
return this.parseTiledJSON(map.data);
|
||||
}
|
||||
}
|
||||
else if (format === Phaser.Tilemap.TILED_JSON)
|
||||
else
|
||||
{
|
||||
return this.parseTiledJSON(data);
|
||||
return { layers: [], objects: [], images: [], tilesets: [] };
|
||||
}
|
||||
|
||||
},
|
||||
@@ -128,8 +136,8 @@ Phaser.TilemapParser = {
|
||||
/**
|
||||
* Parses a Tiled JSON file into valid map data.
|
||||
* @method Phaser.TilemapParser.parseJSON
|
||||
* @param {object} json - The Tiled JSON data.
|
||||
* @return {object} Generated map data.
|
||||
* @param {object} json - The JSON map data.
|
||||
* @return {object} Generated and parsed map data.
|
||||
*/
|
||||
parseTiledJSON: function (json) {
|
||||
|
||||
@@ -278,6 +286,41 @@ Phaser.TilemapParser = {
|
||||
// Tilesets
|
||||
var tilesets = [];
|
||||
|
||||
|
||||
/*
|
||||
// for (var i = this.firstgid; i < this.firstgid + this.total; i++)
|
||||
for (var i = 0; i < this.total; i++)
|
||||
{
|
||||
// Can add extra properties here as needed
|
||||
this.tiles[i] = [x, y];
|
||||
|
||||
x += this.tileWidth + this.tileSpacing;
|
||||
|
||||
count++;
|
||||
|
||||
if (count === this.total)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
countX++;
|
||||
|
||||
if (countX === this.rows)
|
||||
{
|
||||
x = this.tileMargin;
|
||||
y += this.tileHeight + this.tileSpacing;
|
||||
|
||||
countX = 0;
|
||||
countY++;
|
||||
|
||||
if (countY === this.columns)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
/*
|
||||
{
|
||||
"firstgid":1,
|
||||
@@ -302,10 +345,34 @@ Phaser.TilemapParser = {
|
||||
"tilewidth":32
|
||||
},
|
||||
|
||||
|
||||
Create 1 Tileset object that contains the above, but NOT the actual tile indexes
|
||||
Put the tile indexes into a global array (tiles?) - just need x,y + img - a drawImage look-up table
|
||||
|
||||
*/
|
||||
|
||||
for (var i = 0; i < json.tilesets.length; i++)
|
||||
{
|
||||
// name, firstgid, width, height, margin, spacing, properties
|
||||
var set = json.tilesets[i];
|
||||
var newSet = new Phaser.Tileset(set.name, set.firstgid, set.tilewidth, set.tileheight, set.margin, set.spacing, set.properties);
|
||||
|
||||
if (set.tileproperties)
|
||||
{
|
||||
newSet.tileProperties = set.tileproperties;
|
||||
}
|
||||
|
||||
// rows, columns, total
|
||||
var rows = set.imageheight / set.tileheight;
|
||||
var columns = set.imagewidth / set.tilewidth;
|
||||
var total = rows * columns;
|
||||
|
||||
newSet.rows = rows;
|
||||
newSet.columns = columns;
|
||||
newSet.total = total;
|
||||
|
||||
tilesets.push(newSet);
|
||||
|
||||
}
|
||||
|
||||
// Lets build our super tileset index
|
||||
|
||||
+48
-32
@@ -10,8 +10,7 @@
|
||||
*
|
||||
* @class Phaser.Tileset
|
||||
* @constructor
|
||||
* @param {Image} image - The Image object from the Cache.
|
||||
* @param {string} key - The key of the tileset in the cache.
|
||||
* @param {string} name - The name of the tileset in the map data.
|
||||
* @param {number} tileWidth - Width of each tile in pixels.
|
||||
* @param {number} tileHeight - Height of each tile in pixels.
|
||||
* @param {number} tileMargin - The amount of margin around the tilesheet.
|
||||
@@ -20,65 +19,82 @@
|
||||
* @param {number} columns - How many tiles are placed vertically in each column.
|
||||
* @param {number} total - The maximum number of tiles to extract from the image.
|
||||
*/
|
||||
Phaser.Tileset = function (image, key, tileWidth, tileHeight, tileMargin, tileSpacing, rows, columns, total) {
|
||||
Phaser.Tileset = function (name, firstgid, width, height, margin, spacing, properties) {
|
||||
|
||||
/**
|
||||
* @property {string} key - The cache ID.
|
||||
* @property {string} name - The name of the Tileset.
|
||||
*/
|
||||
this.key = key;
|
||||
|
||||
/**
|
||||
* @property {object} image - The image used for rendering.
|
||||
*/
|
||||
this.image = image;
|
||||
|
||||
/**
|
||||
* @property {number} rows - The number of rows in the tile sheet.
|
||||
*/
|
||||
this.rows = rows;
|
||||
|
||||
/**
|
||||
* @property {number} columns - The number of columns in the tile sheet.
|
||||
*/
|
||||
this.columns = columns;
|
||||
|
||||
/**
|
||||
* @property {number} total - The total number of tiles in the tilesheet.
|
||||
*/
|
||||
this.total = total;
|
||||
this.name = name;
|
||||
|
||||
/**
|
||||
* @property {number} firstgid - The Tiled firstgid value.
|
||||
* @default
|
||||
*/
|
||||
this.firstgid = 1;
|
||||
this.firstgid = firstgid;
|
||||
|
||||
/**
|
||||
* @property {number} tileWidth - The width of a tile in pixels.
|
||||
*/
|
||||
this.tileWidth = tileWidth;
|
||||
this.tileWidth = width;
|
||||
|
||||
/**
|
||||
* @property {number} tileHeight - The height of a tile in pixels.
|
||||
*/
|
||||
this.tileHeight = tileHeight;
|
||||
this.tileHeight = height;
|
||||
|
||||
/**
|
||||
* @property {number} tileMargin - The margin around the tiles in the sheet.
|
||||
*/
|
||||
this.tileMargin = tileMargin;
|
||||
this.tileMargin = margin;
|
||||
|
||||
/**
|
||||
* @property {number} tileSpacing - The margin around the tiles in the sheet.
|
||||
*/
|
||||
this.tileSpacing = tileSpacing;
|
||||
this.tileSpacing = spacing;
|
||||
|
||||
/**
|
||||
* @property {object} properties - Tileset specific properties (typically defined in the Tiled editor).
|
||||
*/
|
||||
this.properties = properties;
|
||||
|
||||
/**
|
||||
* @property {object} tilePproperties - Tile specific properties (typically defined in the Tiled editor).
|
||||
*/
|
||||
this.tileProperties = {};
|
||||
|
||||
/**
|
||||
* @property {string} key - The cache ID.
|
||||
*/
|
||||
// this.key = key;
|
||||
|
||||
/**
|
||||
* @property {object} image - The image used for rendering.
|
||||
*/
|
||||
this.image = null;
|
||||
|
||||
/**
|
||||
* @property {number} rows - The number of rows in the tile sheet.
|
||||
*/
|
||||
this.rows = 0;
|
||||
|
||||
/**
|
||||
* @property {number} columns - The number of columns in the tile sheet.
|
||||
*/
|
||||
this.columns = 0;
|
||||
|
||||
/**
|
||||
* @property {number} total - The total number of tiles in the tilesheet.
|
||||
*/
|
||||
this.total = 0;
|
||||
|
||||
/**
|
||||
* @property {array} tiles - An array of the tile data.
|
||||
*/
|
||||
this.tiles = [];
|
||||
// this.tiles = [];
|
||||
|
||||
// this.build();
|
||||
|
||||
|
||||
this.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user