These are chat archives for pixijs/pixi.js

6th
Jan 2016
Matt Ostgard
@MattOstgard
Jan 06 2016 00:35 UTC
weird.. TextureShader isn't in the base namespace, though the docs say it should be: https://pixijs.github.io/docs/PIXI.TextureShader.html
Don't*
Changing the constant isn't the correct fix imo, we should just figure out what is applying the alpha the second time and fix that
Matt Ostgard
@MattOstgard
Jan 06 2016 02:49 UTC
I agree
Inas Luthfi
@nascode
Jan 06 2016 13:32 UTC

Hi everyone, nice to know you all :)

I am new with pixiJS, so i hope someone can help me.
I use pixi with Typescript. Right now i have created a scene manager class. I define scene as everything inherited from PIXI.Container

the weird thing is about PIXI.Container destroy method. When changing scene, i call the scene's destroy method with true argument. I looked at the source of PIXI.Container, and i see that pixi will iterate all of the container's children and call their destroy method with true argument too
Inas Luthfi
@nascode
Jan 06 2016 13:39 UTC

What went wrong is when one of the children is a Sprite. pixi will call destroy method of PIXI.Sprite with 'true' as a first argument. Thus we will destroy the texture too.

Is this the correct implementation? Can we keep the texture on the cache without destroying it?

Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 13:40 UTC
then just dont destroy it
use removeChildren()
GC will take care of old stuff
destroy() exists only to free textures, meshes and other stuff that persists on GPU
Bar Ziony
@bartzy
Jan 06 2016 13:49 UTC
Can a PIXI.Sprite exist without a texture?
I see that the constructor requires a texture so I guess not
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 13:49 UTC
I dont know really, need to test it
I know that it can exist even if texture is not valid (werent loaded yet)
Bar Ziony
@bartzy
Jan 06 2016 13:50 UTC
ok will do
Do you know the timeline for v4 btw?
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 13:50 UTC
you can pass some temporary thing to it
Bar Ziony
@bartzy
Jan 06 2016 13:50 UTC
Or, is there one? :)
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 13:50 UTC
there's no timeline on it, we just pray god to give @englercj enough time for it
Bar Ziony
@bartzy
Jan 06 2016 13:51 UTC
Has is started yet?
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 13:59 UTC
no
what Im doing can be v3.5 :)
Inas Luthfi
@nascode
Jan 06 2016 14:02 UTC

I see,

For now, i solve the problem with calling container's destroy method without true argument. Thus make sure pixi wont call children's destroy method. Makes me destroy things manually.

Looking at the source, i hope PIXI.container destroy method will send true argument only to child which is also a container object, and not sending any argument to child sprite object.

I haven't checked in game memory used yet when we ignore calling destroy. What do you use to profile HTML5 in-game memory used?

