本文整理汇总了C++中StaticSprite2D::SetSprite方法的典型用法代码示例。如果您正苦于以下问题:C++ StaticSprite2D::SetSprite方法的具体用法?C++ StaticSprite2D::SetSprite怎么用?C++ StaticSprite2D::SetSprite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StaticSprite2D
的用法示例。
在下文中一共展示了StaticSprite2D::SetSprite方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
}
示例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: 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");
}
示例5: 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;
}
示例6: 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);
}
示例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 );
}
示例8: 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();
}
示例9: Scene
void Urho2DPhysics::CreateScene()
{
scene_ = new Scene(context_);
scene_->CreateComponent<Octree>();
scene_->CreateComponent<DebugRenderer>();
// 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);
// Create 2D physics world component
/*PhysicsWorld2D* physicsWorld = */scene_->CreateComponent<PhysicsWorld2D>();
ResourceCache* cache = GetSubsystem<ResourceCache>();
Sprite2D* boxSprite = cache->GetResource<Sprite2D>("Urho2D/Box.png");
Sprite2D* ballSprite = cache->GetResource<Sprite2D>("Urho2D/Ball.png");
// Create ground.
Node* groundNode = scene_->CreateChild("Ground");
groundNode->SetPosition(Vector3(0.0f, -3.0f, 0.0f));
groundNode->SetScale(Vector3(200.0f, 1.0f, 0.0f));
// Create 2D rigid body for gound
/*RigidBody2D* groundBody = */groundNode->CreateComponent<RigidBody2D>();
StaticSprite2D* groundSprite = groundNode->CreateComponent<StaticSprite2D>();
groundSprite->SetSprite(boxSprite);
// Create box collider for ground
CollisionBox2D* groundShape = groundNode->CreateComponent<CollisionBox2D>();
// Set box size
groundShape->SetSize(Vector2(0.32f, 0.32f));
// Set friction
groundShape->SetFriction(0.5f);
for (unsigned i = 0; i < NUM_OBJECTS; ++i)
{
Node* node = scene_->CreateChild("RigidBody");
node->SetPosition(Vector3(Random(-0.1f, 0.1f), 5.0f + i * 0.4f, 0.0f));
// Create rigid body
RigidBody2D* body = node->CreateComponent<RigidBody2D>();
body->SetBodyType(BT_DYNAMIC);
StaticSprite2D* staticSprite = node->CreateComponent<StaticSprite2D>();
if (i % 2 == 0)
{
staticSprite->SetSprite(boxSprite);
// Create box
CollisionBox2D* box = node->CreateComponent<CollisionBox2D>();
// Set size
box->SetSize(Vector2(0.32f, 0.32f));
// Set density
box->SetDensity(1.0f);
// Set friction
box->SetFriction(0.5f);
// Set restitution
box->SetRestitution(0.1f);
}
else
{
staticSprite->SetSprite(ballSprite);
// Create circle
CollisionCircle2D* circle = node->CreateComponent<CollisionCircle2D>();
// Set radius
circle->SetRadius(0.16f);
// Set density
circle->SetDensity(1.0f);
// Set friction.
circle->SetFriction(0.5f);
// Set restitution
circle->SetRestitution(0.1f);
}
}
}
示例10: 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;
//.........这里部分代码省略.........
示例11: Scene
void Urho2DConstraints::CreateScene()
{
scene_ = new Scene(context_);
scene_->CreateComponent<Octree>();
scene_->CreateComponent<DebugRenderer>();
PhysicsWorld2D* physicsWorld = scene_->CreateComponent<PhysicsWorld2D>(); // Create 2D physics world component
physicsWorld->SetDrawJoint(true); // Display the joints (Note that DrawDebugGeometry() must be set to true to acually draw the joints)
drawDebug_ = true; // Set DrawDebugGeometry() to true
// Create camera
cameraNode_ = scene_->CreateChild("Camera");
// Set camera's position
cameraNode_->SetPosition(Vector3(0.0f, 0.0f, 0.0f)); // Note that Z setting is discarded; use camera.zoom instead (see MoveCamera() below for example)
camera_ = cameraNode_->CreateComponent<Camera>();
camera_->SetOrthographic(true);
Graphics* graphics = GetSubsystem<Graphics>();
camera_->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE);
camera_->SetZoom(1.2f);
// Set up a viewport to the Renderer subsystem so that the 3D scene can be seen
SharedPtr<Viewport> viewport(new Viewport(context_, scene_, camera_));
Renderer* renderer = GetSubsystem<Renderer>();
renderer->SetViewport(0, viewport);
Zone* zone = renderer->GetDefaultZone();
zone->SetFogColor(Color(0.1f, 0.1f, 0.1f)); // Set background color for the scene
// Create 4x3 grid
for (unsigned i = 0; i<5; ++i)
{
Node* edgeNode = scene_->CreateChild("VerticalEdge");
RigidBody2D* edgeBody = edgeNode->CreateComponent<RigidBody2D>();
if (!dummyBody)
dummyBody = edgeBody; // Mark first edge as dummy body (used by mouse pick)
CollisionEdge2D* edgeShape = edgeNode->CreateComponent<CollisionEdge2D>();
edgeShape->SetVertices(Vector2(i*2.5f -5.0f, -3.0f), Vector2(i*2.5f -5.0f, 3.0f));
edgeShape->SetFriction(0.5f); // Set friction
}
for (unsigned j = 0; j<4; ++j)
{
Node* edgeNode = scene_->CreateChild("HorizontalEdge");
RigidBody2D* edgeBody = edgeNode->CreateComponent<RigidBody2D>();
CollisionEdge2D* edgeShape = edgeNode->CreateComponent<CollisionEdge2D>();
edgeShape->SetVertices(Vector2(-5.0f, j*2.0f -3.0f), Vector2(5.0f, j*2.0f -3.0f));
edgeShape->SetFriction(0.5f); // Set friction
}
ResourceCache* cache = GetSubsystem<ResourceCache>();
// Create a box (will be cloned later)
Node* box = scene_->CreateChild("Box");
box->SetPosition(Vector3(0.8f, -2.0f, 0.0f));
StaticSprite2D* boxSprite = box->CreateComponent<StaticSprite2D>();
boxSprite->SetSprite(cache->GetResource<Sprite2D>("Urho2D/Box.png"));
RigidBody2D* boxBody = box->CreateComponent<RigidBody2D>();
boxBody->SetBodyType(BT_DYNAMIC);
boxBody->SetLinearDamping(0.0f);
boxBody->SetAngularDamping(0.0f);
CollisionBox2D* shape = box->CreateComponent<CollisionBox2D>(); // Create box shape
shape->SetSize(Vector2(0.32, 0.32)); // Set size
shape->SetDensity(1.0f); // Set shape density (kilograms per meter squared)
shape->SetFriction(0.5f); // Set friction
shape->SetRestitution(0.1f); // Set restitution (slight bounce)
// Create a ball (will be cloned later)
Node* ball = scene_->CreateChild("Ball");
ball->SetPosition(Vector3(1.8f, -2.0f, 0.0f));
StaticSprite2D* ballSprite = ball->CreateComponent<StaticSprite2D>();
ballSprite->SetSprite(cache->GetResource<Sprite2D>("Urho2D/Ball.png"));
RigidBody2D* ballBody = ball->CreateComponent<RigidBody2D>();
ballBody->SetBodyType(BT_DYNAMIC);
ballBody->SetLinearDamping(0.0f);
ballBody->SetAngularDamping(0.0f);
CollisionCircle2D* ballShape = ball->CreateComponent<CollisionCircle2D>(); // Create circle shape
ballShape->SetRadius(0.16f); // Set radius
ballShape->SetDensity(1.0f); // Set shape density (kilograms per meter squared)
ballShape->SetFriction(0.5f); // Set friction
ballShape->SetRestitution(0.6f); // Set restitution: make it bounce
// Create a polygon
Node* polygon = scene_->CreateChild("Polygon");
polygon->SetPosition(Vector3(1.6f, -2.0f, 0.0f));
polygon->SetScale(0.7f);
StaticSprite2D* polygonSprite = polygon->CreateComponent<StaticSprite2D>();
polygonSprite->SetSprite(cache->GetResource<Sprite2D>("Urho2D/Aster.png"));
RigidBody2D* polygonBody = polygon->CreateComponent<RigidBody2D>();
polygonBody->SetBodyType(BT_DYNAMIC);
CollisionPolygon2D* polygonShape = polygon->CreateComponent<CollisionPolygon2D>();
// TODO: create from PODVector<Vector2> using SetVertices()
polygonShape->SetVertexCount(6); // Set number of vertices (mandatory when using SetVertex())
polygonShape->SetVertex(0, Vector2(-0.8f, -0.3f));
polygonShape->SetVertex(1, Vector2(0.5f, -0.8f));
polygonShape->SetVertex(2, Vector2(0.8f, -0.3f));
polygonShape->SetVertex(3, Vector2(0.8f, 0.5f));
polygonShape->SetVertex(4, Vector2(0.5f, 0.9f));
polygonShape->SetVertex(5, Vector2(-0.5f, 0.7f));
polygonShape->SetDensity(1.0f); // Set shape density (kilograms per meter squared)
//.........这里部分代码省略.........
示例12: if
void SceneView3D::HandleDragEnterWidget(StringHash eventType, VariantMap& eventData)
{
using namespace DragEnterWidget;
UIWidget* widget = static_cast<UIWidget*>(eventData[P_WIDGET].GetPtr());
if (widget != this)
return;
UIDragObject* dragObject = static_cast<UIDragObject*>(eventData[P_DRAGOBJECT].GetPtr());
Object* object = dragObject->GetObject();
if (!object)
return;
if (object->GetType() == Asset::GetTypeStatic())
{
Asset* asset = (Asset*) object;
AssetImporter* importer = asset->GetImporter();
if (!importer)
return;
StringHash importerType = importer->GetType();
if (importerType == PrefabImporter::GetTypeStatic())
{
dragNode_ = scene_->CreateChild(asset->GetName());
PrefabComponent* pc = dragNode_->CreateComponent<PrefabComponent>();
pc->SetPrefabGUID(asset->GetGUID());
}
else if (importerType == ModelImporter::GetTypeNameStatic())
{
dragNode_ = scene_->CreateChild();
SharedPtr<File> file(new File(context_, asset->GetCachePath()));
SharedPtr<XMLFile> xml(new XMLFile(context_));
if (!xml->Load(*file))
return;
dragNode_->LoadXML(xml->GetRoot());
dragNode_->SetName(asset->GetName());
}
else if (importerType == SpriterImporter::GetTypeNameStatic())
{
AnimationSet2D* animationSet = GetSubsystem<ResourceCache>()->GetResource<AnimationSet2D>(asset->GetPath());
String animationName;
if (animationSet && animationSet->GetNumAnimations())
{
animationName = animationSet->GetAnimation(0)->GetName();
}
dragNode_ = scene_->CreateChild(asset->GetName());
AnimatedSprite2D* sprite = dragNode_->CreateComponent<AnimatedSprite2D>();
if (!animationName.Length())
sprite->SetAnimationSet(animationSet);
else
sprite->SetAnimation(animationSet, animationName);
}
else if (importerType == TextureImporter::GetTypeNameStatic())
{
dragNode_ = scene_->CreateChild(asset->GetName());
Sprite2D* spriteGraphic = GetSubsystem<ResourceCache>()->GetResource<Sprite2D>(asset->GetPath());
StaticSprite2D* sprite = dragNode_->CreateComponent<StaticSprite2D>();
sprite->SetSprite(spriteGraphic);
}
if (dragNode_.NotNull())
{
Input* input = GetSubsystem<Input>();
IntVector2 pos = input->GetMousePosition();
UpdateDragNode(pos.x_, pos.y_);
}
//LOGINFOF("Dropped %s : %s on SceneView3D", asset->GetPath().CString(), asset->GetGUID().CString());
}
}