Ejemplo n.º 1
0
        public void TreeAdd()
        {
            var tc = new TestCore();

            tc.Init();

            var t1 = Texture2D.Load(@"../../Core/TestData/IO/AltseedPink.png");

            Assert.NotNull(t1);

            var s = new SpriteNode();

            s.Src      = new RectF(new Vector2F(100, 100), new Vector2F(100, 100));
            s.Texture  = t1;
            s.Position = new Vector2F(100, 100);

            var s2 = new SpriteNode();

            s2.Src      = new RectF(new Vector2F(200, 200), new Vector2F(100, 100));
            s2.Texture  = t1;
            s2.Position = new Vector2F(200, 200);

            s.AddChildNode(s2);

            tc.LoopBody(c =>
            {
                if (c == 100)
                {
                    Engine.AddNode(s);
                }
            }, null);

            tc.End();
        }
Ejemplo n.º 2
0
        public void IsDrawnActuallyWithNoDrawnNode()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            node.Texture        = texture;
            node.CenterPosition = texture.Size / 2;
            node.Position       = new Vector2F(100, 100);
            Engine.AddNode(node);

            var node2 = new TransformNode();

            node2.CenterPosition = texture.Size / 2;
            node2.Position       = new Vector2F(200, 200);

            var node3 = new RectangleNode();

            node3.RectangleSize  = texture.Size;
            node3.Texture        = texture;
            node3.CenterPosition = texture.Size / 2;
            node3.Position       = new Vector2F(300, 300);

            tc.LoopBody(c =>
            {
                if (c == 2)
                {
                    node.AddChildNode(node2);
                }
                else if (c == 4)
                {
                    node.IsDrawn = false;
                    Assert.IsFalse(node.IsDrawnActually);
                }

                else if (c == 6)
                {
                    node2.AddChildNode(node3);
                }

                else if (c == 8)
                {
                    node.IsDrawn = true;

                    Assert.IsTrue(node.IsDrawnActually);
                    Assert.IsTrue(node3.IsDrawnActually);
                }
            }, null);

            tc.End();
        }
Ejemplo n.º 3
0
        public void VisibleTransformNodeInfo()
        {
            var tc = new TestCore(new Configuration()
            {
                VisibleTransformInfo = true
            });

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node4 = new SpriteNode();

            node4.Texture  = texture;
            node4.Position = new Vector2F(400, 200);
            node4.Src      = new RectF(0, 0, 128, 128);
            node4.VisibleTransformNodeInfo = false;
            Engine.AddNode(node4);

            var node5 = new SpriteNode();

            node5.Texture                  = texture;
            node5.CenterPosition           = texture.Size / 2;
            node5.Position                 = new Vector2F(200, 200);
            node5.Angle                    = 68;
            node5.ZOrder                   = 200;
            node5.Scale                    = new Vector2F(0.8f, 0.5f);
            node5.Color                    = new Color(0, 0, 255);
            node5.VisibleTransformNodeInfo = false;
            node4.AddChildNode(node5);

            var node6 = new SpriteNode();

            node6.Texture                  = texture;
            node6.CenterPosition           = texture.Size / 2;
            node6.Position                 = new Vector2F(300, 300);
            node6.ZOrder                   = 150;
            node6.Color                    = new Color(0, 255, 0);
            node6.VisibleTransformNodeInfo = false;
            node5.AddChildNode(node6);

            tc.Duration = 600;
            tc.LoopBody(c =>
            {
                node4.VisibleTransformNodeInfo = (c / 10) % 2 == 0;
                node5.VisibleTransformNodeInfo = !node4.VisibleTransformNodeInfo;
                node6.VisibleTransformNodeInfo = !node5.VisibleTransformNodeInfo;
            }
                        , null);

            tc.End();
        }
Ejemplo n.º 4
0
        public void CenterPosition()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            node.Texture        = texture;
            node.CenterPosition = texture.Size / 2;
            node.Position       = Engine.WindowSize / 2;
            Engine.AddNode(node);

            var child = new SpriteNode();

            child.Texture        = texture;
            child.CenterPosition = texture.Size / 2;
            //child.Position = texture.Size / 2;
            node.AddChildNode(child);

            var child2 = new SpriteNode();

            child2.Texture        = texture;
            child2.CenterPosition = texture.Size / 2;
            child2.Position       = texture.Size / 2;
            node.AddChildNode(child2);

            tc.LoopBody(c =>
            {
                node.Angle   += 1.0f;
                child.Angle  += 1.0f;
                child2.Angle += 1.0f;
            }
                        , null);

            tc.End();
        }
