1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 22:27:25 +08:00
osu-lazer/osu.Game/Graphics/Containers/ParallaxContainer.cs

46 lines
1.2 KiB
C#
Raw Normal View History

2016-09-30 17:45:55 +08:00
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics;
using osu.Framework.Input;
using OpenTK;
namespace osu.Game.Graphics.Containers
{
class ParallaxContainer : Container
2016-09-30 17:45:55 +08:00
{
public float ParallaxAmount = 0.02f;
public override bool Contains(Vector2 screenSpacePos) => true;
public ParallaxContainer()
2016-09-30 17:45:55 +08:00
{
RelativeSizeAxes = Axes.Both;
AddInternal(content = new Container()
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
}
private Container content;
2016-09-30 17:45:55 +08:00
protected override Container Content => content;
2016-09-30 17:45:55 +08:00
public override void Load()
{
base.Load();
}
protected override bool OnMouseMove(InputState state)
{
content.Position = (state.Mouse.Position - Size / 2) * ParallaxAmount;
2016-09-30 17:45:55 +08:00
return base.OnMouseMove(state);
}
protected override void Update()
{
base.Update();
content.Scale = new Vector2(1 + ParallaxAmount);
}
}
}