本文整理汇总了C++中StaticSprite2D::SetOrderInLayer方法的典型用法代码示例。如果您正苦于以下问题:C++ StaticSprite2D::SetOrderInLayer方法的具体用法?C++ StaticSprite2D::SetOrderInLayer怎么用?C++ StaticSprite2D::SetOrderInLayer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StaticSprite2D
的用法示例。
在下文中一共展示了StaticSprite2D::SetOrderInLayer方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
}
示例2: 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;
}
}
}
示例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;
}
}
}
示例4: imageNode
void TileMapLayer2D::SetImageLayer(const TmxImageLayer2D* imageLayer)
{
imageLayer_ = imageLayer;
if (!imageLayer->GetSprite())
return;
SharedPtr<Node> imageNode(GetNode()->CreateTemporaryChild("Tile"));
imageNode->SetPosition(imageLayer->GetPosition());
StaticSprite2D* staticSprite = imageNode->CreateComponent<StaticSprite2D>();
staticSprite->SetSprite(imageLayer->GetSprite());
staticSprite->SetOrderInLayer(0);
nodes_.Push(imageNode);
}
示例5: fmodf
//.........这里部分代码省略.........
for (unsigned i = 0; i < numTracks_; ++i)
{
trackNodeInfos_[i].worldSpace = false;
const AnimationTrack2D& track = animation_->GetTrack(i);
const Vector<AnimationKeyFrame2D>& keyFrames = track.keyFrames_;
// Time out of range
if (time < keyFrames[0].time_ || time > keyFrames.Back().time_)
trackNodeInfos_[i].value.enabled_ = false;
else
{
unsigned index = keyFrames.Size() - 1;
for (unsigned j = 0; j < keyFrames.Size() - 1; ++j)
{
if (time <= keyFrames[j + 1].time_)
{
index = j;
break;
}
}
const AnimationKeyFrame2D& currKey = keyFrames[index];
AnimationKeyFrame2D& value = trackNodeInfos_[i].value;
value.enabled_ = currKey.enabled_;
value.parent_ = currKey.parent_;
if (index < keyFrames.Size() - 1)
{
const AnimationKeyFrame2D& nextKey = keyFrames[index + 1];
float t = (time - currKey.time_) / (nextKey.time_ - currKey.time_);
value.transform_ = currKey.transform_.Lerp(nextKey.transform_, t, currKey.spin_);
if (trackNodeInfos_[i].hasSprite)
value.alpha_ = Urho3D::Lerp(currKey.alpha_, nextKey.alpha_, t);
}
else
{
value.transform_ = currKey.transform_;
if (trackNodeInfos_[i].hasSprite)
value.alpha_ = currKey.alpha_;
}
if (trackNodeInfos_[i].hasSprite)
{
value.zIndex_ = currKey.zIndex_;
value.sprite_ = currKey.sprite_;
value.useHotSpot_ = currKey.useHotSpot_;
value.hotSpot_ = currKey.hotSpot_;
}
}
}
for (unsigned i = 0; i < numTracks_; ++i)
{
Node* node = trackNodes_[i];
TrackNodeInfo& nodeInfo = trackNodeInfos_[i];
if (!nodeInfo.value.enabled_)
node->SetEnabled(false);
else
{
node->SetEnabled(true);
// Calculate world transform.
CalculateTimelineWorldTransform(i);
// Update node's transform
Vector2 position = nodeInfo.value.transform_.position_ * PIXEL_SIZE;
if (flipX_)
position.x_ = -position.x_;
if (flipY_)
position.y_ = -position.y_;
node->SetPosition(position);
float angle = nodeInfo.value.transform_.angle_;
if (flipX_ != flipY_)
angle = -angle;
node->SetRotation(angle);
node->SetScale(nodeInfo.value.transform_.scale_);
if (nodeInfo.hasSprite)
{
StaticSprite2D* staticSprite = node->GetComponent<StaticSprite2D>();
if (staticSprite)
{
staticSprite->SetOrderInLayer(orderInLayer_ + nodeInfo.value.zIndex_);
staticSprite->SetSprite(nodeInfo.value.sprite_);
staticSprite->SetUseHotSpot(nodeInfo.value.useHotSpot_);
staticSprite->SetHotSpot(nodeInfo.value.hotSpot_);
}
}
}
}
MarkForUpdate();
}
示例6: fmodf
//.........这里部分代码省略.........
float t = (time - currKey.time_) / (nextKey.time_ - currKey.time_);
timelineTransformInfos_[i].worldSpace_ = false;
timelineTransformInfos_[i].transform_ = currKey.transform_.Lerp(nextKey.transform_, t, currKey.spin_);
// Update sprite's sprite and hot spot and color
Node* timelineNode = timelineNodes_[i];
if (timelineNode)
{
StaticSprite2D* staticSprite = timelineNode->GetComponent<StaticSprite2D>();
if (staticSprite)
{
staticSprite->SetSprite(currKey.sprite_);
staticSprite->SetHotSpot(currKey.hotSpot_.Lerp(nextKey.hotSpot_, t));
float alpha = Lerp(currKey.alpha_, nextKey.alpha_, t);
staticSprite->SetColor(Color(color_.r_, color_.g_, color_.b_, color_.a_ * alpha));
}
}
}
else
{
timelineTransformInfos_[i].worldSpace_ = false;
timelineTransformInfos_[i].transform_ = currKey.transform_;
// Update sprite's sprite and hot spot and color
Node* timelineNode = timelineNodes_[i];
if (timelineNode)
{
StaticSprite2D* staticSprite = timelineNode->GetComponent<StaticSprite2D>();
if (staticSprite)
{
staticSprite->SetSprite(currKey.sprite_);
staticSprite->SetHotSpot(currKey.hotSpot_);
staticSprite->SetColor(Color(color_.r_, color_.g_, color_.b_, color_.a_ * currKey.alpha_));
}
}
}
}
// Calculate timeline world transform.
for (unsigned i = 0; i < timelineTransformInfos_.Size(); ++i)
CalculateTimelineWorldTransform(i);
// Get mainline key
const Vector<MainlineKey2D>& mainlineKeys = animation_->GetMainlineKeys();
const MainlineKey2D* mainlineKey = 0;
for (unsigned i = 1; i < mainlineKeys.Size(); ++i)
{
if (time < mainlineKeys[i].time_)
{
mainlineKey = &mainlineKeys[i - 1];
break;
}
}
if (!mainlineKey)
mainlineKey = &mainlineKeys.Back();
// Update node's transform and sprite's z order
for (unsigned i = 0; i < timelineNodes_.Size(); ++i)
{
Node* timelineNode = timelineNodes_[i];
if (!timelineNode)
continue;
const Reference2D* ref = mainlineKey->GetReference(i);
if (!ref)
{
// Disable node
if (timelineNode->IsEnabled())
timelineNode->SetEnabled(false);
}
else
{
// Enable node
if (!timelineNode->IsEnabled())
timelineNode->SetEnabled(true);
// Update node's transform
const Transform2D& transform = timelineTransformInfos_[i].transform_;
Vector2 position = transform.position_ * PIXEL_SIZE;
if (flipX_)
position.x_ = -position.x_;
if (flipY_)
position.y_ = -position.y_;
timelineNode->SetPosition(position);
float angle = transform.angle_;
if (flipX_ != flipY_)
angle = -angle;
timelineNode->SetRotation(angle);
timelineNode->SetScale(transform.scale_);
// Update sprite's z order
StaticSprite2D* staticSprite = timelineNode->GetComponent<StaticSprite2D>();
if (staticSprite)
staticSprite->SetOrderInLayer(orderInLayer_ + ref->zIndex_);
}
}
MarkForUpdate();
}
示例7: Scene
//.........这里部分代码省略.........
CreateFlag("ConstraintGear2D", -4.97f, -1.0f); // Display Text3D flag
Node* baseNode = box->Clone();
RigidBody2D* tempBody = baseNode->GetComponent<RigidBody2D>(); // Get body to make it static
tempBody->SetBodyType(BT_STATIC);
baseNode->SetPosition(Vector3(-3.7f, -2.5f, 0.0f));
Node* ball1Node = ball->Clone();
ball1Node->SetPosition(Vector3(-4.5f, -2.0f, 0.0f));
RigidBody2D* ball1Body = ball1Node->GetComponent<RigidBody2D>();
Node* ball2Node = ball->Clone();
ball2Node->SetPosition(Vector3(-3.0f, -2.0f, 0.0f));
RigidBody2D* ball2Body = ball2Node->GetComponent<RigidBody2D>();
ConstraintRevolute2D* gear1 = baseNode->CreateComponent<ConstraintRevolute2D>(); // Apply constraint to baseBox
gear1->SetOtherBody(ball1Body); // Constrain ball1 to baseBox
gear1->SetAnchor(Vector2(ball1Node->GetPosition().x_, ball1Node->GetPosition().y_));
ConstraintRevolute2D* gear2 = baseNode->CreateComponent<ConstraintRevolute2D>(); // Apply constraint to baseBox
gear2->SetOtherBody(ball2Body); // Constrain ball2 to baseBox
gear2->SetAnchor(Vector2(ball2Node->GetPosition().x_, ball2Node->GetPosition().y_));
ConstraintGear2D* constraintGear = ball1Node->CreateComponent<ConstraintGear2D>(); // Apply constraint to ball1
constraintGear->SetOtherBody(ball2Body); // Constrain ball2 to ball1
constraintGear->SetOwnerConstraint(gear1);
constraintGear->SetOtherConstraint(gear2);
constraintGear->SetRatio(1.0f);
ball1Body->ApplyAngularImpulse(0.015f, true); // Animate
// Create a vehicle from a compound of 2 ConstraintWheel2Ds
CreateFlag("ConstraintWheel2Ds compound", -2.45f, -1.0f); // Display Text3D flag
Node* car = box->Clone();
car->SetScale(Vector3(4.0f, 1.0f, 0.0f));
car->SetPosition(Vector3(-1.2f, -2.3f, 0.0f));
StaticSprite2D* tempSprite = car->GetComponent<StaticSprite2D>(); // Get car Sprite in order to draw it on top
tempSprite->SetOrderInLayer(0); // Draw car on top of the wheels (set to -1 to draw below)
Node* ball1WheelNode = ball->Clone();
ball1WheelNode->SetPosition(Vector3(-1.6f, -2.5f, 0.0f));
Node* ball2WheelNode = ball->Clone();
ball2WheelNode->SetPosition(Vector3(-0.8f, -2.5f, 0.0f));
ConstraintWheel2D* wheel1 = car->CreateComponent<ConstraintWheel2D>();
wheel1->SetOtherBody(ball1WheelNode->GetComponent<RigidBody2D>());
wheel1->SetAnchor(Vector2(ball1WheelNode->GetPosition().x_, ball1WheelNode->GetPosition().y_));
wheel1->SetAxis(Vector2(0.0f, 1.0f));
wheel1->SetMaxMotorTorque(20.0f);
wheel1->SetFrequencyHz(4.0f);
wheel1->SetDampingRatio(0.4f);
ConstraintWheel2D* wheel2 = car->CreateComponent<ConstraintWheel2D>();
wheel2->SetOtherBody(ball2WheelNode->GetComponent<RigidBody2D>());
wheel2->SetAnchor(Vector2(ball2WheelNode->GetPosition().x_, ball2WheelNode->GetPosition().y_));
wheel2->SetAxis(Vector2(0.0f, 1.0f));
wheel2->SetMaxMotorTorque(10.0f);
wheel2->SetFrequencyHz(4.0f);
wheel2->SetDampingRatio(0.4f);
// ConstraintMotor2D
CreateFlag("ConstraintMotor2D", 2.53f, -1.0f); // Display Text3D flag
Node* boxMotorNode = box->Clone();
tempBody = boxMotorNode->GetComponent<RigidBody2D>(); // Get body to make it static
tempBody->SetBodyType(BT_STATIC);
Node* ballMotorNode = ball->Clone();
boxMotorNode->SetPosition(Vector3(3.8f, -2.1f, 0.0f));
ballMotorNode->SetPosition(Vector3(3.8f, -1.5f, 0.0f));
ConstraintMotor2D* constraintMotor = boxMotorNode->CreateComponent<ConstraintMotor2D>();
constraintMotor->SetOtherBody(ballMotorNode->GetComponent<RigidBody2D>()); // Constrain ball to box