mirror of
https://github.com/wassname/phaser.git
synced 2026-08-13 12:30:11 +08:00
Preparing for new release
This commit is contained in:
+170
-163
@@ -1,205 +1,212 @@
|
||||
/// <reference path="Game.ts" />
|
||||
|
||||
class DynamicTexture {
|
||||
/**
|
||||
* Phaser
|
||||
*/
|
||||
|
||||
constructor(game: Game, key: string, width: number, height: number) {
|
||||
module Phaser {
|
||||
|
||||
this._game = game;
|
||||
export class DynamicTexture {
|
||||
|
||||
this.canvas = <HTMLCanvasElement> document.createElement('canvas');
|
||||
this.canvas.width = width;
|
||||
this.canvas.height = height;
|
||||
this.context = this.canvas.getContext('2d');
|
||||
constructor(game: Game, key: string, width: number, height: number) {
|
||||
|
||||
this.bounds = new Rectangle(0, 0, width, height);
|
||||
this._game = game;
|
||||
|
||||
}
|
||||
this.canvas = <HTMLCanvasElement> document.createElement('canvas');
|
||||
this.canvas.width = width;
|
||||
this.canvas.height = height;
|
||||
this.context = this.canvas.getContext('2d');
|
||||
|
||||
private _game: Game;
|
||||
this.bounds = new Rectangle(0, 0, width, height);
|
||||
|
||||
private _sx: number = 0;
|
||||
private _sy: number = 0;
|
||||
private _sw: number = 0;
|
||||
private _sh: number = 0;
|
||||
private _dx: number = 0;
|
||||
private _dy: number = 0;
|
||||
private _dw: number = 0;
|
||||
private _dh: number = 0;
|
||||
}
|
||||
|
||||
// Input / Output nodes?
|
||||
private _game: Game;
|
||||
|
||||
public bounds: Rectangle;
|
||||
public canvas: HTMLCanvasElement;
|
||||
public context: CanvasRenderingContext2D;
|
||||
private _sx: number = 0;
|
||||
private _sy: number = 0;
|
||||
private _sw: number = 0;
|
||||
private _sh: number = 0;
|
||||
private _dx: number = 0;
|
||||
private _dy: number = 0;
|
||||
private _dw: number = 0;
|
||||
private _dh: number = 0;
|
||||
|
||||
public getPixel(x: number, y: number): number {
|
||||
// Input / Output nodes?
|
||||
|
||||
//r = imageData.data[0];
|
||||
//g = imageData.data[1];
|
||||
//b = imageData.data[2];
|
||||
//a = imageData.data[3];
|
||||
var imageData = this.context.getImageData(x, y, 1, 1);
|
||||
public bounds: Rectangle;
|
||||
public canvas: HTMLCanvasElement;
|
||||
public context: CanvasRenderingContext2D;
|
||||
|
||||
return this.getColor(imageData.data[0], imageData.data[1], imageData.data[2]);
|
||||
public getPixel(x: number, y: number): number {
|
||||
|
||||
}
|
||||
//r = imageData.data[0];
|
||||
//g = imageData.data[1];
|
||||
//b = imageData.data[2];
|
||||
//a = imageData.data[3];
|
||||
var imageData = this.context.getImageData(x, y, 1, 1);
|
||||
|
||||
public getPixel32(x: number, y: number) {
|
||||
return this.getColor(imageData.data[0], imageData.data[1], imageData.data[2]);
|
||||
|
||||
var imageData = this.context.getImageData(x, y, 1, 1);
|
||||
}
|
||||
|
||||
return this.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
|
||||
|
||||
}
|
||||
public getPixel32(x: number, y: number) {
|
||||
|
||||
// Returns a CanvasPixelArray
|
||||
public getPixels(rect:Rectangle) {
|
||||
|
||||
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
|
||||
|
||||
}
|
||||
var imageData = this.context.getImageData(x, y, 1, 1);
|
||||
|
||||
public setPixel(x: number, y: number, color:number) {
|
||||
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(x, y, 1, 1);
|
||||
|
||||
}
|
||||
return this.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
|
||||
|
||||
public setPixel32(x: number, y: number, color:number) {
|
||||
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(x, y, 1, 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public setPixels(rect:Rectangle, input) {
|
||||
// Returns a CanvasPixelArray
|
||||
public getPixels(rect: Rectangle) {
|
||||
|
||||
this.context.putImageData(input, rect.x, rect.y);
|
||||
|
||||
}
|
||||
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
|
||||
|
||||
public fillRect(rect: Rectangle, color: number) {
|
||||
}
|
||||
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(rect.x, rect.y, rect.width, rect.height);
|
||||
public setPixel(x: number, y: number, color: number) {
|
||||
|
||||
}
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(x, y, 1, 1);
|
||||
|
||||
public pasteImage(key: string, frame?: number = -1, destX?: number = 0, destY?: number = 0, destWidth?: number = null, destHeight?: number = null) {
|
||||
}
|
||||
|
||||
var texture = null;
|
||||
var frameData;
|
||||
public setPixel32(x: number, y: number, color: number) {
|
||||
|
||||
this._sx = 0;
|
||||
this._sy = 0;
|
||||
this._dx = destX;
|
||||
this._dy = destY;
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(x, y, 1, 1);
|
||||
|
||||
// TODO - Load a frame from a sprite sheet, otherwise we'll draw the whole lot
|
||||
if (frame > -1)
|
||||
{
|
||||
//if (this._game.cache.isSpriteSheet(key))
|
||||
//{
|
||||
// texture = this._game.cache.getImage(key);
|
||||
}
|
||||
|
||||
public setPixels(rect: Rectangle, input) {
|
||||
|
||||
this.context.putImageData(input, rect.x, rect.y);
|
||||
|
||||
}
|
||||
|
||||
public fillRect(rect: Rectangle, color: number) {
|
||||
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(rect.x, rect.y, rect.width, rect.height);
|
||||
|
||||
}
|
||||
|
||||
public pasteImage(key: string, frame?: number = -1, destX?: number = 0, destY?: number = 0, destWidth?: number = null, destHeight?: number = null) {
|
||||
|
||||
var texture = null;
|
||||
var frameData;
|
||||
|
||||
this._sx = 0;
|
||||
this._sy = 0;
|
||||
this._dx = destX;
|
||||
this._dy = destY;
|
||||
|
||||
// TODO - Load a frame from a sprite sheet, otherwise we'll draw the whole lot
|
||||
if (frame > -1)
|
||||
{
|
||||
//if (this._game.cache.isSpriteSheet(key))
|
||||
//{
|
||||
// texture = this._game.cache.getImage(key);
|
||||
//this.animations.loadFrameData(this._game.cache.getFrameData(key));
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
texture = this._game.cache.getImage(key);
|
||||
this._sw = texture.width;
|
||||
this._sh = texture.height;
|
||||
this._dw = texture.width;
|
||||
this._dh = texture.height;
|
||||
//}
|
||||
}
|
||||
else
|
||||
{
|
||||
texture = this._game.cache.getImage(key);
|
||||
this._sw = texture.width;
|
||||
this._sh = texture.height;
|
||||
this._dw = texture.width;
|
||||
this._dh = texture.height;
|
||||
}
|
||||
|
||||
if (destWidth !== null)
|
||||
{
|
||||
this._dw = destWidth;
|
||||
}
|
||||
|
||||
if (destHeight !== null)
|
||||
{
|
||||
this._dh = destHeight;
|
||||
}
|
||||
|
||||
if (texture != null)
|
||||
{
|
||||
this.context.drawImage(
|
||||
texture, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
this._sw, // Source Width
|
||||
this._sh, // Source Height
|
||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._dy, // Destination Y
|
||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (destWidth !== null)
|
||||
{
|
||||
this._dw = destWidth;
|
||||
// TODO - Add in support for: alphaBitmapData: BitmapData = null, alphaPoint: Point = null, mergeAlpha: bool = false
|
||||
public copyPixels(sourceTexture: DynamicTexture, sourceRect: Rectangle, destPoint: Point) {
|
||||
|
||||
// Swap for drawImage if the sourceRect is the same size as the sourceTexture to avoid a costly getImageData call
|
||||
if (sourceRect.equals(this.bounds) == true)
|
||||
{
|
||||
this.context.drawImage(sourceTexture.canvas, destPoint.x, destPoint.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.context.putImageData(sourceTexture.getPixels(sourceRect), destPoint.x, destPoint.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (destHeight !== null)
|
||||
{
|
||||
this._dh = destHeight;
|
||||
public clear() {
|
||||
|
||||
this.context.clearRect(0, 0, this.bounds.width, this.bounds.height);
|
||||
|
||||
}
|
||||
|
||||
if (texture != null)
|
||||
{
|
||||
this.context.drawImage(
|
||||
texture, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
this._sw, // Source Width
|
||||
this._sh, // Source Height
|
||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._dy, // Destination Y
|
||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
||||
);
|
||||
public get width(): number {
|
||||
return this.bounds.width;
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
return this.bounds.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an alpha and 3 color values this will return an integer representation of it
|
||||
*
|
||||
* @param alpha The Alpha value (between 0 and 255)
|
||||
* @param red The Red channel value (between 0 and 255)
|
||||
* @param green The Green channel value (between 0 and 255)
|
||||
* @param blue The Blue channel value (between 0 and 255)
|
||||
*
|
||||
* @return A native color value integer (format: 0xAARRGGBB)
|
||||
*/
|
||||
private getColor32(alpha: number, red: number, green: number, blue: number): number {
|
||||
|
||||
return alpha << 24 | red << 16 | green << 8 | blue;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Given 3 color values this will return an integer representation of it
|
||||
*
|
||||
* @param red The Red channel value (between 0 and 255)
|
||||
* @param green The Green channel value (between 0 and 255)
|
||||
* @param blue The Blue channel value (between 0 and 255)
|
||||
*
|
||||
* @return A native color value integer (format: 0xRRGGBB)
|
||||
*/
|
||||
private getColor(red: number, green: number, blue: number): number {
|
||||
|
||||
return red << 16 | green << 8 | blue;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO - Add in support for: alphaBitmapData: BitmapData = null, alphaPoint: Point = null, mergeAlpha: bool = false
|
||||
public copyPixels(sourceTexture: DynamicTexture, sourceRect: Rectangle, destPoint: Point) {
|
||||
|
||||
// Swap for drawImage if the sourceRect is the same size as the sourceTexture to avoid a costly getImageData call
|
||||
if (sourceRect.equals(this.bounds) == true)
|
||||
{
|
||||
this.context.drawImage(sourceTexture.canvas, destPoint.x, destPoint.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.context.putImageData(sourceTexture.getPixels(sourceRect), destPoint.x, destPoint.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public clear() {
|
||||
|
||||
this.context.clearRect(0, 0, this.bounds.width, this.bounds.height);
|
||||
|
||||
}
|
||||
|
||||
public get width(): number {
|
||||
return this.bounds.width;
|
||||
}
|
||||
|
||||
public get height(): number {
|
||||
return this.bounds.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an alpha and 3 color values this will return an integer representation of it
|
||||
*
|
||||
* @param alpha The Alpha value (between 0 and 255)
|
||||
* @param red The Red channel value (between 0 and 255)
|
||||
* @param green The Green channel value (between 0 and 255)
|
||||
* @param blue The Blue channel value (between 0 and 255)
|
||||
*
|
||||
* @return A native color value integer (format: 0xAARRGGBB)
|
||||
*/
|
||||
private getColor32(alpha: number, red: number, green: number, blue: number): number {
|
||||
|
||||
return alpha << 24 | red << 16 | green << 8 | blue;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Given 3 color values this will return an integer representation of it
|
||||
*
|
||||
* @param red The Red channel value (between 0 and 255)
|
||||
* @param green The Green channel value (between 0 and 255)
|
||||
* @param blue The Blue channel value (between 0 and 255)
|
||||
*
|
||||
* @return A native color value integer (format: 0xRRGGBB)
|
||||
*/
|
||||
private getColor(red: number, green: number, blue: number): number {
|
||||
|
||||
return red << 16 | green << 8 | blue;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user