Skip to content

Commit

Permalink
If Game Objects change their frame, such as with an animated Sprite, …
Browse files Browse the repository at this point in the history
…and the change goes from a previously trimmed frame to a non-trimmed (full size) one, then the previous trim values were still left active, causing it to glitch (thanks stupot)
  • Loading branch information
photonstorm committed Sep 11, 2014
1 parent bb8da11 commit 60acef2
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 35 deletions.
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,23 @@ Finally the list of [community authored Phaser Tutorials](http://www.lessmilk.co

Version 2.1.2 - "Whitebridge" - in development



### New Features



### Updates

* TypeScript definitions fixes and updates (thanks @clark-stevenson @englercj)



### Bug Fixes

* If Game Objects change their frame, such as with an animated Sprite, and the change goes from a previously trimmed frame to a non-trimmed (full size) one, then the previous trim values were still left active, causing it to glitch (thanks stupot)


For details about changes made in previous versions of Phaser see the full Change Log at https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md

![div](http://phaser.io/images/div3.png)
Expand Down Expand Up @@ -127,11 +138,11 @@ Nice and easy :)

Phaser is now available on [CDNJS](http://cdnjs.com). You can include the following in your html:

`http://cdnjs.cloudflare.com/ajax/libs/phaser/2.1.0/phaser.min.js`
`http://cdnjs.cloudflare.com/ajax/libs/phaser/2.1.2/phaser.min.js`

Or if you prefer you can leave the protocol off, so it works via http and https:

`//cdnjs.cloudflare.com/ajax/libs/phaser/2.1.0/phaser.min.js`
`//cdnjs.cloudflare.com/ajax/libs/phaser/2.1.2/phaser.min.js`

![div](http://phaser.io/images/div1.png)

Expand Down
66 changes: 33 additions & 33 deletions resources/Project Templates/Basic/Game.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@

BasicGame.Game = function (game) {

// When a State is added to Phaser it automatically has the following properties set on it, even if they already exist:

this.game; // a reference to the currently running game
this.add; // used to add sprites, text, groups, etc
this.camera; // a reference to the game camera
this.cache; // the game cache
this.input; // the global input manager (you can access this.input.keyboard, this.input.mouse, as well from it)
this.load; // for preloading assets
this.math; // lots of useful common math operations
this.sound; // the sound manager - add a sound, play one, set-up markers, etc
this.stage; // the game stage
this.time; // the clock
this.tweens; // the tween manager
this.state; // the state manager
this.world; // the game world
this.particles; // the particle manager
this.physics; // the physics manager
this.rnd; // the repeatable random number generator

// You can use any of these from any function within this State.
// But do consider them as being 'reserved words', i.e. don't create a property for your own game called "world" or you'll over-write the world reference.
// When a State is added to Phaser it automatically has the following properties set on it, even if they already exist:

this.game; // a reference to the currently running game (Phaser.Game)
this.add; // used to add sprites, text, groups, etc (Phaser.GameObjectFactory)
this.camera; // a reference to the game camera (Phaser.Camera)
this.cache; // the game cache (Phaser.Cache)
this.input; // the global input manager. You can access this.input.keyboard, this.input.mouse, as well from it. (Phaser.Input)
this.load; // for preloading assets (Phaser.Loader)
this.math; // lots of useful common math operations (Phaser.Math)
this.sound; // the sound manager - add a sound, play one, set-up markers, etc (Phaser.SoundManager)
this.stage; // the game stage (Phaser.Stage)
this.time; // the clock (Phaser.Time)
this.tweens; // the tween manager (Phaser.TweenManager)
this.state; // the state manager (Phaser.StateManager)
this.world; // the game world (Phaser.World)
this.particles; // the particle manager (Phaser.Particles)
this.physics; // the physics manager (Phaser.Physics)
this.rnd; // the repeatable random number generator (Phaser.RandomDataGenerator)

// You can use any of these from any function within this State.
// But do consider them as being 'reserved words', i.e. don't create a property for your own game called "world" or you'll over-write the world reference.

};

BasicGame.Game.prototype = {

create: function () {
create: function () {

// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!
// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!

},
},

update: function () {
update: function () {

// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!
// Honestly, just about anything could go here. It's YOUR game after all. Eat your heart out!

},
},

quitGame: function (pointer) {
quitGame: function (pointer) {

// Here you should destroy anything you no longer need.
// Stop music, delete sprites, purge caches, free resources, all that good stuff.
// Here you should destroy anything you no longer need.
// Stop music, delete sprites, purge caches, free resources, all that good stuff.

// Then let's go back to the main menu.
this.state.start('MainMenu');
// Then let's go back to the main menu.
this.state.start('MainMenu');

}
}

};
4 changes: 4 additions & 0 deletions src/gameobjects/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ Phaser.Image.prototype.setFrame = function(frame) {
this.texture.frame.width = frame.sourceSizeW;
this.texture.frame.height = frame.sourceSizeH;
}
else if (!frame.trimmed && this.texture.trim)
{
this.texture.trim = null;
}

if (this.cropRect)
{
Expand Down
4 changes: 4 additions & 0 deletions src/gameobjects/Rope.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ Phaser.Rope.prototype.setFrame = function(frame) {
this.texture.frame.width = frame.sourceSizeW;
this.texture.frame.height = frame.sourceSizeH;
}
else if (!frame.trimmed && this.texture.trim)
{
this.texture.trim = null;
}

if (this.game.renderType === Phaser.WEBGL)
{
Expand Down
4 changes: 4 additions & 0 deletions src/gameobjects/Sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,10 @@ Phaser.Sprite.prototype.setFrame = function(frame) {
this.texture.frame.width = frame.sourceSizeW;
this.texture.frame.height = frame.sourceSizeH;
}
else if (!frame.trimmed && this.texture.trim)
{
this.texture.trim = null;
}

if (this.cropRect)
{
Expand Down
4 changes: 4 additions & 0 deletions src/gameobjects/TileSprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,10 @@ Phaser.TileSprite.prototype.setFrame = function(frame) {
this.texture.frame.width = frame.sourceSizeW;
this.texture.frame.height = frame.sourceSizeH;
}
else if (!frame.trimmed && this.texture.trim)
{
this.texture.trim = null;
}

if (this.game.renderType === Phaser.WEBGL)
{
Expand Down

0 comments on commit 60acef2

Please sign in to comment.