pixijs / layers

Separate the z-hierarchy of your scene tree from its canonical structure.
https://pixijs.io/layers/docs/
MIT License
222 stars 57 forks source link

Amplified Exceptions? #2

Closed kaansoral closed 8 years ago

kaansoral commented 8 years ago

So one of the most common exceptions of PIXI is going outside the texture boundaries with a frame

I think pixi-display might be amplifying the situation when this happens, the exception is replicated by pixi-display, things freeze

I don't know whether anything can or should be done about this, just sharing my experience - the solution is obviously to hunt and prevent exceptions

ivanpopelyshev commented 8 years ago

Can you explain how exactly do you use Texture interface? it might be connected with how we changed it in v4.

kaansoral commented 8 years ago

This is my dirtiest usage:

animation.sprite.texture.frame=new PIXI.Rectangle(animation.sprite.texture.frame.x+animation.sprite.texture.frame.width,animation.sprite.texture.frame.y,animation.sprite.texture.frame.width,animation.sprite.texture.frame.height);

I had a bug where pushed this sliding animation outside it's boundaries, at that point the issue I explained occurred

I can now comment out pixi-display import and see whether the issues I see are emanating from pixi-display, none of them are

At the time of this issue, I didn't have this ability, so I can't verify whether pixi-display made the issue "worse" or "same"

We might close this issue, or I might replicate the problem for the sake of science

ivanpopelyshev commented 8 years ago

Its better to create multiple textures and switch between them, than use one texture to slide. That way you'll detect all errors before you start rendering.

ivanpopelyshev commented 8 years ago

Also, are you using scale.x=-1 to flip the character? Please look at http://pixijs.github.io/examples/index.html?s=demos&f=texture-rotate.js&title=Texture%20Rotate&v=dev , I made is specially for that cause.

kaansoral commented 8 years ago

I do texture reusal for map tiles, yet it didn't occur to me to do it for character sprites and other stuff, I just shift the frame, seems easier

My concern is generally performance (as exceptions manifest themselves during testing) If pre-generating texture's and switching texture's performs better I might do that


I don't do rotations yet, didn't need to, yet I want to do that for some weapon/armor sprites

I guess I will look at that example and try to turn it into a simple function, like rotate(sprite,num) As it will be done once, the performance doesn't matter, and the example seemed too complex to apply in line, on a sprite by sprite basis, better to put the complexities in a function that will be simple to use

I guess I will give it a go now


Edit:

function rotate(sprite,num)
{
    //reference: http://pixijs.github.io/examples/index.html?s=demos&f=texture-rotate.js&title=Texture%20Rotate&v=dev
    var D8 = PIXI.GroupD8,texture=sprite.texture;
    var h = D8.isSwapWidthHeight(num)?texture.frame.width:texture.frame.height;
    var w = D8.isSwapWidthHeight(num)?texture.frame.height:texture.frame.width;

    var frame=texture.frame;
    var crop=new PIXI.Rectangle(texture.frame.x,texture.frame.y, w, h);
    var trim=crop;
    if(num%2==0)
    {
        var rotatedTexture=new PIXI.Texture(texture.baseTexture, frame, crop, trim, num);
    }
    else
    {
        var rotatedTexture=new PIXI.Texture(texture.baseTexture, frame, crop, trim, num-1);
        rotatedTexture.rotate++;
    }
    sprite.texture=rotatedTexture;
}

Didn't work :D

Edit 2: This makes it work, no idea why, purely trial + error

var crop=new PIXI.Rectangle(0,0, w, h);

ivanpopelyshev commented 8 years ago

Strange. Anyway, switching texture of sprite is better for performance, but only a bit. It's just intended behaviour ;)