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

AnimatedSprite can't be a child of Container in TypeScript #43

Closed wizcas closed 5 years ago

wizcas commented 5 years ago

both pixi.js & pixi-layers are installed by npm packages After importing pixi-layers, the AnimatedSprite can't pass type check when being added as a child of Container.

It seems that the error is caused by different function signatures. The paramter renderer of function renderWebGL in class Layer is of type PIXI.WebGLRenderer, whereas it's PIXI.Renderer in Container.

Which one is correct? And how can I make a quick fix for this temperorily?


Here's the compiling error:

TS2345: Argument of type 'AnimatedSprite' is not assignable to parameter of type 'DisplayObject'.
  Types of property 'renderWebGL' are incompatible.
    Type '(renderer: Renderer) => void' is not assignable to type '(renderer: WebGLRenderer) => void'.
      Types of parameters 'renderer' and 'renderer' are incompatible.
        Type 'WebGLRenderer' is missing the following properties from type 'Renderer': globalUniforms, mask, context, shader, and 10 more.
ivanpopelyshev commented 5 years ago

Its because i didnt update it this plugin for v5 yet.

Why do you need pixi-layers, whats your case? I can make it this week instead of next if you explain me that your project is awesome enough, or i can tell you how to use easier solutions.

wizcas commented 5 years ago

@ivanpopelyshev Thanks for you super fast reply! Sorry I didn't noticed I was using Pixi 5... Always thought I was on 4 ;)

I'm making a stage like this:

image

Currently the sprites are added in a bottom-up order, so the upper ones are painted after the lower ones. I need to control their painting order by sprites' y-pos, making lower ones on top. Looks like pixi-layers fits right into it.

ivanpopelyshev commented 5 years ago

well, actually v5 has zIndex field. If all of your sprites are in the same container, you can just assign element.zIndex = element.pos.y , maybe with different sign.

layers are for more extreme cases: to allow things to be rendered not in parent but somewhere else. Character has sprite, shadow, healthbar - to render them in correct order you have to move them into different containers and its bad. Layers allow you to specify where do you want to render them, but leave them with their logic parent :)

Also, layers allows some renderTexture hacks in case you dont want to manage fullscreen render textures yourself.

ivanpopelyshev commented 5 years ago

It is ok to use simple algorithms and move to hard ones when the time comes.

wizcas commented 5 years ago

I'll check out the zIndex field, thanks!

Actually I do have the needs for complex layered rendering like shadows and overlay FXs. There will also be overlay UI, which is attached to player, that needs to be rendered on the topmost layer.

So I'm still looking forward to the new release that supports Pixi v5 and hopefully everything goes well😉