osu/osu.Game/Graphics/Containers/ParallaxContainer.cs

44 lines
1.2 KiB
C#
Raw Normal View History

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