These are chat archives for pixijs/pixi.js

18th
Jan 2016
Bar Ziony
@bartzy
Jan 18 2016 08:07
but that's not correct, your last sentence, because the width/height for a container is something once it has children
no?
I have something like this:
So basically there are layers, each layer has a width and a height, and possibly an image to show (it could be text as well)
and the images are not always the same size as the data in this JSON (they're the same ratio usually though...)
so my thought was: Create a generic "Layer" class which inherits from Container. This will have all kinds of general behaviors like movement, rotation (or locking that so it won't be available to the user)
Bar Ziony
@bartzy
Jan 18 2016 08:12
Then each concrete layer you want to show will be a subclass of Layer. So there will be an "ImageLayer", "HoleLayer", "TextLayer"
and I wanted the Layer object to have the concept of its size, explicitly.
Bar Ziony
@bartzy
Jan 18 2016 08:19
Should I go with a different approach implementing this with PIXI?
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 10:52
so the only thing you need is to override getBounds() on container, right?
I dont even know why do you need width/height of container at all
Bar Ziony
@bartzy
Jan 18 2016 10:54
How would you implement that without it?
All of my Layers are Containers in my implementation above
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 10:54
Why do you need width and height of containers?
the only thing I see is that you have to set width and height of sprites and it will change scale automagically
Bar Ziony
@bartzy
Jan 18 2016 10:55
Because my layers, they are containers, all of them
For example, the implementation for an ImageLayer, would be a PIXI.sprite as a child on the ImageLayer (which is a Container)
I'm not using a PIXI.Sprite directly as the ImageLayer.
This is so I can have the same basic functionality to all of my Layers. And if one layer type will extend from Container but another from Sprite, than they will have different functionality...
How would you do this ?
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:06
if your ImageLayer is PIXI.Container then you can set width/height of it anyway and it will work
I see only one thing - your containers must not be resized at all, I dont know why do you specify width/height for them
I mean ContainerLayer or whatever do you want to name it
I repeat, I dont see a problem at all
Show us the case when PIXI.Container and PIXI.Sprite will fail to show that thing
with wrong width/height
Bar Ziony
@bartzy
Jan 18 2016 11:11
why they must not be resized?
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:11
I dont know
Bar Ziony
@bartzy
Jan 18 2016 11:11
In my case
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:11
I dont understand your case
Bar Ziony
@bartzy
Jan 18 2016 11:11
They can be resized...
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:11
if container 800/600 has child 10/10, will it resize the child to 800/600?
Bar Ziony
@bartzy
Jan 18 2016 11:11
Well, you said I need to override getBounds
nope
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:11
thats why
Bar Ziony
@bartzy
Jan 18 2016 11:12
I still need to override getBounds?
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:12
ok, one more time
Sprite resizes when you set its width height
Bar Ziony
@bartzy
Jan 18 2016 11:12
I took a look and it seems like Container's getBounds doesn't care about the transform that is given to it. Dunno why
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:12
Container resizes depends on its children, also when you set width and height
Bar Ziony
@bartzy
Jan 18 2016 11:12
Yeah I got that
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:13
you want third type, which will have specific bounds
it wont resize whats inside of it
Bar Ziony
@bartzy
Jan 18 2016 11:13
Do you know iOS a bit perhaps?
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:13
no
but it'll give correct bounds to parent so parent may be able to resize
its like "crop" in textures
Bar Ziony
@bartzy
Jan 18 2016 11:14
There's a View there. Each view has a frame. Frame is a rectangle in the superview's coordinate system (x,y,width,height). You must init a view with a frame.
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:14
the only thing you need is that third type, just override getBounds() in it and it will be fine
Bar Ziony
@bartzy
Jan 18 2016 11:14
And the fact that this concept does not exist in Pixi confuses me I guess
Because I want my Layer object (which inherits from Container, to be able to have children), to have that "frame" property.
OK, but my getBounds should accept the matrix argument given to it and do something with it?
I mean, getBounds should return the enclosing bounds of the object, so for example take into account its rotation, scale etc
?
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:16
sorry, now Im busy :)
Bar Ziony
@bartzy
Jan 18 2016 11:16
Because Container doesn't take that into account in its getBounds. I think it implicitly counts on its children's getBounds implementation to do that
oh :D
Ivan Popelyshev
@ivanpopelyshev
Jan 18 2016 11:59
What you described is equal to "every element must be positioned absolute"
is that right?
because if root element is (0,0,width, height) and some nested child is (x,y,w,h) then its not important what's between them at all
hierarchy doesnt matter at all
Micheal Winger
@mordof
Jan 18 2016 13:31
@Bartzy the part that's causing complications here for you, i think, and what @englercj was pointing out: Containers aren't the same behavior as the Layers you've talked about. They don't know how to handle a situation where a child ends up "outside" of the container restrictions. PIXI has different ways of dealing with those scenarios. one of them being - "If a child goes outside of a container, it should not be visible at all" <-- That scenario should be handled by supplying a mask to the container. this will prevent anything outside that mask from being renderered.
@Bartzy simply changing the width and height, or the idea of trying to do so, to a container is not going to achieve what you want to make it like a Layer.
Bar Ziony
@bartzy
Jan 18 2016 14:22
@ivanpopelyshev Sorry, why do you mean hierarchy doesn't matter? it does matter
@ivanpopelyshev I just don't have any hierarchy in my JSON example
@mordof: But what about even the concept of having a width/height for a layer.
I understand that if I want it to clip, I need to provide a mask
but there's simplicity in the fact that you know a Layer's (my layers) dimensions, and it's not implicit
so I'm trying to understand how to do that. Because just overriding getBounds would not take the given transform matrix into account?
Chad Engler
@englercj
Jan 18 2016 16:39

and I wanted the Layer object to have the concept of its size, explicitly.

You still haven't told me what the size is for. What the size is for will let me know how you should implement it, but you just keep saying "because it has size" which doesn't really help. Why do you need a size? What is it for? What is the behavior you are trying to achieve?

I mentioned the multitude of ways that size could be used, and how you would use features in pixi to get that behavior but you still haven't told me what you are trying to do.

but there's simplicity in the fact that you know a Layer's (my layers) dimensions, and it's not implicit

If it isn't implicit, then it sounds like you want to add a property that you set to a specific value just for informational purposes. What does that have to do with pixi? Why not just add a property in your subclass that exposes that information for whatever you are doing?