Exemplo n.º 1
0
        private void LoadRegions(TextureAtlasData data, Dictionary <TextureAtlasData.Page, TextureContext> pageToTexture)
        {
            foreach (var region in data.Regions)
            {
                int width  = region.Width;
                int height = region.Height;

                AtlasRegion atlasRegion = new AtlasRegion(pageToTexture[region.Page], region.Left, region.Top,
                                                          region.Rotate ? height : width, region.Rotate ? width : height)
                {
                    Index          = region.Index,
                    Name           = region.Name,
                    OffsetX        = region.OffsetX,
                    OffsetY        = region.OffsetY,
                    OriginalWidth  = region.OriginalWidth,
                    OriginalHeight = region.OriginalHeight,
                    Rotate         = region.Rotate,
                    Splits         = region.Splits,
                    Pads           = region.Pads,
                };

                if (region.Flip)
                {
                    atlasRegion.Flip(false, true);
                }

                Regions.Add(atlasRegion);
            }
        }
Exemplo n.º 2
0
        public TextureAtlas(GraphicsDevice graphicsDevice, TextureAtlasData data)
        {
            Textures = new HashSet<TextureContext>();
            Regions = new List<AtlasRegion>();

            if (data != null)
                Load(graphicsDevice, data);
        }
Exemplo n.º 3
0
 protected override TextureAtlasData _BuildTextureAtlasData(TextureAtlasData textureAtlasData,
                                                            object textureAtlas)
 {
     if (textureAtlasData == null)
     {
         return(BaseObject.BorrowObject <GodotTextureAtlasData>());
     }
     return(null);
 }
Exemplo n.º 4
0
 internal TextureAtlas(TextureAtlasData data)
 {
     ImagePath = data.ImagePath;
     _textures = new Dictionary <string, Rectangle>();
     foreach (var sub in data.SubTextures)
     {
         _textures.Add(sub.Name, new Rectangle(sub.X, sub.Y, sub.Width, sub.Height));
     }
 }
Exemplo n.º 5
0
        public TextureAtlas(ContentManager contentManager, TextureAtlasData data)
        {
            Textures = new HashSet <TextureContext>();
            Regions  = new List <AtlasRegion>();

            if (data != null)
            {
                Load(contentManager, data);
            }
        }
Exemplo n.º 6
0
        public TextureAtlas(GraphicsDevice graphicsDevice, TextureAtlasData data)
        {
            Textures = new HashSet <TextureContext>();
            Regions  = new List <AtlasRegion>();

            if (data != null)
            {
                Load(graphicsDevice, data);
            }
        }
Exemplo n.º 7
0
        public static TextureAtlas LoadAtlas(TextureAtlasData data)
        {
            var pixmap = new Pixmap(data.Data, data.Width, data.Height);



            var texture = new Texture2D(pixmap, false, false);

            var atlas = TextureAtlas.FromAtlas(texture, data.Atlas);

            atlas.Id = data.Id;

            return(atlas);
        }
Exemplo n.º 8
0
        private void Load(GraphicsDevice graphicsDevice, TextureAtlasData data)
        {
            Dictionary <TextureAtlasData.Page, TextureContext> pageToTexture = new Dictionary <TextureAtlasData.Page, TextureContext>();

            foreach (var page in data.Pages)
            {
                TextureContext texture = page.Texture ?? new TextureContext(graphicsDevice, page.TextureFile, true);

                texture.Filter = page.Filter;
                texture.WrapU  = page.UWrap;
                texture.WrapV  = page.VWrap;

                Textures.Add(texture);
                pageToTexture[page] = texture;
            }

            LoadRegions(data, pageToTexture);
        }
Exemplo n.º 9
0
        private void Load(ContentManager contentManager, TextureAtlasData data)
        {
            Dictionary <TextureAtlasData.Page, TextureContext> pageToTexture = new Dictionary <TextureAtlasData.Page, TextureContext>();

            foreach (var page in data.Pages)
            {
                TextureContext texture = page.Texture ?? new TextureContext(contentManager, page.TextureFile, false);

                texture.Filter = page.Filter;
                texture.WrapU  = page.UWrap;
                texture.WrapV  = page.VWrap;

                Textures.Add(texture);
                pageToTexture[page] = texture;
            }

            LoadRegions(data, pageToTexture);
        }
