Jump to content

Cheapest way to render texture at coordinates


MrYankes
 Share

Recommended Posts

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

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.

Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...