Bar Ziony
@bartzy
Jan 06 2016 14:08 UTC
Is there a "loaded" callback or event for PIXI.Texture?
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:11 UTC
yeah
for baseTexture
texture.baseTexture.on('loaded', function() { stuff } );
that's if you use fromImage(..) and not the async loader
Bar Ziony
@bartzy
Jan 06 2016 14:27 UTC
the async loader is that ResourceLoader fork ?
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:36 UTC
no, ist the resourceloader
var loader = new PIXI.loaders.Loader(); loader.add(...)
that thing
there are two ways of loading textures
Bar Ziony
@bartzy
Jan 06 2016 14:36 UTC
That's the resourceloader, no ?
Also, can I create a texture from an existing HTMLImageElement?
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:37 UTC
first way is to use fromImage() which will create texture but it wont be valid until browser loads it
Bar Ziony
@bartzy
Jan 06 2016 14:37 UTC
I only see options for Video, image URL, Canvas
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:37 UTC
yes you can
Bar Ziony
@bartzy
Jan 06 2016 14:38 UTC
Oh I see, by first creating a base texture
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:38 UTC
fromCanvas works with images :)
Bar Ziony
@bartzy
Jan 06 2016 14:38 UTC
Why there's a Texture AND Base Texture entities? What is the difference and role of each?
and oh... That's confusing :D
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:38 UTC
its two levels of abstraction
BaseTexture is wrapper for images, canvases and other stuff (my CompressedImage)
you specify source and basetexture waits while that thing loads
source can be Image, Canvas or whatever implements necessary functions
it also contains data like "resolution" and "scaleMode"
when webgl renderer wants a texture, it looks at BaseTexture and checks if its loaded in GPU
or may be you updated the canvas, and BaseTexture needs to be uploaded in GPU again :)
Bar Ziony
@bartzy
Jan 06 2016 14:41 UTC
So what is PIXI.Texture for? What job is it doing that is different than BaseTexture
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:41 UTC
Texture has the frame :)
Bar Ziony
@bartzy
Jan 06 2016 14:41 UTC
the frame? What does that mean?
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:41 UTC
rectangle
x,y,width,height
Bar Ziony
@bartzy
Jan 06 2016 14:41 UTC
oh I see
like the bounds of UIKit (iOS)
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:41 UTC
Texture is lightweight thing
Bar Ziony
@bartzy
Jan 06 2016 14:41 UTC
ok
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:42 UTC
yeah, but also it has crop and rotate and other things that are specified in atlas
Bar Ziony
@bartzy
Jan 06 2016 14:42 UTC
I thought that can be better represented in something like PIXI.Sprite.
why would a Texture have rotate property :|
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:42 UTC
did you use texturePacker?
or may b eshoebox
*shoebox
or may be spine
sometimes images fit better in atlas when they are rotated by 90 degrees :)
Bar Ziony
@bartzy
Jan 06 2016 14:43 UTC
no
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:43 UTC
also sometimes texture packer crops image and Sprite neesd to know offset, what part was cropped, to show it
if you have a set of 256x256 buildings
Bar Ziony
@bartzy
Jan 06 2016 14:44 UTC
So PIXI really is game-oriented
not just a general 2D renderer
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:44 UTC
then texture packer crops each image differently, it can be 240x243 or 200x201 or something like that
Bar Ziony
@bartzy
Jan 06 2016 14:44 UTC
Everything is "tweaked" towards game development
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 14:44 UTC
but in your app you can assume that its 256x256 :)
that's why we need crop
yep
so you can use textures from multiple files or you can pack them and you wont have to change code for that
load the atlas and all fromImage(...) will work like before, all Sprites will work with it
but really all that stuff will be backed only by one BaseTexture
you can create as many sprites as you want, as many textures as you want, but the only thing that matters for webgl is BaseTexture
Bar Ziony
@bartzy
Jan 06 2016 14:59 UTC
OK
Thanks
So back to the fromCanvas, the fact that it works with images is not a bug? Not something that will be gone in 3.1 or something? :)
because it's not documentsed
documented
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 15:05 UTC
not a bug
it can work with any thing that either gave "getContext()" method either have "complete" field
be it Canvas or Image or any surrogate like CompressedImage
Bar Ziony
@bartzy
Jan 06 2016 16:38 UTC
complete field? What's the connection to an image...?
so I can give it an object that implements "getContext" ? :D
that's a bit weird
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 16:38 UTC
if it has "getContext" then its a canvas
if it has "complete" than its an image :)
if complete=false then image isnt loaded yet
and BaseTexture rewrites its "onload" method to determine when it will be ready
Bar Ziony
@bartzy
Jan 06 2016 16:40 UTC
well that's a bit weird since it's coincidental that an object that has getContext is a Canvas
I have another question about pivot and anchor
why both of them exist?
Why the anchor is not the pivot ?
Ivan Popelyshev
@ivanpopelyshev
Jan 06 2016 16:41 UTC
pivot is legacy and i doubt that it works
but the thing is , texturepacker and shoebox both can specify pivot in the atlas
but i didnt see usage of that field
Chad Engler
@englercj
Jan 06 2016 18:08 UTC
Pivot is not legacy. Pivot effects the rotation of an object, anchor is the attachment point for the texture
Containers don't have anchor, they have no texture
They have pivot to effect where the rotation occurs
Matt Ostgard
@MattOstgard
Jan 06 2016 20:22 UTC
@englercj it looks like blend mode constants will have to be changed no matter what to fix the additive issue. See my comment here: https://github.com/pixijs/pixi.js/issues/2248#issuecomment-169449972