当前位置: 首页>>代码示例>>C++>>正文


C++ StaticSprite2D::SetLayer方法代码示例

本文整理汇总了C++中StaticSprite2D::SetLayer方法的典型用法代码示例。如果您正苦于以下问题:C++ StaticSprite2D::SetLayer方法的具体用法?C++ StaticSprite2D::SetLayer怎么用?C++ StaticSprite2D::SetLayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StaticSprite2D的用法示例。


在下文中一共展示了StaticSprite2D::SetLayer方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: tileNode

void TileMapLayer2D::SetTileLayer(const TmxTileLayer2D* tileLayer)
{
    tileLayer_ = tileLayer;

    int width = tileLayer->GetWidth();
    int height = tileLayer->GetHeight();
    nodes_.Resize((unsigned)(width * height));

    const TileMapInfo2D& info = tileMap_->GetInfo();
    for (int y = 0; y < height; ++y)
    {
        for (int x = 0; x < width; ++x)
        {
            const Tile2D* tile = tileLayer->GetTile(x, y);
            if (!tile)
                continue;

            SharedPtr<Node> tileNode(GetNode()->CreateTemporaryChild("Tile"));
            tileNode->SetPosition(info.TileIndexToPosition(x, y));

            StaticSprite2D* staticSprite = tileNode->CreateComponent<StaticSprite2D>();
            staticSprite->SetSprite(tile->GetSprite());
            staticSprite->SetLayer(drawOrder_);
            staticSprite->SetOrderInLayer(y * width + x);

            nodes_[y * width + x] = tileNode;
        }
    }
}
开发者ID:MonkeyFirst,项目名称:Urho3D,代码行数:29,代码来源:TileMapLayer2D.cpp

示例2: objectNode

void TileMapLayer2D::SetObjectGroup(const TmxObjectGroup2D* objectGroup)
{
    objectGroup_ = objectGroup;

    TmxFile2D* tmxFile = objectGroup->GetTmxFile();
    nodes_.Resize(objectGroup->GetNumObjects());

    for (unsigned i = 0; i < objectGroup->GetNumObjects(); ++i)
    {
        const TileMapObject2D* object = objectGroup->GetObject(i);

        // Create dummy node for all object
        SharedPtr<Node> objectNode(GetNode()->CreateTemporaryChild("Object"));
        objectNode->SetPosition(object->GetPosition());

        // If object is tile, create static sprite component
        if (object->GetObjectType() == OT_TILE && object->GetTileGid() && object->GetTileSprite())
        {
            StaticSprite2D* staticSprite = objectNode->CreateComponent<StaticSprite2D>();
            staticSprite->SetSprite(object->GetTileSprite());
            staticSprite->SetLayer(drawOrder_);
            staticSprite->SetOrderInLayer((int)((10.0f - object->GetPosition().y_) * 100));

            if (tmxFile->GetInfo().orientation_ == O_ISOMETRIC)
            {
                staticSprite->SetUseHotSpot(true);
                staticSprite->SetHotSpot(Vector2(0.5f, 0.0f));
            }
        }

        nodes_[i] = objectNode;
    }
}
开发者ID:MonkeyFirst,项目名称:Urho3D,代码行数:33,代码来源:TileMapLayer2D.cpp

示例3: tileNode

void TileMapLayer2D::SetTileLayer(const TmxTileLayer2D* tileLayer)
{
    tileLayer_ = tileLayer;

    int width = tileLayer->GetWidth();
    int height = tileLayer->GetHeight();
    nodes_.Resize((unsigned)(width * height));

    const TileMapInfo2D& info = tileMap_->GetInfo();
    for (int y = 0; y < height; ++y)
    {
        for (int x = 0; x < width; ++x)
        {
            const Tile2D* tile = tileLayer->GetTile(x, y);
            if (!tile)
                continue;

            SharedPtr<Node> tileNode(GetNode()->CreateChild("Tile"));
            tileNode->SetTemporary(true);
            tileNode->SetPosition(info.TileIndexToPosition(x, y));

            StaticSprite2D* staticSprite = tileNode->CreateComponent<StaticSprite2D>();
            staticSprite->SetSprite(tile->GetSprite());
            staticSprite->SetLayer(drawOrder_);
            staticSprite->SetOrderInLayer(y * width + x);

            // ATOMIC BEGIN

            // collision
            RigidBody2D *body = NULL;
            TmxObjectGroup2D* group = tile->GetObjectGroup();
            if (group)
            {
                for (unsigned i = 0; i < group->GetNumObjects(); i++)
                {
                    TileMapObject2D* o = group->GetObject(i);

                    if (o->ValidCollisionShape())
                    {
                        if (!body)
                        {
                            body = tileNode->CreateComponent<RigidBody2D>();
                            body->SetBodyType(BT_STATIC);
                        }

                        o->CreateCollisionShape(tileNode);

                    }
                }

            }


            // ATOMIC END

            nodes_[y * width + x] = tileNode;
        }
    }
}
开发者ID:sourceops,项目名称:AtomicGameEngine,代码行数:59,代码来源:TileMapLayer2D.cpp

