Skip to content

Commit

Permalink
Fix ScaleManager and Sprite.crop bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
playif committed Sep 1, 2014
1 parent 64eab05 commit e22ffb9
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 54 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -100,6 +100,10 @@ The number of examples for each class.

Change log
==========
0.10.2
* Fix a ScaleManager bug (thanks to [#4](https://github.com/playif/play_phaser/issues/4)).
* Fix a Sprite.crop bug (thanks to [#5](https://github.com/playif/play_phaser/issues/5)).

0.10.1
* Add types to all functions and Signals.

Expand Down
30 changes: 9 additions & 21 deletions example/basics/basic_01_load_an_image.dart
Expand Up @@ -3,11 +3,10 @@ part of example;

class basic_01_load_an_image extends State {

Text text;
Sprite image;

preload() {
//Phaser.Easing.Linear.None;

// You can fill the preloader with as many assets as your game requires

// Here we are loading an image. The first parameter is the unique
Expand All @@ -19,30 +18,19 @@ class basic_01_load_an_image extends State {
}

create() {

// This creates a simple sprite that is using our loaded image and
// displays it on-screen
for (int i = 0; i < 10; i++) {
var image = game.add.sprite(game.world.centerX, game.world.centerY, 'car');

// Moves the image anchor to the middle, so it centers inside the game properly
image.anchor.set(0.5);

image.scale.set(2);
image.position.set(game.rnd.integerInRange(0, 800), game.rnd.integerInRange(0, 600));
image = game.add.sprite(game.world.centerX, game.world.centerY, 'car');

// Enables all kind of input actions on this image (click, etc)
image.inputEnabled = true;

// When moving on the image, kill it.
image.events.onInputOver.add((Sprite s, Pointer p) {
image.kill();
});
}

// Add a text
text = game.add.text(250, 16, 'Hello World!!', new TextStyle(fill:'#ffffff'));
// Moves the image anchor to the middle, so it centers inside the game properly
image.anchor.set(0.5);

image.scale.set(2);
}

update() {
image.angle += 1;
}

}
8 changes: 8 additions & 0 deletions example/main.dart
Expand Up @@ -53,6 +53,9 @@ part "camera/camera_03_camera_view.dart";
part "tilemaps/tilemaps_01_blank_map.dart";
part "tilemaps/tilemaps_16_tilemap_ray_cast.dart";

part "sprites/sprites_06_dynamic_crop.dart";
part "sprites/sprites_09_horizontal_crop.dart";

part "display/display_01_alpha_mask.dart";
part "display/display_02_bitmapdata_atlas.dart";
part "display/display_14_bitmapdata_wobble.dart";
Expand Down Expand Up @@ -125,6 +128,11 @@ Map<String, State> examples = {
"tilemaps_01_blank_map": new tilemaps_01_blank_map(),
"tilemaps_16_tilemap_ray_cast": new tilemaps_16_tilemap_ray_cast(),


"sprites_06_dynamic_crop": new sprites_06_dynamic_crop(),
"sprites_09_horizontal_crop": new sprites_09_horizontal_crop(),


"display_01_alpha_mask":new display_01_alpha_mask(),
"display_02_bitmapdata_atlas":new display_02_bitmapdata_atlas(),
"display_14_bitmapdata_wobble":new display_14_bitmapdata_wobble(),
Expand Down
42 changes: 42 additions & 0 deletions example/sprites/sprites_06_dynamic_crop.dart
@@ -0,0 +1,42 @@
part of example;

class sprites_06_dynamic_crop extends State {
preload() {
game.load.image('trsi', 'assets/pics/trsipic1_lazur.jpg');
}

Sprite pic;
Rectangle cropRect;
num w;
num h;

create() {

pic = game.add.sprite(0, 0, 'trsi');

w = pic.width;
h = pic.height;

cropRect = new Rectangle(0, 0, 128, 128);

pic.crop(cropRect);

}

update() {

if (game.input.x < w && game.input.y < h) {
pic.x = game.input.x;
pic.y = game.input.y;
cropRect.x = game.input.x;
cropRect.y = game.input.y;

pic.updateCrop();
}

}

render() {
game.debug.text('x: ' + game.input.x.toString() + ' y: ' + game.input.y.toString(), 32, 32);
}
}
33 changes: 33 additions & 0 deletions example/sprites/sprites_09_horizontal_crop.dart
@@ -0,0 +1,33 @@
part of example;

class sprites_09_horizontal_crop extends State{
preload() {
game.load.image('trsi', 'assets/pics/trsipic1_lazur.jpg');
}

Sprite pic;
Rectangle cropRect;

create() {

pic = game.add.sprite(game.world.centerX, 550, 'trsi');

pic.anchor.setTo(0.5, 1);

cropRect = new Rectangle(0, 0, 0, pic.height);

// Here we'll tween the crop rect, from a width of zero to full width, and back again
Tween tween = game.add.tween(cropRect).to( { 'width': pic.width }, 3000, Easing.Bounce.Out, false, 0, 1000, true);

pic.crop(cropRect);

tween.start();

}

update () {

pic.updateCrop();

}
}
11 changes: 5 additions & 6 deletions lib/core/scale_manager.dart
Expand Up @@ -734,10 +734,6 @@ class ScaleManager {

setScreenSize([bool force=false]) {

// if (force == null) {
// force = false;
// }

if (!this.game.device.iPad && !this.game.device.webApp && !this.game.device.desktop) {
if (this.game.device.android && !this.game.device.chrome) {
window.scrollTo(0, 1);
Expand Down Expand Up @@ -774,8 +770,11 @@ class ScaleManager {
}

this.setSize();
this._check.cancel();
this._check = null;

if(this._check != null){
this._check.cancel();
this._check = null;
}
}

}
Expand Down
23 changes: 2 additions & 21 deletions lib/gameobjects/sprite.dart
Expand Up @@ -2,25 +2,6 @@ part of Phaser;

class Sprite extends PIXI.Sprite implements GameObject, AnimationInterface {

// int getTweenableValues(int tweenType, List<num> returnValues) {
// switch (tweenType) {
// case 0:
// returnValues[0]=this.x;
// break;
// }
//
// return 1;
// }
//
// void setTweenableValues(int tweenType, List<num> newValues) {
// switch (tweenType) {
// case 0:
// this.x=newValues[0];
// break;
// }
//
// }


Game game;

Expand Down Expand Up @@ -640,8 +621,8 @@ class Sprite extends PIXI.Sprite implements GameObject, AnimationInterface {
return;
}

this.cropRect.clone(this._crop);
//this._crop = Rectangle.clone(this.cropRect, this._crop);
this._crop = this.cropRect.clone();

this._crop.x += this._frame.x;
this._crop.y += this._frame.y;

Expand Down
10 changes: 5 additions & 5 deletions lib/tilemap/tile.dart
Expand Up @@ -26,7 +26,7 @@ class Tile {

num alpha;

Map properties;
Map<String, String> properties;

bool scanned;

Expand All @@ -46,9 +46,9 @@ class Tile {

bool collideDown;

bool collides=false;
bool debug=false;
bool collides = false;

bool debug = false;


Function collisionCallback;
Expand Down Expand Up @@ -380,7 +380,7 @@ class Tile {

if (collides && faces) {
// Does this tile have any collide flags OR interesting face?
return (this.collideLeft || this.collideRight || this.collideUp || this.collideDown || this.faceTop || this.faceBottom || this.faceLeft || this.faceRight || this.collisionCallback !=null);
return (this.collideLeft || this.collideRight || this.collideUp || this.collideDown || this.faceTop || this.faceBottom || this.faceLeft || this.faceRight || this.collisionCallback != null);
}
else if (collides) {
// Does this tile collide?
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,5 +1,5 @@
name: play_phaser
version: 0.10.1
version: 0.10.2
description:
A Dart port for Phaser.js library.
author: playif <playif@gmail.com>
Expand Down

0 comments on commit e22ffb9

Please sign in to comment.