Exemplo n.º 10
0
        protected override void LoadContent()
        {
            _viewportAdapter = new ScalingViewportAdapter(_graphics.GraphicsDevice, 1600, 900);

            _camera      = new OrthographicCamera(_viewportAdapter);
            _spriteBatch = new SpriteBatch(_graphics.GraphicsDevice);

            if (File.Exists(@"Content\allSprites_default.xml"))
            {
                _atlas             = TextureAtlasData.CreateFromFile(Content, @"Content\allSprites_default.xml");
                _projectileFactory = new ProjectileFactory(_entityManager, _atlas);
            }


            var map = Content.Load <TiledMap>("map01");

            _mapRenderer = new TiledMapRenderer(_graphics.GraphicsDevice);
            LoadMap(map);
            _player = _entityManager.AddEntity(
                new Player(_atlas.GetRegion("tankBody_red"), _atlas.GetRegion("tankRed_barrel1"), _projectileFactory)
                );
            _movementController = new MovementController(_player, _camera);
        }
Exemplo n.º 11
0
        public TextureAtlas(ContentManager contentManager, TextureAtlasData data)
        {
            Textures = new HashSet<TextureContext>();
            Regions = new List<AtlasRegion>();

            if (data != null)
                Load(contentManager, data);
        }
Exemplo n.º 12
0
        private void LoadRegions(TextureAtlasData data, Dictionary<TextureAtlasData.Page, TextureContext> pageToTexture)
        {
            foreach (var region in data.Regions) {
                int width = region.Width;
                int height = region.Height;

                AtlasRegion atlasRegion = new AtlasRegion(pageToTexture[region.Page], region.Left, region.Top,
                    region.Rotate ? height : width, region.Rotate ? width : height) {
                        Index = region.Index,
                        Name = region.Name,
                        OffsetX = region.OffsetX,
                        OffsetY = region.OffsetY,
                        OriginalWidth = region.OriginalWidth,
                        OriginalHeight = region.OriginalHeight,
                        Rotate = region.Rotate,
                        Splits = region.Splits,
                        Pads = region.Pads,
                    };

                if (region.Flip)
                    atlasRegion.Flip(false, true);

                Regions.Add(atlasRegion);
            }
        }
Exemplo n.º 13
0
        private void Load(GraphicsDevice graphicsDevice, TextureAtlasData data)
        {
            Dictionary<TextureAtlasData.Page, TextureContext> pageToTexture = new Dictionary<TextureAtlasData.Page, TextureContext>();

            foreach (var page in data.Pages) {
                TextureContext texture = page.Texture ?? new TextureContext(graphicsDevice, page.TextureFile, true);

                texture.Filter = page.Filter;
                texture.WrapU = page.UWrap;
                texture.WrapV = page.VWrap;

                Textures.Add(texture);
                pageToTexture[page] = texture;
            }

            LoadRegions(data, pageToTexture);
        }
Exemplo n.º 14
0
        private void Load(ContentManager contentManager, TextureAtlasData data)
        {
            Dictionary<TextureAtlasData.Page, TextureContext> pageToTexture = new Dictionary<TextureAtlasData.Page, TextureContext>();

            foreach (var page in data.Pages) {
                TextureContext texture = page.Texture ?? new TextureContext(contentManager, page.TextureFile, false);

                texture.Filter = page.Filter;
                texture.WrapU = page.UWrap;
                texture.WrapV = page.VWrap;

                Textures.Add(texture);
                pageToTexture[page] = texture;
            }

            LoadRegions(data, pageToTexture);
        }
Exemplo n.º 15
0
        static int IndexComparator(TextureAtlasData.Region region1, TextureAtlasData.Region region2)
        {
            int i1 = region1.Index;
            if (i1 == -1)
                i1 = int.MaxValue;

            int i2 = region2.Index;
            if (i2 == -1)
                i2 = int.MaxValue;

            return i1 - i2;
        }
Exemplo n.º 16
0
 /// <summary>
 /// Parse the json file at the given path and return the resulting TextureAtlas.
 /// Don't forget to load the texture using <see cref="LoadContent"/>.
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static TextureAtlas FromJson(string path)
 {
     return(new TextureAtlas(TextureAtlasData.FromJson(path)));
 }