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
|
|
|
|
|
{
|
2016-10-01 17:40:14 +08:00
|
|
|
|
class ParallaxContainer : Container
|
2016-09-30 17:45:55 +08:00
|
|
|
|
{
|
|
|
|
|
public float ParallaxAmount = 0.02f;
|
|
|
|
|
|
|
|
|
|
public override bool Contains(Vector2 screenSpacePos) => true;
|
|
|
|
|
|
2016-10-01 17:40:14 +08:00
|
|
|
|
public ParallaxContainer()
|
2016-09-30 17:45:55 +08:00
|
|
|
|
{
|
2016-10-01 17:40:14 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2016-10-09 17:56:41 +08:00
|
|
|
|
AddInternal(content = new Container()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre
|
|
|
|
|
});
|
2016-10-01 17:40:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-09 17:56:41 +08:00
|
|
|
|
private Container content;
|
2016-09-30 17:45:55 +08:00
|
|
|
|
|
2016-10-09 17:56:41 +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)
|
|
|
|
|
{
|
2016-10-01 17:40:14 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|