void ParallaxNodeExtras::incrementOffset(Point offset, Node* node){
	for (int i = 0; i < _parallaxArray->num; i++) {
		PointObject *point = (PointObject *)_parallaxArray->arr[i];
		Node * curNode = point->getChild();
		if (curNode==/*->isEqual*/(node)) {
			point->setOffset(point->getOffset() + offset);
			break;
		}
	}
}
Exemplo n.º 2
0
void ParallaxContainer::visit(cocos2d::Renderer *renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags)
{
    Vec2 pos = parallaxPosition;

    //if (!pos.equals(_lastPosition)) {
        for( int i=0; i < _parallaxArray->num; i++ ) {
            PointObject *point = (PointObject*)_parallaxArray->arr[i];

            // auto scrolling
            auto offset = point->getOffset();
            offset.x += point->getAutoscroll().x;
            offset.y += point->getAutoscroll().y;
            point->setOffset(offset);

            float x = pos.x * point->getRatio().x + point->getOffset().x;
            float y = pos.y * point->getRatio().y + point->getOffset().y;
            point->getChild()->setPosition({x, y});
        }
        _lastPosition = pos;
    //}
    Node::visit(renderer, parentTransform, parentFlags);
}
Exemplo n.º 3
0
/*
The positions are updated at visit because:
- using a timer is not guaranteed that it will called after all the positions were updated
- overriding "draw" will only precise if the children have a z > 0
*/
void ParallaxNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags)
{
    //    Vec2 pos = position_;
    //    Vec2    pos = [self convertToWorldSpace:Vec2::ZERO];
    Vec2 pos = this->absolutePosition();
    if( ! pos.equals(_lastPosition) )
    {
        for( int i=0; i < _parallaxArray->num; i++ ) 
        {
            PointObject *point = (PointObject*)_parallaxArray->arr[i];
            float x = -pos.x + pos.x * point->getRatio().x + point->getOffset().x;
            float y = -pos.y + pos.y * point->getRatio().y + point->getOffset().y;            
            point->getChild()->setPosition(x,y);
        }
        _lastPosition = pos;
    }
    Node::visit(renderer, parentTransform, parentFlags);
}