void Urho2DSpriterAnimation::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); camera->SetZoom(1.5f * Min((float)graphics->GetWidth() / 1280.0f, (float)graphics->GetHeight() / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.5) is set for full visibility at 1280x800 resolution) ResourceCache* cache = GetSubsystem<ResourceCache>(); AnimationSet2D* spriterAnimationSet = cache->GetResource<AnimationSet2D>("Urho2D/imp/imp.scml"); if (!spriterAnimationSet) return; spriterNode_ = scene_->CreateChild("SpriterAnimation"); AnimatedSprite2D* spriterAnimatedSprite = spriterNode_->CreateComponent<AnimatedSprite2D>(); spriterAnimatedSprite->SetAnimationSet(spriterAnimationSet); spriterAnimatedSprite->SetAnimation(spriterAnimationSet->GetAnimation(spriterAnimationIndex_)); }
void EnemyEntity::Start() { ResourceCache* cache = GetSubsystem<ResourceCache>(); AnimationSet2D* animationSet = cache->GetResource<AnimationSet2D>("Urho2D/tortuga2.scml"); if (!animationSet) return; AnimatedSprite2D* animatedSprite = node_->CreateComponent<AnimatedSprite2D>(); animatedSprite->SetLayer(2); // Set animation animatedSprite->SetAnimationSet(animationSet); animatedSprite->SetAnimation("walk"); animatedSprite->SetSpeed(1.0f); RigidBody2D* bodysprite = node_->CreateComponent<RigidBody2D>(); bodysprite->SetBodyType(BT_DYNAMIC); bodysprite->SetFixedRotation(true); //bodysprite->SetBullet(false); //bodysprite->SetLinearVelocity(Vector2::ZERO); CollisionCircle2D* circle = node_->CreateComponent<CollisionCircle2D>(); // Set radius circle->SetRadius(1.2f); circle->SetDensity(1.0f); circle->SetFriction(0.4f); circle->SetRestitution(0.0f); circle->SetCenter(0,0.35f); circle->SetCategoryBits(8192); circle->SetMaskBits(65533); vel = Vector2(-2.0f,0); }
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()); } }