本文整理汇总了C++中StaticSprite2D::SetCustomMaterial方法的典型用法代码示例。如果您正苦于以下问题:C++ StaticSprite2D::SetCustomMaterial方法的具体用法?C++ StaticSprite2D::SetCustomMaterial怎么用?C++ StaticSprite2D::SetCustomMaterial使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StaticSprite2D
的用法示例。
在下文中一共展示了StaticSprite2D::SetCustomMaterial方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadSprite
Node* TerrySpawner::LoadSprite(String name)
{
//Vector3 startPos = terrySpawns_->GetChild(Random(0,terrySpawns_->GetNumChildren()))->GetPosition();
Vector3 startPos = spawnPoint_;
XMLFile* xmlFile = main_->cache_->GetResource<XMLFile>("Objects/terriesNode.xml");
Node* spriteNode = scene_->InstantiateXML(xmlFile->GetRoot(),
startPos, Quaternion::IDENTITY, LOCAL);
spriteNode->RemoveChild(spriteNode->GetChild("camera"));
spriteNode->SetName(name);
spriteNode->AddComponent(new Gravity(context_, main_), 0, LOCAL);
spriteNode->AddComponent(new Speed(context_, main_), 0, LOCAL);
//spriteNode->AddComponent(new RotateTo(context_, main_), 0, LOCAL);
spriteNode->AddComponent(new MoveByTouch(context_, main_), 0, LOCAL);
spriteNode->AddComponent(new Health(context_, main_), 0, LOCAL);
spriteNode->GetComponent<MoveByTouch>()->UnsubscribeFromEvent(E_HUDBUTT);
StaticSprite2D* sprite = spriteNode->CreateComponent<StaticSprite2D>();
sprite->SetCustomMaterial(SharedPtr<Material>(main_->cache_->GetResource<Material>("Materials/" + name + "Mat.xml")));
AnimatedSpriteSheet* animatedSpriteSheet = new AnimatedSpriteSheet();
animatedSpriteSheet->sheet_ = main_->cache_->GetResource<SpriteSheet2D>("Urho2D/" + name + "/" + name + "Sheet.xml");
animatedSpriteSheet->staticSprite_ = sprite;
animatedSpriteSheet->playing_ = false;
animatedSpriteSheet->spriteID_ = spriteIDCount_;
animatedSpriteSheet->noed_ = spriteNode;
animatedSpriteSheet->flipX_ = false;
sprites_.Push(animatedSpriteSheet);
spriteIDCount_++;
Vector<String> files;
files.Push("attackF.xml");
files.Push("attackM.xml");
files.Push("dieF.xml");
files.Push("dieM.xml");
files.Push("gestureF.xml");
files.Push("gestureM.xml");
files.Push("idleF.xml");
files.Push("idleM.xml");
files.Push("runF.xml");
files.Push("runM.xml");
/*main_->filesystem_->ScanDir(files,
main_->filesystem_->GetProgramDir() + "Data/Urho2D/" + name + "/animations/",
"*.xml", SCAN_FILES, false);*/
for (int x = 0; x < files.Size(); x++)
{
XMLElement ani = main_->cache_->GetResource<XMLFile>("Urho2D/" + name + "/animations/" + files[x])->GetRoot();
SpriteSheetAnimation* spriteSheetAni = new SpriteSheetAnimation();
animatedSpriteSheet->animations_.Push(spriteSheetAni);
spriteSheetAni->name_ = ani.GetChild("Name").GetAttribute("name");
spriteSheetAni->loop_ = ani.GetChild("Loop").GetBool("loop");
int frameCount = ani.GetChild("FrameCount").GetInt("frameCount");
for (int x = 0; x < frameCount; x++)
{
SpriteSheetAnimationFrame* frame = new SpriteSheetAnimationFrame();
spriteSheetAni->frames_.Push(frame);
String child = "Frame" + String(x);
frame->duration_ = ani.GetChild(child).GetFloat("duration");
frame->sprite_ = ani.GetChild(child).GetAttribute("sprite");
}
}
bool sex = Random(0,2);
animatedSpriteSheet->noed_->SetVar("sex",sex);
VariantMap vm;
vm[AnimateSpriteSheet::P_NODE] = node_;
vm[AnimateSpriteSheet::P_SPRITEID] = animatedSpriteSheet->spriteID_;
if (sex)
{
vm[AnimateSpriteSheet::P_ANIMATION] = "idleF";
}
else
{
vm[AnimateSpriteSheet::P_ANIMATION] = "idleM";
}
vm[AnimateSpriteSheet::P_FLIPX] = 0;
SendEvent(E_ANIMATESPRITESHEET, vm);
animatedSpriteSheet->noed_->SetVar("collisionCount",0);
animatedSpriteSheet->noed_->SetVar("attack",1);
animatedSpriteSheet->noed_->SetVar("attackInterval",1.0f);
animatedSpriteSheet->noed_->SetVar("attackElapsedTime",0.0f);
//.........这里部分代码省略.........