Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="colorOffset"></param>
        public void DrawSprite(int id, int x, int y, int colorOffset = 0)
        {
            // This only works when the canvas has a reference to the gameChip
            if (gameChip == null)
            {
                return;
            }

            var pixelData = gameChip.Sprite(id);

            if (colorOffset > 0)
            {
                var total = pixelData.Length;

                for (int i = 0; i < total; i++)
                {
                    pixelData[i] = pixelData[i] + colorOffset;
                }
            }

            // Canvas is reversed, so flip the pixel data
            SpriteChipUtil.FlipSpriteData(ref pixelData, spriteSize.x, spriteSize.y);

            SetPixels(x, y, spriteSize.x, spriteSize.y, pixelData);
        }
        // TODO this should be a step in the exporter
        public void ConfigurePixelData()
        {
            var spriteChip = engine.spriteChip;

            var totalSprite = spriteChip.totalSprites - 1;

            var width   = spriteChip.textureWidth;
            var height  = spriteChip.textureHeight;
            var sWidth  = spriteChip.width;
            var sHeight = spriteChip.height;

            var emptyCount = 0;
            var tmpData    = new int[sWidth * sHeight];
            var cols       = (int)Math.Floor((float)width / sWidth);

            for (int i = totalSprite; i > -1; i--)
            {
                spriteChip.ReadSpriteAt(i, tmpData);

                if (spriteChip.IsEmpty(tmpData))
                {
                    emptyCount++;
                }

                if (i % cols == 0)
                {
                    if (emptyCount == cols)
                    {
                        height -= sHeight;
                    }

                    emptyCount = 0;
                }
            }

            var pixelData = new int[width * height];

            spriteChip.texture.CopyPixels(ref pixelData, 0, 0, width, height);

            SpriteChipUtil.FlipSpriteData(ref pixelData, width, height, false, true);

            var colorMapChip = engine.chipManager.GetChip(ColorMapParser.chipName, false) as ColorChip;

            var colors = colorMapChip == null ? engine.colorChip.colors : colorMapChip.colors;

            exporter = new PixelDataExporter(fullFileName, pixelData, width, height, colors, textureFactory);
        }
Exemple #3
0
        /// <summary>
        ///     Creates a new draw by copying the supplied pixel data over
        ///     to the Display's TextureData.
        /// </summary>
        /// <param name="pixelData"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="flipH"></param>
        /// <param name="flipV"></param>
        /// <param name="flipY"></param>
        /// <param name="layerOrder"></param>
        /// <param name="masked"></param>
        /// <param name="colorOffset"></param>
        public void NewDrawCall(int[] pixelData, int x, int y, int width, int height, bool flipH, bool flipV, bool flipY, int layerOrder = 0, bool masked = false, int colorOffset = 0)
        {
            var drawCalls = width / engine.spriteChip.width * (height / engine.spriteChip.height);

            //currentSprites += drawCalls;

            if (currentSprites + drawCalls > maxSpriteCount)
            {
                return;
            }

            currentSprites += drawCalls;

            //TODO need to add in layer merge logic, -1 is behind, 0 is normal, 1 is above

            //layerOrder = layerOrder.Clamp(-1, 1);

            // flip y coordinate space
            if (flipY)
            {
                y = _height - engine.spriteChip.height - y;
            }

            if (pixelData != null)
            {
                if (flipH || flipV)
                {
                    SpriteChipUtil.FlipSpriteData(ref pixelData, width, height, flipH, flipV);
                }

                var draw = NextDrawRequest();
                draw.x           = x;
                draw.y           = y;
                draw.width       = width;
                draw.height      = height;
                draw.pixelData   = pixelData;
                draw.order       = layerOrder;
                draw.colorOffset = colorOffset;
                drawRequests.Add(draw);


                //texturedata.MergePixels(x, y, width, height, pixelData);
            }
        }
 protected override void FlipPixels()
 {
     // TODO maybe the base class should just expect to have the pixel data so this doens't need to override it
     SpriteChipUtil.FlipSpriteData(ref pixelData, width, height, false, true);
     currentStep++;
 }
Exemple #5
0
 protected virtual void FlipPixels()
 {
     pixelData = tmpTextureData.GetPixels();
     SpriteChipUtil.FlipSpriteData(ref pixelData, width, height, false, true);
     currentStep++;
 }