Ejemplo n.º 5
0
        public void AutoCollisionSystem()
        {
            var tc = new TestCore()
            {
                Duration = int.MaxValue
            };

            tc.Init();

            var texture = Texture2D.Load(@"../../Core/TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var scene   = new Altseed.Node();
            var manager = new CollisionManagerNode();

            scene.AddChildNode(manager);

            Engine.AddNode(scene);

            var player = new Player(texture);

            scene.AddChildNode(player);

            var comparison = new SpriteNode()
            {
                Texture  = texture,
                Position = new Vector2F(300f, 300f)
            };
            var colliderNode = new CircleColliderNode()
            {
                Radius   = texture.Size.X / 2,
                Position = comparison.Position
            };

            comparison.AddChildNode(colliderNode);

            scene.AddChildNode(comparison);

            tc.LoopBody(null, x =>
            {
                if (Engine.Keyboard.GetKeyState(Keys.Escape) == ButtonState.Push)
                {
                    tc.Duration = 0;
                }
                if (x == 10)
                {
                    Assert.True(manager.ContainsCollider(colliderNode));
                    Assert.AreEqual(manager.ColliderCount, 2);
                }
            });
            tc.End();
        }
Ejemplo n.º 6
0
        public void AutoCollisionSystem_Circle()
        {
            var tc = new TestCore();

            tc.Init();
            //tc.Duration = int.MaxValue;

            var texture = Texture2D.LoadStrict(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var scene   = new Altseed2.Node();
            var manager = new CollisionManagerNode();

            scene.AddChildNode(manager);

            Engine.AddNode(scene);

            var player = new Player_Circle(texture);

            scene.AddChildNode(player);

            var comparison = new SpriteNode()
            {
                Texture        = texture,
                CenterPosition = texture.Size / 2,
                Position       = new Vector2F(500f, 100f),
                Scale          = new Vector2F(0.8f, 0.8f),
            };
            var colliderNode = new CircleColliderNode()
            {
                Radius = texture.Size.X / 2,
            };

            comparison.AddChildNode(colliderNode);
            colliderNode.AddChildNode(ColliderVisualizeNodeFactory.Create(colliderNode));
            scene.AddChildNode(comparison);

            tc.LoopBody(null, x =>
            {
                if (Engine.Keyboard.GetKeyState(Key.Escape) == ButtonState.Push)
                {
                    tc.Duration = 0;
                }
                if (x == 10)
                {
                    Assert.True(manager.ContainsCollider(colliderNode));
                    Assert.AreEqual(manager.ColliderCount, 2);
                }
            });
            tc.End();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            // Altseed2 を初期化します。
            Engine.Initialize("Collision", 640, 480);

            // 衝突判定が行われるノードの親ノードを作成します。
            var scene = new Node();

            // コライダを自動処理するノードをシーンに登録します。
            scene.AddChildNode(new CollisionManagerNode());


            // 衝突判定を持つSpriteNodeを生成します。
            var texture = Texture2D.Load(@"TestData/IO/AltseedPink256.png");
            var sprite  = new SpriteNode()
            {
                Position       = new Vector2F(200f, 200f),
                Scale          = new Vector2F(0.5f, 0.5f),
                Texture        = texture,
                CenterPosition = texture.Size / 2,
            };

            // 円形コライダノードを生成します。
            var collider = new CircleColliderNode()
            {
                Radius = texture.Size.X / 2,
            };

            // colliderの衝突判定を視覚化できるノードを生成します。
            var visualizer = ColliderVisualizeNodeFactory.Create(collider);

            // エンジンにノードを追加します。
            scene.AddChildNode(sprite);
            sprite.AddChildNode(collider);
            collider.AddChildNode(visualizer);
            Engine.AddNode(scene);

            // メインループ。
            // Altseed のウインドウが閉じられると終了します。
            while (Engine.DoEvents())
            {
                // Altseed を更新します。
                Engine.Update();
            }

            // Altseed の終了処理をします。
            Engine.Terminate();
        }
Ejemplo n.º 8
0
        public void TransformNodeInfo()
        {
            var tc = new TestCore(new Configuration()
            {
                VisibleTransformInfo = true
            });

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            node.Texture  = texture;
            node.Position = new Vector2F(100, 200);
            node.Src      = new RectF(0, 0, 128, 128);
            Engine.AddNode(node);

            var node2 = new SpriteNode();

            node2.Texture        = texture;
            node2.CenterPosition = texture.Size / 2;
            node2.Position       = new Vector2F(200, 200);
            node2.Angle          = 68;
            node2.ZOrder         = 200;
            node2.Scale          = new Vector2F(0.8f, 0.5f);
            node2.Color          = new Color(0, 0, 255);
            node.AddChildNode(node2);

            var node3 = new SpriteNode();

            node3.Texture        = texture;
            node3.CenterPosition = texture.Size / 2;
            node3.Position       = new Vector2F(300, 300);
            node3.ZOrder         = 150;
            node3.Color          = new Color(0, 255, 0);
            node2.AddChildNode(node3);

            tc.Duration = 600;
            tc.LoopBody(c =>
            {
            }
                        , null);

            tc.End();
        }
Ejemplo n.º 9
0
        public void EnuemrateAncestors()
        {
            var tc = new TestCore();

            tc.Init();

            var t1 = Texture2D.Load(@"../../Core/TestData/IO/AltseedPink.png");

            Assert.NotNull(t1);

            var s = new SpriteNode();

            s.Src      = new RectF(new Vector2F(100, 100), new Vector2F(100, 100));
            s.Texture  = t1;
            s.Position = new Vector2F(100, 100);

            var s2 = new SpriteNode();

            s2.Src      = new RectF(new Vector2F(200, 200), new Vector2F(100, 100));
            s2.Texture  = t1;
            s2.Position = new Vector2F(200, 0);

            s.AddChildNode(s2);

            Engine.AddNode(s);

            tc.LoopBody(c =>
            {
                if (c == 2)
                {
                    var e = s2.EnumerateAncestors().ToArray();
                    Assert.AreEqual(1, e.Length);
                    Assert.AreSame(e[0], s);
                }
                s.Angle++;
            }, null);

            tc.End();
        }
Ejemplo n.º 10
0
        public void AcnhorAndShapeNode()
        {
            var tc = new TestCore(new Configuration()
            {
                VisibleTransformInfo = true
            });

            tc.Init();

            var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 64);

            Assert.NotNull(font);

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var sprite = new SpriteNode();

            sprite.Texture = texture;
            sprite.ZOrder  = 5;

            Vector2F rectSize = texture.Size;
            var      parent   = new AnchorTransformerNode();

            parent.Position   = Engine.WindowSize / 2;
            parent.Size       = rectSize;
            parent.AnchorMode = AnchorMode.Fill;
            Engine.AddNode(sprite);
            sprite.AddChildNode(parent);

            var circle2 = new CircleNode()
            {
                Color    = new Color(0, 255, 0),
                Position = new Vector2F(400, 200),
                Radius   = 100f,
                VertNum  = 80,
                ZOrder   = 10,
            };

            var circle2Anchor = new AnchorTransformerNode();

            circle2Anchor.AnchorMin  = new Vector2F(0.0f, 0.0f);
            circle2Anchor.AnchorMax  = new Vector2F(0.5f, 1f);
            circle2Anchor.AnchorMode = AnchorMode.Fill;
            sprite.AddChildNode(circle2);
            circle2.AddChildNode(circle2Anchor);

            var circle3 = new CircleNode()
            {
                Color    = new Color(0, 0, 255),
                Position = new Vector2F(50, 400),
                Radius   = 100f,
                VertNum  = 50,
                ZOrder   = 15,
            };

            var circle3Anchor = new AnchorTransformerNode();

            circle3Anchor.AnchorMin  = new Vector2F(0.5f, 0.5f);
            circle3Anchor.AnchorMax  = new Vector2F(1f, 1f);
            circle3Anchor.AnchorMode = AnchorMode.Fill;
            circle2.AddChildNode(circle3);
            circle3.AddChildNode(circle3Anchor);

            var text2 = new TextNode()
            {
                Font     = font,
                FontSize = 20,
                Text     = "",
                ZOrder   = 10,
                Scale    = new Vector2F(0.8f, 0.8f),
                Color    = new Color(255, 128, 0)
            };

            Engine.AddNode(text2);

            tc.Duration = 10000;

            string infoText(AnchorTransformerNode n) =>
            $"Scale:{n.Scale}\n" +
            $"Position:{n.Position}\n" +
            $"Pivot:{n.Pivot}\n" +
            $"Size:{n.Size}\n" +
            $"Margin: LT:{n.LeftTop} RB:{n.RightBottom}\n" +
            $"Anchor: {n.AnchorMin} {n.AnchorMax}\n";

            tc.LoopBody(c =>
            {
                circle2Anchor.RightBottom = new Vector2F();
                circle3Anchor.RightBottom = new Vector2F();

                if (Engine.Keyboard.GetKeyState(Key.Right) == ButtonState.Hold)
                {
                    rectSize.X += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Left) == ButtonState.Hold)
                {
                    rectSize.X -= 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Down) == ButtonState.Hold)
                {
                    rectSize.Y += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Up) == ButtonState.Hold)
                {
                    rectSize.Y -= 1.5f;
                }

                if (Engine.Keyboard.GetKeyState(Key.D) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.A) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(-1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.S) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, 1.5f);
                }
                if (Engine.Keyboard.GetKeyState(Key.W) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, -1.5f);
                }

                if (Engine.Keyboard.GetKeyState(Key.Q) == ButtonState.Hold)
                {
                    circle2Anchor.Angle += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.E) == ButtonState.Hold)
                {
                    circle2Anchor.Angle -= 1.5f;
                }

                if (Engine.Keyboard.GetKeyState(Key.Z) == ButtonState.Hold)
                {
                    parent.Scale += new Vector2F(0.1f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.C) == ButtonState.Hold)
                {
                    parent.Scale -= new Vector2F(0.1f, 0);
                }

                parent.Size = rectSize;

                text2.Text = infoText(parent) + '\n' + infoText(circle2Anchor) + '\n' + infoText(circle3Anchor);
            }, null);

            tc.End();
        }
