public override void Start() { // We setup our scene, main camera and viewport _viewport = GetSubsystem <Renderer>().GetViewport(0); _scene = new Scene(); _scene.CreateComponent <Octree>().SetSize(new BoundingBox(1, 100), 3); _viewport.Scene = _scene; _camera = _scene.CreateChild("Camera").CreateComponent <Camera>(); _camera.Node.Position = new Vector3(50, 10, -1); _camera.Orthographic = true; _camera.OrthoSize = 26; _viewport.Camera = _camera; // We create a sound source for the music and the music SoundSource musicSource = _scene.CreateComponent <SoundSource>(); Sound music = Cache.Get <Sound>("music/Happy_Bee.ogg"); music.SetLooped(true); musicSource.Play(music); musicSource.SetSoundType("Music"); // We don't need a sound listener for the above, but we add one for the sounds and adjust the music gain Audio audioSystem = GetSubsystem <Audio>(); audioSystem.SetListener(_camera.Node.CreateComponent <SoundListener>()); audioSystem.SetMasterGain("Music", 0.3f); // We create a background node which is a child of the camera so it won't move relative to it Node bg = _camera.Node.CreateChild("Background"); StaticSprite2D bgspr = bg.CreateComponent <StaticSprite2D>(); bgspr.SetSprite(Cache.Get <Sprite2D>("scenarios/grasslands/bg.png")); bg.SetPosition(new Vector3(0, 0, 100)); bg.SetScale2D(Vector2.One * 5); // We add a physics world so we can simulate physics, and enable CCD PhysicsWorld2D pw = _scene.CreateComponent <PhysicsWorld2D>(); pw.SetContinuousPhysics(true); // We create a terrain, vehicle and cloud system _terrain = new Terrain(_scene); _vehicle = CreateVehicle(new Vector2(50, 10)); _clouds = new Clouds(50, 5, 40, 16, 40); // We subscribe to the PostUpdateEvent SubscribeToEvent <PostUpdateEvent>(PostUpdate); // If we're building a debug release, we draw debug data #if DEBUG DebugRenderer dbr = _scene.CreateComponent <DebugRenderer>(); pw.SetDrawCenterOfMass(true); pw.SetDrawJoint(true); pw.SetDrawPair(true); pw.SetDrawShape(true); SubscribeToEvent <PostRenderUpdateEvent>(e => { _scene.GetComponent <PhysicsWorld2D>().DrawDebugGeometry(dbr, false); }); #endif }
void UpdateSizeHud(int value) { Node xNode = hudScene.GetChild("hudSize", true); if (xNode != null) { Node fillx = xNode.GetChild("hudSizeFill"); if (fillx != null) { StaticSprite2D hudSprite = fillx.GetComponent <StaticSprite2D>(); hudSprite.SetSprite(filler[value]); } } }
void CreateHUD() { float hscal = 0.4f; // // create a 2nd viewport and scene for a hud with sprites. // hudScene = new Scene(); hudScene.CreateComponent <Octree>(); // Create camera node var hudCam = hudScene.CreateChild("HudCamera"); // Set camera's position hudCam.SetPosition(new Vector3(0.0f, 0.0f, -10.0f)); hudCamera = hudCam.CreateComponent <Camera>(); hudCamera.SetOrthographic(true); var graphics = GetSubsystem <Graphics>(); hudCamera.SetOrthoSize((float)graphics.GetHeight() * PixelSize); //PIXEL_SIZE var cache = GetSubsystem <ResourceCache>(); // add a crosshair in the center of the screen var sprite = cache.GetResource <Sprite2D>("Textures/NinjaSnowWar/Sight.png"); var targetSprite_ = hudScene.CreateChild("targetSprite"); targetSprite_.SetPosition2D(new Vector2(0, 0)); targetSprite_.SetScale2D(new Vector2(0.75f, 0.75f)); var staticSprite = targetSprite_.CreateComponent <StaticSprite2D>(); staticSprite.SetSprite(sprite); // Set sprite staticSprite.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA); // Set blend mode staticSprite.SetAlpha(0.3f); // borrow the spinning coin from the 2DSprite example to show what the possibilities are float halfWidth = graphics.Width * 0.5f * PixelSize; float halfHeight = graphics.Height * 0.5f * PixelSize; // Get animation set AnimationSet2D animationSet = cache.Get <AnimationSet2D>("Urho2D/GoldIcon.scml"); if (animationSet == null) { return; } var spriteNode2 = hudScene.CreateChild("AnimatedSprite2D"); AnimatedSprite2D animatedSprite = spriteNode2.CreateComponent <AnimatedSprite2D>(); animatedSprite.AnimationSet = animationSet; // Set animation animatedSprite.SetAnimation("idle", LoopMode2D.LM_DEFAULT); spriteNode2.SetPosition2D(new Vector2(halfWidth - 0.4f, halfHeight - 0.4f)); // (bullet) mass, speed size feature huds filler.Push(cache.GetResource <Sprite2D>("Textures/hudfill1.png")); filler.Push(cache.GetResource <Sprite2D>("Textures/hudfill2.png")); filler.Push(cache.GetResource <Sprite2D>("Textures/hudfill3.png")); filler.Push(cache.GetResource <Sprite2D>("Textures/hudfill4.png")); filler.Push(cache.GetResource <Sprite2D>("Textures/hudfill5.png")); filler.Push(cache.GetResource <Sprite2D>("Textures/hudfill6.png")); Sprite2D spritem = cache.GetResource <Sprite2D>("Textures/hudmass.png"); Node hudm = hudScene.CreateChild("hudMass"); hudm.SetScale2D(new Vector2(hscal, hscal)); hudm.SetPosition2D(new Vector2(0f - (halfWidth / 3.0f), halfHeight - 0.4f)); StaticSprite2D hudSpritem = hudm.CreateComponent <StaticSprite2D>(); hudSpritem.SetSprite(spritem); hudSpritem.SetAlpha(0.9f); hudSpritem.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA); hudSpritem.SetOrderInLayer(3); Node hudfm = hudm.CreateChild("hudMassFill"); hudfm.SetScale2D(new Vector2(1f, 1f)); hudfm.SetPosition2D(new Vector2(0f, 0f)); StaticSprite2D hudSpritefm = hudfm.CreateComponent <StaticSprite2D>(); hudSpritefm.SetSprite(filler[0]); hudSpritefm.SetAlpha(0.9f); hudSpritefm.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA); hudSpritefm.SetOrderInLayer(-3); Sprite2D sprites = cache.GetResource <Sprite2D>("Textures/hudspeed.png"); Node huds = hudScene.CreateChild("hudSpeed"); huds.SetScale2D(new Vector2(hscal, hscal)); huds.SetPosition2D(new Vector2(0f, halfHeight - 0.4f)); StaticSprite2D hudSprites = huds.CreateComponent <StaticSprite2D>(); hudSprites.SetSprite(sprites); hudSprites.SetAlpha(0.9f); hudSprites.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA); hudSprites.SetOrderInLayer(3); Node hudsm = huds.CreateChild("hudSpeedFill"); hudsm.SetScale2D(new Vector2(1f, 1f)); hudsm.SetPosition2D(new Vector2(0f, 0f)); StaticSprite2D hudSpritesm = hudsm.CreateComponent <StaticSprite2D>(); hudSpritesm.SetSprite(filler[0]); hudSpritesm.SetAlpha(0.9f); hudSpritesm.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA); hudSpritesm.SetOrderInLayer(-3); Sprite2D spritez = cache.GetResource <Sprite2D>("Textures/hudsize.png"); Node hudz = hudScene.CreateChild("hudSize"); hudz.SetScale2D(new Vector2(hscal, hscal)); hudz.SetPosition2D(new Vector2(0f + (halfWidth / 3.0f), halfHeight - 0.4f)); StaticSprite2D hudSpritez = hudz.CreateComponent <StaticSprite2D>(); hudSpritez.SetSprite(spritez); hudSpritez.SetAlpha(0.9f); hudSpritez.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA); hudSpritez.SetOrderInLayer(3); Node hudzm = hudz.CreateChild("hudSizeFill"); hudzm.SetScale2D(new Vector2(1f, 1f)); hudzm.SetPosition2D(new Vector2(0f, 0f)); StaticSprite2D hudSpritezm = hudzm.CreateComponent <StaticSprite2D>(); hudSpritezm.SetSprite(filler[0]); hudSpritezm.SetAlpha(0.9f); hudSpritezm.SetBlendMode(AtomicEngine.BlendMode.BLEND_ALPHA); hudSpritezm.SetOrderInLayer(-3); }