Beispiel #1
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            float width = GraphicsDevice.Viewport.Width;
            float height = GraphicsDevice.Viewport.Height;

            Texture2D spritesheet = Content.Load<Texture2D>("Test/spritesheet");

            TextureRegion.CreateFromSheet(out TextureRegion[] right, spritesheet, 34, 34, new Point(0, 0), new Point(1, 0), new Point(2, 0), new Point(3, 0), new Point(4, 0));

            Animation<TextureRegion> loop = new Animation<TextureRegion>(right, 0.2f, Animation<TextureRegion>.PlaybackMode.NormalLoop);
            Animation<TextureRegion> revLopp = new Animation<TextureRegion>(right, 0.2f, Animation<TextureRegion>.PlaybackMode.ReversedLoop);

            Animation<TextureRegion> pingPong = new Animation<TextureRegion>(right, 0.2f, Animation<TextureRegion>.PlaybackMode.PingPongLoop);

            Actor loopActor = stage.CreateActor(0);
            loopActor.AddComponent<Transform2>().LocalPosition = new Vector2(width * 0.25f, height * 0.5f);
            loopActor.AddComponent<AnimatedTextureRegionComponent>().Set(loop);

            Actor revLoopActor = stage.CreateActor(0);
            revLoopActor.AddComponent<Transform2>().LocalPosition = new Vector2(width * 0.5f, height * 0.5f);
            revLoopActor.AddComponent<AnimatedTextureRegionComponent>().Set(revLopp);

            Actor pingPongActor = stage.CreateActor(0);
            pingPongActor.AddComponent<Transform2>().LocalPosition = new Vector2(width * 0.75f, height * 0.5f);
            pingPongActor.AddComponent<AnimatedTextureRegionComponent>().Set(pingPong);

            Texture2D testingLayers = Content.Load<Texture2D>("Test/testingLayers");
            TextureRegion[] layerRegions = TextureRegion.CreateAllFromSheet(testingLayers, 20, 20);
            
            MyraEnvironment.Game = this;

            stage.CreateActor(0).AddComponent<CameraTestComponent>().camera = camera;
        }
Beispiel #2
0
        private void LoadAll()
        {
            TextureRegion[] loadedRegions = TextureRegion.CreateAllFromSheet(content.Load <Texture2D>("Assets/guns"), 32, 15);
            gunRegions = new Fast2DArray <TextureRegion>(3, 6);
            for (int i = 0; i < loadedRegions.Length; i++)
            {
                gunRegions.Set(loadedRegions[i], i % 3, i / 6);
            }

            playerWalk = TextureRegion.CreateAllFromSheet(content.Load <Texture2D>("Assets/catWalk"), 18, 30);
            playerIdle = TextureRegion.CreateAllFromSheet(content.Load <Texture2D>("Assets/catIdle"), 18, 30);
            bulletTex  = new TextureRegion(content.Load <Texture2D>("Assets/bullet"), 0, 0, 10, 10);
        }
Beispiel #3
0
        protected override void LoadContent()
        {
            base.LoadContent();

            float width  = GraphicsDevice.Viewport.Width;
            float height = GraphicsDevice.Viewport.Height;

            Texture2D testingLayers = Content.Load <Texture2D>("Test/testingLayers");

            TextureRegion[] layerRegions = TextureRegion.CreateAllFromSheet(testingLayers, 20, 20);

            for (int i = 0; i < 5; i++)
            {
                Actor      physActor = stage.CreateActor(0);
                Transform2 physTrans = physActor.AddComponent <Transform2>();
                physTrans.WorldPosition = new Vector2(300, height * 0.2f * i);
                physTrans.LocalScale    = new Vector2(1f, 1f);
                physActor.AddComponent <Rigidbody>().velocity = new Vector2(20 * i, 0);
                physActor.AddComponent <DrawTextureRegionComponent>().region = layerRegions[i];
                physActor.GetComponent <Rigidbody>().height   = layerRegions[0].sourceRectangle.Height;
                physActor.GetComponent <Rigidbody>().width    = layerRegions[0].sourceRectangle.Width;
                physActor.GetComponent <Rigidbody>().isSquare = true;
            }

            Actor      triggerBox   = stage.CreateActor(0);
            Transform2 triggerTrans = triggerBox.AddComponent <Transform2>();

            triggerTrans.WorldPosition = new Vector2(300, height * 0.6f);
            triggerBox.AddComponent <DrawTextureRegionComponent>().region = layerRegions[0];
            Rigidbody body = triggerBox.AddComponent <Rigidbody>();

            body.width     = layerRegions[0].sourceRectangle.Width;
            body.height    = layerRegions[0].sourceRectangle.Height;
            body.isTrigger = true;
            body.isStatic  = true;
            triggerBox.AddComponent <TriggerTest>();
        }