Пример #1
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);
}