Jump to content

Some words about sprites


TMTH
 Share

Recommended Posts

There are two questions about sprite2d behaviour, again I don't know whether it's bug or intended properties (fun club of  @Nockawa keeps working)

1. Origin property of primitive. (That can be a bug)

From documentation:
        Origin: define the origin of the primitive, default being 0.5,0.5,
        which is the center of the primitive, 0.0,0.0 would be the bottom/left corner of the primitive.
        The origin play a role in the rotation/scaling of the primitive but not in its positioning.


       Here is PG with exploration of that  "not in its positioning" thing in the context of Sprite2D:  http://babylonjs-playground.com/#1RJPAB

As we can see, the right origin formula has to be written as "...but not in its positioning, if the primitive is not Sprite2d. In later case, you wouldn't guess the algorithm that derives actual sprite position from it's position and origin properties.

2. Size and width + height (That is a question of usability).

Simple - you can set size property, but you can't set height and width properties on sprite2d.

I belive that is the intended behaviour, because there are no height and width in sprite2d constructor settings, nor in renderablePrim2d or prim2dBase.

But,

1. using all shape2d-based primitives and group2d you can set size or height/width,

2. on all primitives (including sprited2d) you can set  position or x/y

so, that is one of those nasty little things that you have to just remember.

 

 

Link to comment
Share on other sites

@TMTH ok, so:

1) You  have to know that Origin gave me nightmares (still does...sometimes), I really had hard time to code it, to understand what would be the best behavior, I've tried many different behaviors, anyway: it's hard... I've created a Trello Card for this and I'll work on replicating your issue and then trying to fix it. I don't know when I'll work on it, if you subscribe to the trello card you'll be able to be notified when the card is moved from TODO to In Progress.

2) Well, let's say that for me width/height could be in the constructor because it's just another way to express the dimension of the primitive. But is it a useful thing to expose a width and height properties, well, I'm not sure, I thought that the size of a sprite would be pretty close to immutable. If you give me a good use case where it's helpful to have them, then why not. But you will see in this (gorgeous) class diagram that Sprite2D is not a Shape2D, but I do get your point about making things more uniform, it's easier for the JS user indeed.

Link to comment
Share on other sites

  • 3 weeks later...

@TMTH I've investigate the 1. and result is you're displaying a 64x64 sprite with a 100x100 size, which result of internally applying a scale of 1,5625 which is messing up the positioning where the origin is involved.

It doesn't mean it's an "expected behavior", I still consider you're right, it's a bug, the scale is hidden to the user, he's not aware of it, so it shouldn't affect the origin. 

Now that being said, I have to think about a way to solve this, on the top of my mind it appears to me that using the "user scale" may not be the best thing to do, it was easy for me, but it's misleading on other area of the lib....
My subconscious is telling me that it won't be solved quickly and pretty... I'll keep you in touch.

Link to comment
Share on other sites

@TMTH the origin issue is solved, I've update the preview build. when the PG will be updated you'll see the expected result, you can also rotate the sprite with 0.5, 0.5 origin to see the expected center of rotation.

Thanks for reporting the issue.

I'll find some time to implement the width/height properties, these are wrappers, it's not that hard to do, well, I'm going to do it now, it will be done then.

Link to comment
Share on other sites

On 2/3/2017 at 7:03 AM, TMTH said:

2. Size and width + height (That is a question of usability).

Simple - you can set size property, but you can't set height and width properties on sprite2d.

I belive that is the intended behaviour, because there are no height and width in sprite2d constructor settings, nor in renderablePrim2d or prim2dBase.

But,

1. using all shape2d-based primitives and group2d you can set size or height/width,

2. on all primitives (including sprited2d) you can set  position or x/y

so, that is one of those nasty little things that you have to just remember.

 

 

Well, I've just checked and I don't understand because you can set width or height to a Sprite2D instance (not during its construction, but after). I've just checked and it works. Do you speak about width/height or spriteWidth and spriteHeight ?

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...