Ejemplo n.º 11
0
        public void TreeDelete()
        {
            var tc = new TestCore();

            tc.Init();

            var t1 = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(t1);

            var s = new Altseed2.Node();
            //s.Texture = t1;
            //s.Position = new Vector2F(100, 100);

            var s2 = new SpriteNode();

            s2.Texture  = t1;
            s2.Position = new Vector2F(100, 100);

            var s3 = new SpriteNode();

            s3.Texture  = t1;
            s3.Position = new Vector2F(100, 100);

            var s4 = new SpriteNode();

            s4.Texture  = t1;
            s4.Position = new Vector2F(100, 100);

            s.AddChildNode(s2);
            s2.AddChildNode(s3);
            s3.AddChildNode(s4);

            Engine.AddNode(s);

            tc.LoopBody(c =>
            {
                if (c == 100)
                {
                    Engine.RemoveNode(s);
                }
                if (c == 101)
                {
                    Assert.IsFalse(s.IsRegistered);
                    Assert.IsFalse(s2.IsRegistered);
                    Assert.IsFalse(s3.IsRegistered);
                    Assert.IsFalse(s4.IsRegistered);

                    var dc     = typeof(Engine).GetField("_DrawnCollection", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as DrawnCollection;
                    var drawns = typeof(DrawnCollection).GetField("_Drawns", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dc) as SortedDictionary <int, HashSet <IDrawn> >;
                    Assert.IsTrue(drawns.All(kv => kv.Value.Count == 0));
                }
                if (c == 110)
                {
                    Engine.AddNode(s);
                }
                if (c == 111)
                {
                    Assert.IsTrue(s.IsRegistered);
                    Assert.IsTrue(s2.IsRegistered);
                    Assert.IsTrue(s3.IsRegistered);
                    Assert.IsTrue(s4.IsRegistered);

                    var dc     = typeof(Engine).GetField("_DrawnCollection", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as DrawnCollection;
                    var drawns = typeof(DrawnCollection).GetField("_Drawns", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dc) as SortedDictionary <int, HashSet <IDrawn> >;
                    Assert.AreEqual(3, drawns.Sum(kv => kv.Value.Count));
                }
                if (c == 120)
                {
                    s2.RemoveChildNode(s3);
                    s2.FlushQueue();

                    Assert.AreEqual(RegisteredStatus.Free, s3.Status);

                    Assert.IsTrue(s.IsRegistered);
                    Assert.IsTrue(s2.IsRegistered);
                    Assert.IsFalse(s3.IsRegistered);
                    Assert.IsFalse(s4.IsRegistered);

                    var dc     = typeof(Engine).GetField("_DrawnCollection", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as DrawnCollection;
                    var drawns = typeof(DrawnCollection).GetField("_Drawns", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dc) as SortedDictionary <int, HashSet <IDrawn> >;
                    Assert.AreEqual(1, drawns.Sum(kv => kv.Value.Count));
                }
            }, null);

            tc.End();
        }
Ejemplo n.º 12
0
        public void Reusable()
        {
            var tc = new TestCore();

            tc.Init();

            var t1 = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(t1);

            var s = new SpriteNode();

            s.Texture  = t1;
            s.Position = new Vector2F(100, 100);

            var s2 = new SpriteNode();

            s2.Texture  = t1;
            s2.Position = new Vector2F(200, 200);
            s.AddChildNode(s2);
            Engine.AddNode(s);

            var n = new Node();

            tc.Duration = 5;
            tc.LoopBody(c =>
            {
                switch (c)
                {
                case 0:
                    break;

                case 1:
                    break;

                case 2:
                    Assert.True(s2.Parent == s);
                    break;

                case 3:
                    Engine.RemoveNode(s);
                    break;

                case 4:
                    Assert.Null(s.Parent);
                    Assert.True(s.Status == RegisteredStatus.Free);
                    break;

                case 5:
                    s.RemoveChildNode(s2);
                    Assert.True(s2.Status == RegisteredStatus.WaitingRemoved);
                    s.FlushQueue();
                    Assert.Null(s2.Parent);
                    Assert.True(s2.Status == RegisteredStatus.Free);
                    Assert.AreEqual(s.Children.Count, 0);
                    break;
                }
            }, null);

            tc.End();
        }
Ejemplo n.º 13
0
        public void Anchor()
        {
            var tc = new TestCore();

            tc.Init();

            var font = Font.LoadDynamicFont("../../Core/TestData/Font/mplus-1m-regular.ttf", 30);

            Assert.NotNull(font);

            var texture = Texture2D.Load(@"../../Core/TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            Vector2F rectSize = texture.Size;
            var      parent   = new PolygonNode();

            parent.Position = new Vector2F(320, 240);
            //parent.Pivot = new Vector2F(0.5f, 0.5f);
            parent.SetVertexes(new[] {
                new Vector2F(0, 0),
                new Vector2F(rectSize.X, 0),
                new Vector2F(rectSize.X, rectSize.Y),
                new Vector2F(0, rectSize.Y),
            }, new Color(255, 255, 255, 255));
            parent.AdjustSize();
            Engine.AddNode(parent);

            var child = new SpriteNode();

            child.Texture   = texture;
            child.Position  = new Vector2F(120, 200);
            child.Src       = new RectF(new Vector2F(), texture.Size);
            child.Pivot     = new Vector2F(0.5f, 0.5f);
            child.AnchorMin = new Vector2F(0.2f, 0.0f);
            child.AnchorMax = new Vector2F(0.8f, 1f);
            child.ZOrder    = 10;
            child.Mode      = DrawMode.Fill;
            child.AdjustSize();
            parent.AddChildNode(child);

            var childText = new TextNode();

            childText.Font                = font;
            childText.Color               = new Color(0, 0, 0);
            childText.Text                = "あいうえお";
            childText.Pivot               = new Vector2F(0.5f, 0.5f);
            childText.AnchorMin           = new Vector2F(0.5f, 0.5f);
            childText.AnchorMax           = new Vector2F(0.5f, 0.5f);
            childText.ZOrder              = 15;
            childText.HorizontalAlignment = HorizontalAlignment.Center;
            childText.VerticalAlignment   = VerticalAlignment.Center;
            childText.Size                = child.Size;
            child.AddChildNode(childText);

            var text = new TextNode()
            {
                Font = font, Text = "", ZOrder = 10
            };

            Engine.AddNode(text);

            tc.Duration = 10000;
            tc.LoopBody(c =>
            {
                if (Engine.Keyboard.GetKeyState(Keys.Right) == ButtonState.Hold)
                {
                    rectSize.X += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Keys.Left) == ButtonState.Hold)
                {
                    rectSize.X -= 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Keys.Down) == ButtonState.Hold)
                {
                    rectSize.Y += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Keys.Up) == ButtonState.Hold)
                {
                    rectSize.Y -= 1.5f;
                }

                if (Engine.Keyboard.GetKeyState(Keys.D) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Keys.A) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(-1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Keys.S) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, 1.5f);
                }
                if (Engine.Keyboard.GetKeyState(Keys.W) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, -1.5f);
                }

                parent.SetVertexes(new[] {
                    new Vector2F(0, 0),
                    new Vector2F(rectSize.X, 0),
                    new Vector2F(rectSize.X, rectSize.Y),
                    new Vector2F(0, rectSize.Y),
                }, new Color(255, 255, 255, 255));
                parent.AdjustSize();

                text.Text = child.Size.ToString();
            }, null);

            tc.End();
        }
