MrYankes Posted January 14, 2014 Share Posted January 14, 2014 Just have a simple question like the topic states - what is the cheapest (lowest memory and cpu consuming) method to create and render a texture using any of Phaser namespace objects (except direct calls to PIXI object)? Sprite and TileSprite seem to be too heavy for simple background image render with x/y adjustments for parallax from time to time. Link to comment Share on other sites More sharing options...
rich Posted January 14, 2014 Share Posted January 14, 2014 Everything effectively boils down to a Sprite in the end, but for a simple background you can save a load of time by disabling it's body. Set it to null and it will skip all of the body physics checks, which is where most of a Sprites time is taken up. We will be adding a "dumbed down" Sprite in v1.2 when we upgrade to Pixi 1.4, that will have input, animation and physics all removed, making it ideal for something like this. But for now killing the body is your best bet. jerome and tackle 2 Link to comment Share on other sites More sharing options...
MrYankes Posted January 14, 2014 Author Share Posted January 14, 2014 Sounds tasty. I'm off to my refactoring process then and waiting for that crispy v1.2 one day. Link to comment Share on other sites More sharing options...
Cameron Foale Posted January 14, 2014 Share Posted January 14, 2014 Here's a quick-fix to speed up basic sprites.It assumes anchor/pivot is at (0,0), no rotation, and that the sprite is always in the world.BasicSprite = function(game, x, y, key, frame) { Phaser.Sprite.call(this, game, x, y, key, frame);}BasicSprite.prototype = Object.create(Phaser.Sprite.prototype);BasicSprite.prototype.constructor = BasicSprite;BasicSprite.prototype.preUpdate = function() { if (!this.exists || (this.group && !this.group.exists)) { this.renderOrderID = -1; // Skip children if not exists return false; } if (this.lifespan > 0) { this.lifespan -= this.game.time.elapsed; if (this.lifespan <= 0) { this.kill(); return false; } } if (this.visible) { this.renderOrderID = this.game.world.currentRenderOrderID++; } this.updateCache(); this.updateAnimation(); this.updateCrop(); this.updateBounds(); return true;};BasicSprite.prototype.updateBounds = function() { this.updateFrame = true; this.inWorld = true; this.bounds.setTo(this.world.x, this.world.y, this.width, this.height); this._cache.cameraVisible = this.renderable = Phaser.Rectangle.intersects(this.bounds, this.game.camera.view);};You might even be able to pull out some of the other updates, like updateCrop and updateAnimation, but I'm not sure. Link to comment Share on other sites More sharing options...
Recommended Posts