-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameScene.cs
91 lines (78 loc) · 2.14 KB
/
GameScene.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using SpriteKit;
using UIKit;
using CoreGraphics;
using Foundation;
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace Gladius
{
public class GameScene : SKScene
{
public GameScene() {
AnchorPoint = new CGPoint(0.5, 0.5);
}
private void AddAxes() {
CGPath pathToDraw;
var center = new CGPoint(0, 0);
var xAxis = new SKShapeNode();
pathToDraw = new CGPath();
pathToDraw.MoveToPoint(center);
pathToDraw.AddLineToPoint(new CGPoint(1000, 0));
xAxis.Path = pathToDraw;
xAxis.StrokeColor = UIColor.LightGray;
xAxis.LineWidth = 2;
AddChild(xAxis);
var yAxis = new SKShapeNode();
pathToDraw = new CGPath();
pathToDraw.MoveToPoint(center);
pathToDraw.AddLineToPoint(new CGPoint(0, 1000));
yAxis.Path = pathToDraw;
yAxis.StrokeColor = UIColor.LightGray;
yAxis.LineWidth = 2;
AddChild(yAxis);
var zAxis = new SKShapeNode();
pathToDraw = new CGPath();
pathToDraw.MoveToPoint(center);
pathToDraw.AddLineToPoint(new CGPoint(center.X - 1000, center.Y - 1000));
zAxis.Path = pathToDraw;
zAxis.StrokeColor = UIColor.LightGray;
zAxis.LineWidth = 2;
AddChild(zAxis);
}
private void PresentBVHMenu() {
var bvhFiles = NSBundle
.MainBundle
.PathsForResources("bvh", "BVHs")
.ToDictionary(Path.GetFileNameWithoutExtension);
for (var i = 0; i < bvhFiles.Count; i++) {
var bvhFile = bvhFiles.ElementAt(i);
var label = SKButtonNode.WithText(bvhFile.Key, () => {
LoadBvh(bvhFile.Value);
});
label.Position = new CGPoint(-200, 75 - (i * 20));
AddChild(label);
}
}
private void LoadBvh(string bvhName) {
if (_root != null)
RemoveChildren(_root.SkNodes.ToArray());
_bvh = new BVH(bvhName);
_root = _bvh.Roots.First();
_root.Draw(this, _bvh.FrameTimeSecs);
NSTimer.CreateRepeatingScheduledTimer(_bvh.FrameTimeSecs, t => {
if (_bvh.PlayOneFrame())
_root.Draw(this, _bvh.FrameTimeSecs);
});
}
public override void DidMoveToView(SKView view) {
BackgroundColor = UIColor.White;
//AddAxes();
PresentBVHMenu();
}
private BVH _bvh;
private Node _root;
}
}