1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 18:07:24 +08:00
osu-lazer/osu.Game/Graphics/Containers/ParallaxContainer.cs

55 lines
1.6 KiB
C#
Raw Normal View History

2016-12-06 17:56:20 +08:00
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics.Containers;
2016-09-30 17:45:55 +08:00
using osu.Framework.Graphics;
using osu.Framework.Input;
using OpenTK;
2016-10-10 16:17:26 +08:00
using osu.Framework;
2016-11-09 07:13:20 +08:00
using osu.Framework.Allocation;
using osu.Framework.Graphics.Transformations;
2016-09-30 17:45:55 +08:00
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;
2016-11-11 06:40:42 +08:00
AddInternal(content = new Container
2016-11-09 07:13:20 +08:00
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
2016-09-30 17:45:55 +08:00
}
2016-11-11 06:40:42 +08:00
private Container content;
private InputManager input;
2016-11-11 06:40:42 +08:00
protected override Container<Drawable> Content => content;
[BackgroundDependencyLoader]
private void load(UserInputManager input)
2016-09-30 17:45:55 +08:00
{
this.input = input;
2016-09-30 17:45:55 +08:00
}
bool firstUpdate = true;
2016-09-30 17:45:55 +08:00
protected override void Update()
{
base.Update();
content.MoveTo((ToLocalSpace(input.CurrentState.Mouse.NativeState.Position) - DrawSize / 2) * ParallaxAmount, firstUpdate ? 0 : 1000, EasingTypes.OutQuint);
2016-09-30 17:45:55 +08:00
content.Scale = new Vector2(1 + ParallaxAmount);
firstUpdate = false;
2016-09-30 17:45:55 +08:00
}
}
}