本文整理汇总了C++中StaticSprite2D::SetColor方法的典型用法代码示例。如果您正苦于以下问题:C++ StaticSprite2D::SetColor方法的具体用法?C++ StaticSprite2D::SetColor怎么用?C++ StaticSprite2D::SetColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StaticSprite2D
的用法示例。
在下文中一共展示了StaticSprite2D::SetColor方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SubscribeToEvent
void Urho2DConstraints::HandleTouchBegin3(StringHash eventType, VariantMap& eventData)
{
Graphics* graphics = GetSubsystem<Graphics>();
PhysicsWorld2D* physicsWorld = scene_->GetComponent<PhysicsWorld2D>();
using namespace TouchBegin;
RigidBody2D* rigidBody = physicsWorld->GetRigidBody(Vector2(eventData[P_X].GetInt(), eventData[P_Y].GetInt())); // Raycast for RigidBody2Ds to pick
if (rigidBody)
{
pickedNode = rigidBody->GetNode();
StaticSprite2D* staticSprite = pickedNode->GetComponent<StaticSprite2D>();
staticSprite->SetColor(Color(1.0f, 0.0f, 0.0f, 1.0f)); // Temporary modify color of the picked sprite
RigidBody2D* rigidBody = pickedNode->GetComponent<RigidBody2D>();
// Create a ConstraintMouse2D - Temporary apply this constraint to the pickedNode to allow grasping and moving with touch
ConstraintMouse2D* constraintMouse = pickedNode->CreateComponent<ConstraintMouse2D>();
Vector3 pos = camera_->ScreenToWorldPoint(Vector3((float)eventData[P_X].GetInt() / graphics->GetWidth(), (float)eventData[P_Y].GetInt() / graphics->GetHeight(), 0.0f));
constraintMouse->SetTarget(Vector2(pos.x_, pos.y_));
constraintMouse->SetMaxForce(1000 * rigidBody->GetMass());
constraintMouse->SetCollideConnected(true);
constraintMouse->SetOtherBody(dummyBody); // Use dummy body instead of rigidBody. It's better to create a dummy body automatically in ConstraintMouse2D
constraintMouse->SetDampingRatio(0);
}
SubscribeToEvent(E_TOUCHMOVE, HANDLER(Urho2DConstraints, HandleTouchMove3));
SubscribeToEvent(E_TOUCHEND, HANDLER(Urho2DConstraints, HandleTouchEnd3));
}
示例2: Scene
void Urho2DSprite::CreateScene()
{
scene_ = new Scene(context_);
scene_->CreateComponent<Octree>();
// Create camera node
cameraNode_ = scene_->CreateChild("Camera");
// Set camera's position
cameraNode_->SetPosition(Vector3(0.0f, 0.0f, -10.0f));
Camera* camera = cameraNode_->CreateComponent<Camera>();
camera->SetOrthographic(true);
Graphics* graphics = GetSubsystem<Graphics>();
camera->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE);
ResourceCache* cache = GetSubsystem<ResourceCache>();
// Get sprite
Sprite2D* sprite = cache->GetResource<Sprite2D>("Urho2D/Aster.png");
if (!sprite)
return;
float halfWidth = graphics->GetWidth() * 0.5f * PIXEL_SIZE;
float halfHeight = graphics->GetHeight() * 0.5f * PIXEL_SIZE;
for (unsigned i = 0; i < NUM_SPRITES; ++i)
{
SharedPtr<Node> spriteNode(scene_->CreateChild("StaticSprite2D"));
spriteNode->SetPosition(Vector3(Random(-halfWidth, halfWidth), Random(-halfHeight, halfHeight), 0.0f));
StaticSprite2D* staticSprite = spriteNode->CreateComponent<StaticSprite2D>();
// Set random color
staticSprite->SetColor(Color(Random(1.0f), Random(1.0f), Random(1.0f), 1.0f));
// Set blend mode
staticSprite->SetBlendMode(BLEND_ALPHA);
// Set sprite
staticSprite->SetSprite(sprite);
// Set move speed
spriteNode->SetVar(VAR_MOVESPEED, Vector3(Random(-2.0f, 2.0f), Random(-2.0f, 2.0f), 0.0f));
// Set rotate speed
spriteNode->SetVar(VAR_ROTATESPEED, Random(-90.0f, 90.0f));
// Add to sprite node vector
spriteNodes_.Push(spriteNode);
}
// Get animation set
AnimationSet2D* animationSet = cache->GetResource<AnimationSet2D>("Urho2D/GoldIcon.scml");
if (!animationSet)
return;
SharedPtr<Node> spriteNode(scene_->CreateChild("AnimatedSprite2D"));
spriteNode->SetPosition(Vector3(0.0f, 0.0f, -1.0f));
AnimatedSprite2D* animatedSprite = spriteNode->CreateComponent<AnimatedSprite2D>();
// Set animation
animatedSprite->SetAnimation(animationSet, "idle");
}
示例3: UnsubscribeFromEvent
void Urho2DConstraints::HandleTouchEnd3(StringHash eventType, VariantMap& eventData)
{
if (pickedNode)
{
StaticSprite2D* staticSprite = pickedNode->GetComponent<StaticSprite2D>();
staticSprite->SetColor(Color(1.0f, 1.0f, 1.0f, 1.0f)); // Restore picked sprite color
pickedNode->RemoveComponent<ConstraintMouse2D>(); // Remove temporary constraint
pickedNode = NULL;
}
UnsubscribeFromEvent(E_TOUCHMOVE);
UnsubscribeFromEvent(E_TOUCHEND);
}
示例4: UnsubscribeFromEvent
void Clockwork2DConstraints::HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
{
if (pickedNode)
{
StaticSprite2D* staticSprite = pickedNode->GetComponent<StaticSprite2D>();
staticSprite->SetColor(Color(1.0f, 1.0f, 1.0f, 1.0f)); // Restore picked sprite color
pickedNode->RemoveComponent<ConstraintMouse2D>(); // Remove temporary constraint
pickedNode = NULL;
}
UnsubscribeFromEvent(E_MOUSEMOVE);
UnsubscribeFromEvent(E_MOUSEBUTTONUP);
}
示例5: fmodf
void AnimatedSprite2D::UpdateAnimation(float timeStep)
{
if (!animation_)
return;
currentTime_ += timeStep * speed_;
float time;
float animtationLength = animation_->GetLength();
if (looped_)
{
time = fmodf(currentTime_, animtationLength);
if (time < 0.0f)
time += animation_->GetLength();
}
else
time = Clamp(currentTime_, 0.0f, animtationLength);
// Update timeline's local transform
for (unsigned i = 0; i < timelineTransformInfos_.Size(); ++i)
{
const Timeline2D& timeline = animation_->GetTimeline(i);
const Vector<TimelineKey2D>& objectKeys = timeline.timelineKeys_;
unsigned index = objectKeys.Size() - 1;
for (unsigned j = 0; j < objectKeys.Size() - 1; ++j)
{
if (time <= objectKeys[j + 1].time_)
{
index = j;
break;
}
}
const TimelineKey2D& currKey = objectKeys[index];
if (index < objectKeys.Size() - 1)
{
const TimelineKey2D& nextKey = objectKeys[index + 1];
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;
//.........这里部分代码省略.........