Jump to content

Displayobject width height


coter
 Share

Recommended Posts

What would you expect a DisplayObject's size to be? It has no texture, and it has no children. What defines its size?

DisplayObject is intended to be an abstract base class, right? Thus I'd think whether it should have certain properties would depend on whether classes that implement/extend it should have those properties.

Maybe the OP is looking for DisplayObjectContainer? ie. the class that display objects like Sprite inherit from, and which defines common properties such as width and height.

Also given Xerver's (rhetorical? Tongue-in-cheek?) questions, it suddenly strikes me a slightly odd that DisplayObject has x and y and visible properties, and methods like getBounds() -- surely the same arguments apply ;)

Link to comment
Share on other sites

DisplayObject is intended to be an abstract base class, right? Thus I'd think whether it should have certain properties would depend on whether classes that implement/extend it should have those properties.

Maybe the OP is looking for DisplayObjectContainer? ie. the class that display objects like Sprite inherit from, and which defines common properties such as width and height.

Also given Xerver's (rhetorical? Tongue-in-cheek?) questions, it suddenly strikes me a slightly odd that DisplayObject has x and y and visible properties, and methods like getBounds() -- surely the same arguments apply ;)

 

I'm not being smart, I'm asking seriously. I don't know what DO width/height would actually represent. Since it is an abstract base class representing a renderable object in scene space, maybe it makes sense to have size data (since most if not all children would have it). There is some JS weirdness here though, because on Container we want to define the width/height properties as getters/setters. If we defined width/height as normal properties on a DO, then we wouldn't be able to do that in Container.

 

I was trying to ascertain what the "nightmare" was and try to fix it, by understanding what the OP expects those things to mean to them.

Link to comment
Share on other sites

I'm sorry Xerver, I didn't understand what you meant, and I hope my remarks on the other properties & methods was not rude.

I note the OP mentions Flash in other threads (which does have width and height on DisplayObject) -

http://www.html5gamedevs.com/topic/17158-how-to-draw-the-shape-by-the-given-points/

http://www.html5gamedevs.com/topic/16834-how-to-know-the-size-of-a-work-area/

And mentions extending DisplayObject -

http://www.html5gamedevs.com/topic/17248-how-to-extend-eventemitter/

My guess is that the "nightmare" is that the OP is coming from Flash development and is having a hard time with Pixi.js due to the API looking similar but being different enough to cause them headaches.

Link to comment
Share on other sites

I do not make conclusions based on a specific technology. I make conclusions based on OOP.

DisplayObject is the base abstract class for all objects that are added and the display sheet.

Show me a class that extends DisplayObject and which has no width and height?
The base type must describe the properties and methods that are inherent to all his descendants.
 
I could write a thousand lines, but I'm afraid that Google translator translates so that my thoughts are distorted and You just don't understand them.

But all these thousands of rows would say only one thing - the width and height must be a DisplayObject. without variants.

interface IDisplayObject {x: number;y: number;}interface IContainer extends IBase{width: number;height: number;}interface IGraphics extends IContainer{}var container: IDisplayObject = new Container();var graphics: IDisplayObject = new Graphics();container.x // good, IDisplayObject base typegraphics.x // good, IDisplayObject base typecontainer.width // oooh no, IDisplayObject is not base typegraphics.width // oooh no, IDisplayObject is not base typevar container: Container = new Container(); // Oh God, I can create an instance of an abstract type??// it turns out that the Container - base type. // DisplayObject - absurd type.
Link to comment
Share on other sites

Show me a class that extends DisplayObject and which has no width and height?

 

https://github.com/pixijs/pixi-lights/blob/master/src/lights/light/Light.js

 

The base type must describe the properties and methods that are inherent to all his descendants.

 

And we have display-objects in plugins and such that do not actually have a hard width/height. That being said, I'm not disagreeing that it shouldn't have them in DO, just curious why we should. JavaScript doesn't have interfaces, so that isn't an issue. Also size isn't strictly necessary to draw something (though conceptually you could argue the opposite and that's valid).

 

You should never create an DisplayObject directly, in which case you wouldn't have a non-width/height object unless the descendant didn't have a width/height. The reason most of the base pixi objects have width/height is because they inherit from Container, which does have a size. PLugins and other situations may call for inheriting from DisplayObject, and many times those objects don't necessarily have width/height (like the light object).

 

Finally, Container is not an abstract type, it is concrete and meant to be used. DisplayObject is abstract, and (since this is JavaScript) it *can* be instantiated, we recommend against it as it isn't entirely useful on its own.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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