Add basic background display system.

This commit is contained in:
Dean Herbert
2016-09-30 18:45:55 +09:00
parent d93718d953
commit cc14aeb802
4 changed files with 90 additions and 1 deletions

View File

@ -0,0 +1,36 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics.Containers;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Graphics.Background
{
class Background : OsuLargeContainer
{
protected Sprite BackgroundSprite;
public override void Load()
{
base.Load();
Add(BackgroundSprite = new Sprite
{
Texture = Game.Textures.Get(@"Menu/background"),
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = Color4.DarkGray
});
}
protected override void Update()
{
base.Update();
BackgroundSprite.Scale = new Vector2(Math.Max(ActualSize.X / BackgroundSprite.Size.X, ActualSize.Y / BackgroundSprite.Size.Y));
}
}
}

View File

@ -0,0 +1,40 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Input;
using OpenTK;
namespace osu.Game.Graphics.Containers
{
class ParallaxContainer : LargeContainer
{
public float ParallaxAmount = 0.02f;
public override bool Contains(Vector2 screenSpacePos) => true;
private Container content = new LargeContainer()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
protected override Container AddTarget => content;
public override void Load()
{
base.Load();
Add(content);
}
protected override bool OnMouseMove(InputState state)
{
content.Position = (state.Mouse.Position - ActualSize / 2) * ParallaxAmount;
return base.OnMouseMove(state);
}
protected override void Update()
{
base.Update();
content.Scale = new Vector2(1 + ParallaxAmount);
}
}
}