On Wed, Aug 27, 2008 at 11:35 PM, Kao Cardoso Felix <[EMAIL PROTECTED]> wrote:
> I'll be working on that this night and tomorrow I'll send an email
> here to say if I had any progress :)

Ok, so I worked on this and couldn't make a patch yet. But here are
some interesting facts:

I thought very carefully about how the anchors transforms should be
applied given the definition found on the commentaries of cocosnode.py
(transform_anchor is an offset from the position about wich the node
transformations like scale and rotation should be applied and
children_anchor is an offset from the position where children should
be located). After scribling on a paper to try to understand what
should happen I came to the exactly sequence of transformations that
are happening right now on the CocosNode transform method.

Well, I was puzzled to see this so I thought alittle more and I think
I understood what's happening with the sprites:

When we talk about sprites we have 3 anchors involved, actually. We
have the transform_anchor and the children_anchor of cocosnode and
also we have the anchor of the sprite image (used by pyglet to offset
the vertex data). When we create a sprite all those anchors are set to
w/2, h/2 (considering w and h are the dimensions of the sprite image).
We the position our sprite and it's center goes to the desired
position.

We rotate our sprite and it rotates about the center. But, when we add
children to our sprite, they don't go to the center. They go to an
offset from the center equals the value of children_anchor. That is
correct if we interpret the children_anchor as it is defined. The
position of the sprite is the position of the center because the
anchor of the img is in the center of the sprite, so children get
offset from the *center* of the sprite hence the children_anchor to
having a w/2, h/2 value causes a child to go to the top right corner
of our image, and not the center as one could expect (I did).

Until now, this is only the correct behaviour causing an unintuitive
result. The real problem occurs with the transform_anchor. On the code
of cocos' Sprite the image anchor gets bound to the transform_anchor
property. This implies that when one sets the transform_anchor to be
w/2, h/2 she is both setting the image center to be positioned
relative to this point and transforms to be done around an offset from
the position equals w/2, h/2. Since the image data is centered on the
position, transforms should happen around a point that is w/2, h/2
offset from the center of the image data (the top-right corner). With
the sprite itself it doesn't happen because pyglet is handling
rotation and scaling and it's doing around the image anchor, but the
sprite children get rotated around a point that is offset from the
center because of this.

I hope that my explanation is clear enough. The reason I didn't made a
patch for this is because I simply don't know where things should be
changed. From my point of view this is more of a specification bug of
the sprite class than a implementation one. The relation of those 3
anchors (transform, children and image) should be redefined until it
is right. I'm willing to discuss this, but unfornately I can't give a
solution right now because I ran out of ideas :(

I hope this at least help you to understand the problem. Please, let
me know if I got anything wrong on that.

Best regards

-- 
Kao Cardoso Félix

Página pessoal: http://www.inf.ufrgs.br/~kcfelix
Blog: http://kaofelix.blogspot.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"cocos2d discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cocos-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to