示例4:

void AnimatedSprite2D::OnLayerChanged()
{
    for (unsigned i = 0; i < numTracks_; ++i)
    {
        if (!trackNodes_[i])
            continue;

        StaticSprite2D* staticSprite = trackNodes_[i]->GetComponent<StaticSprite2D>();
        staticSprite->SetLayer(layer_);
    }
}
开发者ID:,项目名称:,代码行数:11,代码来源:

示例5:

void AnimatedSprite2D::SetLayer(int layer)
{
    if (layer == layer_)
        return;

    layer_ = layer;

    for (unsigned i = 0; i < timelineNodes_.Size(); ++i)
    {
        if (!timelineNodes_[i])
            continue;

        StaticSprite2D* staticSprite = timelineNodes_[i]->GetComponent<StaticSprite2D>();
        staticSprite->SetLayer(layer_);
    }
}
开发者ID:OvermindDL1,项目名称:Urho3D,代码行数:16,代码来源:AnimatedSprite2D.cpp

示例6:

void TileMapLayer2D::SetDrawOrder(int drawOrder)
{
    if (drawOrder == drawOrder_)
        return;

    drawOrder_ = drawOrder;

    for (unsigned i = 0; i < nodes_.Size(); ++i)
    {
        if (!nodes_[i])
            continue;

        StaticSprite2D* staticSprite = nodes_[i]->GetComponent<StaticSprite2D>();
        if (staticSprite)
            staticSprite->SetLayer(drawOrder_);
    }
}
开发者ID:MonkeyFirst,项目名称:Urho3D,代码行数:17,代码来源:TileMapLayer2D.cpp

示例7: Shoot

void EnemyEntity::Shoot()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();

    Sprite2D* bulletSprite = cache->GetResource<Sprite2D>("Urho2D/bullet2.png");
    if (!bulletSprite)
        return;

	SharedPtr<Node> bulletNode_(GetScene()->CreateChild("e_bullet"));
	bulletNode_->SetPosition2D(node_->GetPosition2D());
	//bulletNode_->SetDirection(Vector3(dir.x_,-dir.y_,0));
	StaticSprite2D* staticSprite = bulletNode_->CreateComponent<StaticSprite2D>();
	staticSprite->SetSprite(bulletSprite);
	staticSprite->SetLayer(6 * 10);

	RigidBody2D* bulletBody = bulletNode_->CreateComponent<RigidBody2D>();
    bulletBody->SetBodyType(BT_DYNAMIC);
    bulletBody->SetFixedRotation(true);
    bulletBody->SetBullet(true);

    CollisionCircle2D* circleshape = bulletNode_->CreateComponent<CollisionCircle2D>();
    circleshape->SetRadius(0.08f);
    circleshape->SetDensity(1.0f);
    circleshape->SetFriction(0.0f);
    circleshape->SetRestitution(0.0f);
    circleshape->SetMaskBits(57340);
    circleshape->SetCategoryBits(2);

	bulletNode_->CreateComponent<BulletEntity>();

	Node* nodebullet2 = bulletNode_->Clone();
	Node* nodebullet3 = bulletNode_->Clone();
	Node* nodebullet4 = bulletNode_->Clone();

    nodebullet2->GetComponent<RigidBody2D>()->ApplyLinearImpulse(Vector2(0.030f,0.13f),node_->GetPosition2D(),true );
    nodebullet3->GetComponent<RigidBody2D>()->ApplyLinearImpulse(Vector2(-0.02f,0.13f),node_->GetPosition2D(),true );
    nodebullet4->GetComponent<RigidBody2D>()->ApplyLinearImpulse(Vector2(-0.030f,0.13f),node_->GetPosition2D(),true );
	bulletBody->ApplyLinearImpulse(Vector2(0.02f,0.13f),node_->GetPosition2D(),true );
}
开发者ID:CarlosZarate,项目名称:urho3d_platform_game,代码行数:39,代码来源:EnemyEntity.cpp

示例8: SetLoopMode