Ejemplo n.º 14
0
        public void Anchor()
        {
            var tc = new TestCore(new Configuration()
            {
                VisibleTransformInfo = true
            });

            tc.Init();

            var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 30);

            Assert.NotNull(font);

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var sprite = new SpriteNode();

            sprite.Texture = texture;
            sprite.ZOrder  = 5;

            Vector2F rectSize = texture.Size;
            var      parent   = new AnchorTransformerNode();

            parent.Position   = Engine.WindowSize / 2;
            parent.Size       = rectSize;
            parent.AnchorMode = AnchorMode.Fill;
            Engine.AddNode(sprite);
            sprite.AddChildNode(parent);

            var sprite2 = new SpriteNode();

            sprite2.Texture = texture;
            sprite2.Color   = new Color(255, 0, 0, 200);
            sprite2.ZOrder  = 10;

            var child = new AnchorTransformerNode();

            child.Position            = rectSize / 2;
            child.Pivot               = new Vector2F(0.5f, 0.5f);
            child.AnchorMin           = new Vector2F(0.0f, 0.0f);
            child.AnchorMax           = new Vector2F(1f, 1f);
            child.HorizontalAlignment = HorizontalAlignment.Left;
            child.VerticalAlignment   = VerticalAlignment.Center;
            child.Size       = sprite2.ContentSize;
            child.AnchorMode = AnchorMode.KeepAspect;
            sprite.AddChildNode(sprite2);
            sprite2.AddChildNode(child);

            var text = new TextNode();

            text.Font   = font;
            text.Color  = new Color(0, 0, 0);
            text.Text   = "あいうえお";
            text.ZOrder = 15;

            var childText = new AnchorTransformerNode();

            childText.Pivot     = new Vector2F(0.5f, 0.5f);
            childText.AnchorMin = new Vector2F(0.5f, 0.5f);
            childText.AnchorMax = new Vector2F(0.5f, 0.5f);
            childText.Size      = text.ContentSize;
            //childText.HorizontalAlignment = HorizontalAlignment.Center;
            //childText.VerticalAlignment = VerticalAlignment.Center;
            childText.AnchorMode = AnchorMode.ContentSize;
            sprite2.AddChildNode(text);
            text.AddChildNode(childText);

            var text2 = new TextNode()
            {
                Font   = font,
                Text   = "",
                ZOrder = 10,
                Scale  = new Vector2F(0.8f, 0.8f),
                Color  = new Color(255, 128, 0)
            };

            Engine.AddNode(text2);

            tc.Duration = 10000;

            string infoText(AnchorTransformerNode n) =>
            $"Scale:{n.Scale}\n" +
            $"Position:{n.Position}\n" +
            $"Pivot:{n.Pivot}\n" +
            $"Size:{n.Size}\n" +
            $"Margin: LT:{n.LeftTop} RB:{n.RightBottom}\n" +
            $"Anchor: {n.AnchorMin} {n.AnchorMax}\n";

            tc.LoopBody(c =>
            {
                if (Engine.Keyboard.GetKeyState(Key.Right) == ButtonState.Hold)
                {
                    rectSize.X += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Left) == ButtonState.Hold)
                {
                    rectSize.X -= 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Down) == ButtonState.Hold)
                {
                    rectSize.Y += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Up) == ButtonState.Hold)
                {
                    rectSize.Y -= 1.5f;
                }

                if (Engine.Keyboard.GetKeyState(Key.D) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.A) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(-1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.S) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, 1.5f);
                }
                if (Engine.Keyboard.GetKeyState(Key.W) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, -1.5f);
                }

                if (Engine.Keyboard.GetKeyState(Key.Q) == ButtonState.Hold)
                {
                    child.Angle += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.E) == ButtonState.Hold)
                {
                    child.Angle -= 1.5f;
                }

                if (Engine.Keyboard.GetKeyState(Key.Z) == ButtonState.Hold)
                {
                    parent.Scale += new Vector2F(0.1f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.C) == ButtonState.Hold)
                {
                    parent.Scale -= new Vector2F(0.1f, 0);
                }

                parent.Size = rectSize;

                text2.Text = infoText(parent) + '\n' + infoText(child) + '\n' + infoText(childText);
            }, null);

            tc.End();
        }