-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameView.cs
52 lines (44 loc) · 1.44 KB
/
GameView.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using Android.Content;
using Android.Graphics;
using Android.Util;
using Android.Views;
using Android.Content.Res;
using Android.App;
namespace Segmentus
{
//Singleton
class GameView : View
{
public static GameView Instance { get; set; }
public const int CanonWidth = 720;
public const int CanonHeight = 1280;
public static int xCenter, yCenter;
public static float scaleFactor;
public event Action<Canvas> DrawEvent;
public Pivot rootPivot;
static GameView()
{
Resources res = Application.Context.Resources;
int w = res.DisplayMetrics.WidthPixels;
int h = res.DisplayMetrics.HeightPixels;
xCenter = w / 2;
yCenter = h / 2;
scaleFactor = Math.Min((float)w / CanonWidth, (float)h / CanonHeight);
}
public GameView(Context context, IAttributeSet attrs) : base(context, attrs, 0)
{
Instance = this;
rootPivot = new Pivot(xCenter, yCenter);
}
protected override void OnDraw(Canvas canvas)
{
canvas.DrawColor(ColorBank.GetColor(ColorBank.Background));
canvas.Save();
canvas.Translate(rootPivot.X, rootPivot.Y);
DrawEvent?.Invoke(canvas);
canvas.Restore();
}
public override bool OnTouchEvent(MotionEvent e) => TouchHandler.Handle(e);
}
}