mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Add basic background display system.
This commit is contained in:
36
osu.Game/Graphics/Background/Background.cs
Normal file
36
osu.Game/Graphics/Background/Background.cs
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
40
osu.Game/Graphics/Containers/ParallaxContainer.cs
Normal file
40
osu.Game/Graphics/Containers/ParallaxContainer.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,10 @@ using osu.Game.Configuration;
|
|||||||
using osu.Game.GameModes.Menu;
|
using osu.Game.GameModes.Menu;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.OS;
|
using osu.Framework.OS;
|
||||||
|
using osu.Game.Graphics.Background;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
|
||||||
namespace osu.Game
|
namespace osu.Game
|
||||||
{
|
{
|
||||||
@ -22,7 +25,15 @@ namespace osu.Game
|
|||||||
{
|
{
|
||||||
base.Load();
|
base.Load();
|
||||||
|
|
||||||
Add(new MainMenu());
|
Add(new Drawable[] {
|
||||||
|
new ParallaxContainer
|
||||||
|
{
|
||||||
|
Children = new [] {
|
||||||
|
new Background()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new MainMenu()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
@ -62,6 +62,8 @@
|
|||||||
<Compile Include="GameModes\Direct\OnlineListing.cs" />
|
<Compile Include="GameModes\Direct\OnlineListing.cs" />
|
||||||
<Compile Include="GameModes\Play\SongSelectPlay.cs" />
|
<Compile Include="GameModes\Play\SongSelectPlay.cs" />
|
||||||
<Compile Include="GameModes\Edit\SongSelectEdit.cs" />
|
<Compile Include="GameModes\Edit\SongSelectEdit.cs" />
|
||||||
|
<Compile Include="Graphics\Background\Background.cs" />
|
||||||
|
<Compile Include="Graphics\Containers\ParallaxContainer.cs" />
|
||||||
<Compile Include="Graphics\Containers\OsuContainer.cs" />
|
<Compile Include="Graphics\Containers\OsuContainer.cs" />
|
||||||
<Compile Include="Graphics\Containers\OsuGameMode.cs" />
|
<Compile Include="Graphics\Containers\OsuGameMode.cs" />
|
||||||
<Compile Include="Graphics\Containers\OsuLargeContainer.cs" />
|
<Compile Include="Graphics\Containers\OsuLargeContainer.cs" />
|
||||||
|
Reference in New Issue
Block a user