public void PolygonNode_SetVertexesByVector2F() { var tc = new TestCore(new Configuration() { WaitVSync = false }); tc.Init(); var node = new PolygonNode(); Engine.AddNode(node); tc.LoopBody(c => { var sin = MathF.Sin(MathHelper.DegreeToRadian(c)) * 50; var cos = MathF.Cos(MathHelper.DegreeToRadian(c)) * 50; node.SetVertexes(new[] { new Vector2F(100 + cos, 100 - sin), new Vector2F(100 - sin, 100 - cos), new Vector2F(100 - cos, 100 + sin), new Vector2F(100 + sin, 100 + cos), }, new Color(255, c % 255, 255, 255)); }, null); tc.End(); }
public void PolygonNode() { var tc = new TestCore(); tc.Init(); PolygonNode node = new PolygonNode() { Position = new Vector2F(250, 250) }; Engine.AddNode(node); Span <Vector2F> span = stackalloc Vector2F[] { new Vector2F(-100, -100), new Vector2F(100, -100), new Vector2F(100, 100), new Vector2F(-100, 100), }; node.SetVertexes(span, new Color(255, 0, 0)); foreach (var current in node.Buffers) { System.Diagnostics.Debug.WriteLine(current); } tc.LoopBody(c => { }, null); tc.End(); }
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(); }
static void Main(string[] args) { // Altseed を初期化します。 Engine.Initialize("Sound_BGM", 640, 480); // 音ファイルを読み込みます。 // 効果音の場合は第2引数を true に設定して再生しながら解凍することが推奨されている。 var bgm = Sound.Load(@"TestData\Sound\bgm1.ogg", false); // 音を再生します。 var id = Engine.Sound.Play(bgm); // スペクトルバーのインスタンスを1024個作成します。 var spectrumBars = new PolygonNode[1024]; for (int i = 0; i < 1024; ++i) { // ※ 640 / 1024 = 0.625 var spectrumBar = new PolygonNode(); spectrumBar.Position = new Vector2F(i * 0.625f, 1.0f); var vertexes = new Vector2F[4]; vertexes[0] = new Vector2F(0.0f, 480.0f); vertexes[1] = new Vector2F(0.0f, 480.0f); vertexes[2] = new Vector2F(0.625f, 480.0f); vertexes[3] = new Vector2F(0.625f, 480.0f); spectrumBar.SetVertexes(vertexes); spectrumBars[i] = spectrumBar; Engine.AddNode(spectrumBar); } // メインループ。 // Altseed のウインドウが閉じられると終了します。 while (Engine.DoEvents()) { // Altseedを更新します。 Engine.Update(); // 再生されている音のスペクトル情報を取得します。 // データの長さは2のn乗でなくてはなりません。 var spectrum = Engine.Sound.GetSpectrum(id, 1024, FFTWindow.Rectangular); // 取得したスペクトル情報をスペクトルバーに反映させます。 for (int i = 0; i < 1024; ++i) { var vertexes = new Vector2F[4]; vertexes[0] = new Vector2F(0.0f, 480.0f); vertexes[1] = new Vector2F(0.0f, 480.0f - spectrum[i]); vertexes[2] = new Vector2F(0.625f, 480.0f - spectrum[i]); vertexes[3] = new Vector2F(0.625f, 480.0f); spectrumBars[i].SetVertexes(vertexes); } // 音の再生が終了しているか調べる。 if (!Engine.Sound.GetIsPlaying(id)) { break; } } // Altseed の終了処理をします。 Engine.Terminate(); }