Questions about normalizedPosition

33 views
Skip to first unread message

guanghui

unread,
Aug 5, 2014, 11:12:35 PM8/5/14
to cocos2d-...@googlegroups.com, Ricardo Quesada

Now our normalizedPosition implementation only works when the parent’s contentSize is dirty.


 uint32_t flags = parentFlags;

    flags |= (_transformUpdated ? FLAGS_TRANSFORM_DIRTY : 0);

    flags |= (_contentSizeDirty ? FLAGS_CONTENT_SIZE_DIRTY : 0);


    if(_usingNormalizedPosition && (flags & FLAGS_CONTENT_SIZE_DIRTY)) {

        CCASSERT(_parent, "setNormalizedPosition() doesn't work with orphan nodes");

        auto s = _parent->getContentSize();

        _position.x = _normalizedPosition.x * s.width;

        _position.y = _normalizedPosition.y * s.height;

        _transformUpdated = _transformDirty = _inverseDirty = true;

    }



But suppose we have the following code : I want to change child’s normalizedPosition in ccTouchBegain callback.


auto parent = Node::create();

auto child = Node::create();

parent->addChild(child);


onTouchBegain()

{

    child->setNormalizedPosition(xxx);  // it won’t work because it’s parent’s content size doesn’t change.

}


Any suggestions? Anything missing here? 

Thanks.


Regards,
Guanghui

guanghui

unread,
Aug 5, 2014, 11:33:19 PM8/5/14
to cocos2d-...@googlegroups.com, Ricardo Quesada
oops, I missed one thing. when the node’s parent’s content size or its own content size changed, the normalizedPosition settings will take effect.
But I want the normalized Position behavior likes the anchorPoint, I can change it anytime and anywhere and it should behavior  correctly.

Help please!


Regards,
Guanghui

guanghui

unread,
Aug 6, 2014, 2:43:06 AM8/6/14
to cocos2d-...@googlegroups.com, Ricardo Quesada
How do you guys think about it?


Regards,
Guanghui

Ricardo Quesada

unread,
Aug 21, 2014, 6:19:28 PM8/21/14
to guanghui, cocos2d-...@googlegroups.com
Hi,

I couldn't understand the bug.
I noticed that you edited a test that tries to reproduce the bug, but please, create a new test case for this bug. Add it in NodeTest.cpp, but add a new entry, and I'll take a look at it.

Thanks.

guanghui

unread,
Aug 21, 2014, 10:29:26 PM8/21/14
to Ricardo Quesada, cocos2d-...@googlegroups.com
The bug was that when I change a Node’s normalized position, it won’t modify the Node’s position unless its parent’s contentSize or its own contentSize becomes dirty.

Let’s give the anchorPoint and Position as an example. If we add a Node to a Layer, no matter when we change the anchorPoint of the node, its position will also be changed too.

But the normalizedPosition change will not affect the node’s position, it relies on whether the contentSize of its parents or itself.

Is it a bug or a intentional design goal here?

Thanks for your reply. :)

Regards,
Guanghui

--
You received this message because you are subscribed to the Google Groups "cocos2d JS development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocos2d-js-dev...@googlegroups.com.
To post to this group, send email to cocos2d-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ricardo Quesada

unread,
Aug 26, 2014, 2:58:25 PM8/26/14
to guanghui, cocos2d-...@googlegroups.com
Hi,

I don't know if this is a bug or not.
For me, the easiest way to test something is by having a test case. So, if you could add a complete test case in the PR I will test it.
thanks.
Reply all
Reply to author
Forward
0 new messages