本文整理汇总了C++中StaticSprite2D类的典型用法代码示例。如果您正苦于以下问题:C++ StaticSprite2D类的具体用法?C++ StaticSprite2D怎么用?C++ StaticSprite2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StaticSprite2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
}
示例2: 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));
}
示例3: IsEnabledEffective
void AnimatedSprite2D::OnSetEnabled()
{
StaticSprite2D::OnSetEnabled();
bool enabled = IsEnabledEffective();
Scene* scene = GetScene();
if (scene)
{
if (enabled)
SubscribeToEvent(scene, E_SCENEPOSTUPDATE, HANDLER(AnimatedSprite2D, HandleScenePostUpdate));
else
UnsubscribeFromEvent(scene, E_SCENEPOSTUPDATE);
}
for (unsigned i = 0; i < trackNodes_.Size(); ++i)
{
if (!trackNodes_[i])
continue;
StaticSprite2D* staticSprite = trackNodes_[i]->GetComponent<StaticSprite2D>();
if (staticSprite)
staticSprite->SetEnabled(enabled);
}
}
示例4: 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;
}
}
}
示例5: 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");
}
示例6:
void AnimatedSprite2D::OnBlendModeChanged()
{
for (unsigned i = 0; i < numTracks_; ++i)
{
if (!trackNodes_[i])
continue;
StaticSprite2D* staticSprite = trackNodes_[i]->GetComponent<StaticSprite2D>();
staticSprite->SetBlendMode(blendMode_);
}
}
示例7:
void AnimatedSprite2D::OnDrawOrderChanged()
{
for (unsigned i = 0; i < numTracks_; ++i)
{
if (!trackNodes_[i])
continue;
StaticSprite2D* staticSprite = trackNodes_[i]->GetComponent<StaticSprite2D>();
if (staticSprite)
staticSprite->SetLayer(layer_);
}
}
示例8: 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);
}
示例9: 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);
}
示例10: UpdateAnimation
void AnimatedSprite2D::OnFlipChanged()
{
for (unsigned i = 0; i < numTracks_; ++i)
{
if (!trackNodes_[i])
continue;
StaticSprite2D* staticSprite = trackNodes_[i]->GetComponent<StaticSprite2D>();
staticSprite->SetFlip(flipX_, flipY_);
}
// For editor paused mode
UpdateAnimation(0.0f);
}
示例11: InstantiateNode
Node* TextureImporter::InstantiateNode(Node* parent, const String& name)
{
Node* node = parent->CreateChild(name);
Sprite2D* spriteGraphic = GetSubsystem<ResourceCache>()->GetResource<Sprite2D>(asset_->GetPath());
StaticSprite2D* sprite = node->CreateComponent<StaticSprite2D>();
sprite->SetSprite(spriteGraphic);
return node;
}
示例12:
void AnimatedSprite2D::SetBlendMode(BlendMode blendMode)
{
if (blendMode == blendMode_)
return;
blendMode_ = blendMode;
for (unsigned i = 0; i < timelineNodes_.Size(); ++i)
{
if (!timelineNodes_[i])
continue;
StaticSprite2D* staticSprite = timelineNodes_[i]->GetComponent<StaticSprite2D>();
staticSprite->SetBlendMode(blendMode_);
}
}
示例13: 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);
}
示例14:
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_);
}
}
示例15: 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;
}
}