示例#1
0
        public StarlingGameSpriteWithTank()
        {
            var textures = new StarlingGameSpriteWithTankTextures(new_texsprite_crop);

            this.autorotate = true;

            this.onbeforefirstframe += delegate
            {
                // this will be called once.



                // 12 FPS
                //var c = 64;

                // 60 FPS
                // ios 17FPS ?
                //var c = 20;

                // ios8 60FPS!
                var c = 10;

                for (int i = 0; i < c; i++)
                {
                    for (int yi = 0; yi < c; yi++)
                    {
                        var rot = random.NextDouble() * Math.PI;

                        var tank1 = new VisualTank(textures, this);


                        // setting up some randomization
                        tank1.SetPositionAndAngle(i * 128, yi * 128, rot);

                        // this will be called a lot.
                        onframe += delegate
                        {
                            tank1.Animate(1);
                        };
                    }
                }
            };
        }
        public VisualTank(StarlingGameSpriteWithTankTextures textures, StarlingGameSpriteBase Context)
        {
            this.Context = Context;



            #region visual
            currentshadow = new Image(
                textures.greentank_shadow()
                )
            {
            }.AttachTo(
                Context.Content_layer2_shadows
                );

            currentvisual = new Sprite().AttachTo(Context.Content);



            tanktrackpattern1 = new Image(
                textures.tanktrackpattern()
                )
            {
            }.AttachTo(
                currentvisual
                );


            tanktrackpattern0 = new Image(
                textures.tanktrackpattern()
                )
            {
            }.AttachTo(
                currentvisual
                );


            var imgstand = new Image(
                textures.greentank()
                )
            {
            }.AttachTo(
                currentvisual
                );

            var guntower = new Image(
                textures.greentank_guntower()
                )
            {
            }.AttachTo(
                currentvisual
                );



            {
                var cm = new Matrix();

                cm.translate(-64, -64);
                cm.scale(0.55, 0.75);

                tanktrackpattern0.transformationMatrix = cm;
                tanktrackpattern1.transformationMatrix = cm;
            }

            // rpeate not suppported!
            // http://forum.starling-framework.org/topic/problem-with-repeat-and-textureatlas



            {
                var cm = new Matrix();

                cm.translate(-64, -64);

                imgstand.transformationMatrix = cm;
            }

            {
                var cm = new Matrix();

                cm.translate(-64, -64);

                guntower.transformationMatrix = cm;
            }

            //{
            //    var cm = new Matrix();

            //    cm.translate(-64, -64);

            //    // shadow with tracks!
            //    cm.scale(1.2, 1.0);
            //    //cm.rotate(rot);
            //    //cm.translate(i * 128, yi * 128);

            //    cm.translate(8, 8);

            //    currentshadow.transformationMatrix = cm;
            //}

            //{
            //    var cm = new Matrix();

            //    //cm.rotate(rot);
            //    //cm.translate(i * 128, yi * 128);


            //    currentvisual.transformationMatrix = cm;
            //}

            #endregion
        }