Esempio n. 1
0
    public static Scene MakeTestPivotScene()
    {
        var scene = new Scene()
        {
            Name = "Pivot test"
        };

        scene.Camera2D.SetViewFromHeightAndCenter(8.0f, new Vector2(3, 3));

        var texture_info = Director.Instance.GL.WhiteTextureInfo;

        var sprite = new SpriteUV()
        {
            TextureInfo = texture_info
        };

        sprite.Position = new Vector2(2, 3);

        sprite.Scale = new Vector2(2, 2);
        sprite.Pivot = new Vector2(0.5f, 0.5f);

        sprite.Color     = new Vector4(0.0f, 0.0f, 1.0f, 0.5f);
        sprite.BlendMode = BlendMode.Normal;

        //FIXME:added
//		sprite.Name = "sprite001";
//		sprite.__isdebug = true;

        sprite.Schedule((dt) =>

        {
            float period_in_seconds = 3.0f;
            float wave = ((1.0f + FMath.Sin((float)Director.Instance.CurrentScene.SceneTime * Math.Pi / period_in_seconds)) * 0.5f);

            sprite.Rotation = Vector2.Rotation(Math.Pi * 2.0f * wave);
            sprite.Scale    = new Vector2(1.0f + 2.0f * wave);
        }
                        );

        //FIXME:added
//		sprite.__allowAdHocDraw = true;
//		sprite.AdHocDraw += () =>
//
//			{
//				// debug draw the emission rectangle in pink
//
//				if (false)
//				{
//					Director.Instance.GL.SetBlendMode( BlendMode.Additive );
//					Director.Instance.DrawHelpers.SetColor( Colors.Pink * 0.3f );
//					Director.Instance.DrawHelpers.DrawBounds2( Bounds2.QuadMinus1_1.Scale( sprite.Position, Math._00 ) );
//				}
//				else
//				{
//					Director.Instance.GL.SetBlendMode( BlendMode.Additive );
//					Director.Instance.DrawHelpers.SetColor( Colors.Pink * 0.3f );
//					Director.Instance.DrawHelpers.DrawDisk( new Vector2(1, 1), 1f, 16 );
////					Director.Instance.DrawHelpers.DrawBounds2( new Bounds2(new Vector2(1, 1), new Vector2(2, 2)) );
//				}
//			};


//		System.Console.WriteLine( Director.Instance.GL.GetViewportf().Aspect );
        Vector2 bpos = new Vector2(0.0f, 0.0f);

        AddButton(scene, "Pivot at 0,0", ref bpos, () => { sprite.Pivot = new Vector2(0.0f, 0.0f); });
        AddButton(scene, "Pivot at 0.5,0.5", ref bpos, () => { sprite.Pivot = new Vector2(0.5f, 0.5f); });

        scene.AdHocDraw += () =>

        {
            Director.Instance.GL.ModelMatrix.Push();
            Director.Instance.GL.ModelMatrix.SetIdentity();             // go in world space

            Director.Instance.GL.SetBlendMode(BlendMode.None);
            Director.Instance.DrawHelpers.SetColor(Colors.Yellow);
            Director.Instance.DrawHelpers.DrawDisk(sprite.LocalToWorld(sprite.Pivot), 0.05f, 16);

            Director.Instance.GL.SetBlendMode(BlendMode.Normal);
            Director.Instance.SpriteRenderer.DefaultFontShader.SetColor(ref Colors.Yellow);
            Director.Instance.SpriteRenderer.DrawTextDebug(".Pivot=" + sprite.Pivot.ToString(), sprite.LocalToWorld(sprite.Pivot) + new Vector2(0.05f, 0.05f)
                                                           , scene.Camera2D.GetPixelSize() * EmbeddedDebugFontData.CharSizei.Y);

            Director.Instance.GL.ModelMatrix.Pop();
        };

        scene.AddChild(sprite, -1);

        return(scene);
    }