void AnimatedSprite2D::SetAnimation(Animation2D* animation, LoopMode2D loopMode)
{
    if (animation == animation_)
    {
        SetLoopMode(loopMode_);

        currentTime_ = 0.0f;
        UpdateAnimation(0.0f);
        return;
    }

    for (unsigned i = 0; i < numTracks_; ++i)
    {
        if (trackNodes_[i])
            trackNodes_[i]->SetEnabled(false);
    }

    numTracks_ = 0;
    trackNodes_.Clear();
    trackNodeInfos_.Clear();

    animation_ = animation;

    if (!animation_)
        return;

    currentTime_ = 0.0f;

    if (!rootNode_)
    {
        rootNode_ = GetNode()->CreateChild("_root_", LOCAL);
        rootNode_->SetTemporary(true);
    }

    numTracks_ = animation_->GetNumTracks();
    trackNodes_.Resize(numTracks_);
    trackNodeInfos_.Resize(numTracks_);

    for (unsigned i = 0; i < numTracks_; ++i)
    {
        const AnimationTrack2D& track = animation->GetTrack(i);
        SharedPtr<Node> trackNode(rootNode_->GetChild(track.name_));

        StaticSprite2D* staticSprite = 0;
        if (trackNode)
        {
            // Enable track node
            trackNode->SetEnabled(true);
            
            // Get StaticSprite2D component
            if (track.hasSprite_)
                staticSprite = trackNode->GetComponent<StaticSprite2D>();
        }
        else
        {
            // Create new track node
            trackNode = rootNode_->CreateChild(track.name_, LOCAL);
            trackNode->SetTemporary(true);

            // Create StaticSprite2D component
            if (track.hasSprite_)
                staticSprite = trackNode->CreateComponent<StaticSprite2D>();
        }

        if (staticSprite)
        {
            staticSprite->SetLayer(layer_);
            staticSprite->SetBlendMode(blendMode_);
            staticSprite->SetFlip(flipX_, flipY_);
            staticSprite->SetUseHotSpot(true);
        }

        trackNodes_[i] = trackNode;

        trackNodeInfos_[i].hasSprite = track.hasSprite_;
    }

    SetLoopMode(loopMode);
    UpdateAnimation(0.0f);

    MarkNetworkUpdate();
}
开发者ID:,项目名称:,代码行数:82,代码来源:

示例9: SetLoopMode

void AnimatedSprite2D::SetAnimation(Animation2D* animation, LoopMode2D loopMode)
{
    if (animation == animation_)
    {
        SetLoopMode(loopMode_);

        currentTime_ = 0.0f;
        UpdateAnimation(0.0f);
        return;
    }

    for (unsigned i = 0; i < timelineNodes_.Size(); ++i)
    {
        if (timelineNodes_[i])
            timelineNodes_[i]->SetEnabled(false);
    }

    timelineNodes_.Clear();

    animation_ = animation;

    if (!animation_)
        return;

    currentTime_ = 0.0f;

    if (!rootNode_)
    {
        rootNode_ = GetNode()->CreateChild("RootNode", LOCAL);
        rootNode_->SetTemporary(true);
    }

    timelineNodes_.Resize(animation_->GetNumTimelines());
    timelineTransformInfos_.Resize(animation_->GetNumTimelines());

    for (unsigned i = 0; i < animation_->GetNumTimelines(); ++i)
    {
        const Timeline2D& timeline = animation->GetTimeline(i);
        SharedPtr<Node> timelineNode(rootNode_->GetChild(timeline.name_));

        StaticSprite2D* staticSprite = 0;

        if (timelineNode)
        {
            // Enable timeline node
            timelineNode->SetEnabled(true);
            // Get StaticSprite2D component
            if (timeline.type_ == OT_SPRITE)
                staticSprite = timelineNode->GetComponent<StaticSprite2D>();
        }
        else
        {
            // Create new timeline node
            timelineNode = rootNode_->CreateChild(timeline.name_, LOCAL);
            // Create StaticSprite2D component
            if (timeline.type_ == OT_SPRITE)
                staticSprite = timelineNode->CreateComponent<StaticSprite2D>();
        }

        if (staticSprite)
        {
            staticSprite->SetLayer(layer_);
            staticSprite->SetBlendMode(blendMode_);
            staticSprite->SetFlip(flipX_, flipY_);
            staticSprite->SetUseHotSpot(true);
        }

        timelineNodes_[i] = timelineNode;

        timelineTransformInfos_[i].parent_ = timeline.parent_;
    }

    SetLoopMode(loopMode);
    UpdateAnimation(0.0f);

    MarkNetworkUpdate();
}
开发者ID:OvermindDL1,项目名称:Urho3D,代码行数:77,代码来源:AnimatedSprite2D.cpp


注:本文中的StaticSprite2D::SetLayer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。