DrawImage() public méthode

public DrawImage ( TypeOption image, double dx, double dy ) : void
image TypeOption
dx double
dy double
Résultat void
Exemple #1
0
        public void Draw(CanvasRenderingContext2D canvas, Point pos)
        {
            if (Active) {
                Ysp += 0.09375;
                X += (int) Xsp;
                Y += (int) Ysp;

                var wl = SonicManager.Instance.WindowLocation;
                if (X < wl.X || Y < wl.Y || X > wl.X + wl.Width || Y > wl.Y + wl.Height) {
                    TickCount = 0xfffffff;
                    return;
                }
                /*       if (SonicManager.Instance.SonicToon.CheckCollisionLine((this.X) + 8, (this.Y) + 8, 16, 1) != -1)
                {
                this.Ysp *= -0.75;
            }

            if (SonicManager.Instance.SonicToon.CheckCollisionLine((this.X) - 8, (this.Y) + 8, 26, 0) != -1) {
                this.Xsp *= -0.75;
            } */

                if (SonicManager.Instance.DrawTickCount > SonicManager.Instance.SonicToon.sonicLastHitTick + 64 &&
                    IntersectingRectangle.IntersectsRect(SonicManager.Instance.SonicToon.myRec,
                                                         new Rectangle(X - 8, Y - 8, 8 * 2, 2 * 8))) {
                    TickCount = 0xfffffff;
                    SonicManager.Instance.SonicToon.Rings++;
                    return;
                }

                TickCount++;
            }
            if (SonicManager.Instance.CurrentGameState == GameState.Playing)
                AnimationIndex = ( SonicManager.Instance.DrawTickCount % ( ( Active ? 4 : 8 ) * 4 ) ) / ( Active ? 4 : 8 );
            else AnimationIndex = 0;
            List<CanvasInformation> sprites = null;
            if (SonicManager.Instance.SpriteCache.Rings.Truthy())
                sprites = SonicManager.Instance.SpriteCache.Rings;
            else throw new Exception("bad ring animation");
            var sps = sprites[AnimationIndex];

            canvas.DrawImage(sps.Canvas, ( pos.X - 8 ), ( pos.Y - 8 ));
        }
        public void DrawUI(CanvasRenderingContext2D _canvas,
                           Point pos,
                           bool showOutline,
                           bool showCollideMap,
                           bool showHurtMap,
                           bool showOffset,
                           bool xflip,
                           bool yflip)
        {
            var fd = GetCache(showOutline, showCollideMap, showHurtMap);



            _canvas.Save();

            _canvas.Translate(pos.X, pos.Y);
            if (xflip)
            {
                if (yflip)
                {
                    _canvas.Translate(fd.Canvas.Width / 2d, fd.Canvas.Height / 2d);
                    _canvas.Rotate(-90 * Math.PI / 180);
                    _canvas.Translate(-fd.Canvas.Width / 2d, -fd.Canvas.Height / 2d);

                    _canvas.Translate(0, Height);
                    _canvas.Scale(1, -1);
                }
                else
                {
                    _canvas.Translate(fd.Canvas.Width / 2d, fd.Canvas.Height / 2d);
                    _canvas.Rotate(-90 * Math.PI / 180);
                    _canvas.Translate(-fd.Canvas.Width / 2d, -fd.Canvas.Height / 2d);
                }
            }
            else
            {
                if (yflip)
                {
                    _canvas.Translate(0, Height);
                    _canvas.Scale(1, -1);
                }
                else { }
            }
            _canvas.DrawImage(fd.Canvas, 0, 0);
            if (showOffset)
            {
                _canvas.BeginPath();
                _canvas.MoveTo(OffsetX, 0);
                _canvas.LineTo(OffsetX, Height);
                _canvas.LineWidth = 1;
                _canvas.StrokeStyle = "#000000";
                _canvas.Stroke();

                _canvas.BeginPath();
                _canvas.MoveTo(0, OffsetY);
                _canvas.LineTo(Width, OffsetY);
                _canvas.LineWidth = 1;
                _canvas.StrokeStyle = "#000000";
                _canvas.Stroke();
            }

            _canvas.Restore();
        }
        /* this.uploadImage = function (sprite) {
        this.width = sprite.width;
        this.height = sprite.height;
        this.offsetX = _H.floor(sprite.width / 2);
        this.offsetY = _H.floor(sprite.height / 2);

        var ca = _H.defaultCanvas(this.width, this.height);

        ca.context.drawImage(sprite, 0, 0);
        var imgd = ca.context.getImageData(0, 0, this.width, this.height);
        var pix = imgd.data;

        var palette = {};
        var paletteLength = 0;

        for (var x = 0; x < this.width; x++) {
            this.colorMap[x] = [];
            for (var y = 0; y < this.height; y++) {
                var pl = _H.colorFromData(pix, (x * 4) + y * this.width * 4);
                var ind = 0;
                if (palette[pl] != undefined) {
                    ind = palette[pl];
                } else {
                    ind = paletteLength;
                    palette[pl] = paletteLength;
                    paletteLength++;
                }
                this.colorMap[x][y] = ind;
            }
        }
        this.palette = [];
        var ind = 0;
        for (var p in palette) {
            this.palette[ind++] = p.replace("#", "");
        }

    };*/

        public void DrawSimple(CanvasRenderingContext2D mainCanvas, Point pos, int width, int height, bool xflip, bool yflip)
        {
            var c = GetCache(false, false, false);

            mainCanvas.Save();
            mainCanvas.Translate(pos.X, pos.Y);
            mainCanvas.Scale(((double)width / Width), ((double)height / Height));

            mainCanvas.DrawImage(c.Canvas, 0, 0);
            mainCanvas.Restore();
        }
        private void drawHighChunks(CanvasRenderingContext2D canvas, int fxP, int fyP, Point[] offs, Point localPoint)
        {
            foreach (Point off in offs)
            {
                int _xP = fxP + off.X;
                int _yP = fyP + off.Y;
                int _xPreal = fxP + off.X;
                int _yPreal = fyP + off.Y;
                //if (_xP < 0 || _xP >= SonicLevel.LevelWidth) continue;
                _xP = Help.Mod(_xP, SonicLevel.LevelWidth);
                _yP = Help.Mod(_yP, SonicLevel.LevelHeight);
                TileChunk chunk = SonicLevel.GetChunkAt(_xP, _yP);
                if (chunk == null) continue;

                localPoint.X = (_xPreal * 128) - WindowLocation.X;
                localPoint.Y = (_yPreal * 128) - WindowLocation.Y;

                if (!chunk.IsEmpty() && !chunk.OnlyBackground())
                    chunk.Draw(canvas, localPoint, ChunkLayer.High);

                if (ShowHeightMap)
                {
                    var fd = SpriteCache.HeightMapChunks[(SonicLevel.CurHeightMap ? 1 : 2) + " " + chunk.Index];

                    if (fd == null)
                    {
                        fd = cacheHeightMapForChunk(chunk);
                    }
                    canvas.DrawImage(fd.Canvas, localPoint.X, localPoint.Y);
                }
                if (CurrentGameState == GameState.Editing)
                {
                    canvas.StrokeStyle = "#DD0033";
                    canvas.LineWidth = 3;
                    canvas.StrokeRect(localPoint.X, localPoint.Y, 128, 128);
                }
            }
        }
 private void drawCanveses(CanvasRenderingContext2D canvas, Point localPoint)
 {
     canvas.Scale(Scale.X, Scale.Y);
     canvas.DrawImage(lowChunkCanvas.Canvas, localPoint.X, localPoint.Y);
     canvas.DrawImage(sonicCanvas.Canvas, localPoint.X, localPoint.Y);
     canvas.DrawImage(highChuckCanvas.Canvas, localPoint.X, localPoint.Y);
 }
Exemple #6
0
        public void Draw(CanvasRenderingContext2D canvas, Point pos, bool xflip, bool yflip, int solid, int angle)
        {
            if (Items == null) return;
            canvas.Save();

            var oPos = new Point(pos);
            if (xflip) {
                pos.X = -pos.X - 16;
                canvas.Scale(-1, 1);
            }
            if (yflip) {
                pos.Y = -pos.Y - 16;
                canvas.Scale(1, -1);
            }
            var fd = SonicManager.Instance.SpriteCache.HeightMaps[Index + ( solid << 20 )];
            if (Index != -1 && fd.Truthy())
                canvas.DrawImage(fd.Canvas, pos.X, pos.Y);
            else {
                var ntcanvas = CanvasInformation.Create(16, 16, false);
                var ncanvas = ntcanvas.Context;

                if (solid > 0) {
                    for (int x = 0; x < 16; x++) {
                        for (int y = 0; y < 16; y++) {
                            var jx = 0;
                            var jy = 0;
                            if (ItemsGood(Items, x, y)) {
                                jx = x;
                                jy = y;
                                var _x = jx;
                                var _y = jy;
                                ncanvas.LineWidth = 1;
                                ncanvas.FillStyle = colors[solid];
                                ncanvas.FillRect(_x, _y, 1, 1);
                                if (angle != 255) {
                                    ncanvas.BeginPath();
                                    ncanvas.LineWidth = 1;
                                    ncanvas.StrokeStyle = "rgba(163,241,255,0.8)";
                                    ncanvas.MoveTo(16 / 2, 16 / 2);
                                    ncanvas.LineTo(16 / 2 - Help.Sin(angle) * 8, 16 / 2 - Help.Cos(angle) * 8);
                                    ncanvas.Stroke();
                                    /*ncanvas.BeginPath();
                                    ncanvas.FillStyle = "rgba(163,241,255,0.8)";
                                    ncanvas.Arc(16 / 2 - Help.Sin(angle) * 8,16 / 2 - Help.Cos(angle) * 8,5,0,2 * Math.PI,true);
                                    ncanvas.Fill();*/
                                }
/*
                                canvas.LineWidth = 1;
                                canvas.StrokeStyle = "#000000";
                                canvas.StrokeRect(pos.X, pos.Y, scale.X * 16, scale.Y * 16);
*/
                            }
                        }
                    }
                }
                SonicManager.Instance.SpriteCache.HeightMaps[Index + ( solid << 20 )] = ntcanvas;

                canvas.DrawImage(ntcanvas.Canvas, pos.X, pos.Y);
            }
            canvas.Restore();
            pos.X = oPos.X;
            pos.Y = oPos.Y;
        }
        public void Draw(CanvasRenderingContext2D canvas, int x, int y, bool showHeightMap)
        {
            if (Dead || ObjectData.Falsey()) return;

            if (ObjectData.PieceLayouts.Count == 0) {
                canvas.DrawImage(ObjectManager.broken,
                                 ( x - ObjectManager.broken.Width / 2 ),
                                 ( y - ObjectManager.broken.Height / 2 ),
                                 ObjectManager.broken.Width,
                                 ObjectManager.broken.Height);
                return;
            }

            MainPieceLayout().Draw(canvas, x, y, ObjectData, this, showHeightMap);
            if (ConsoleLog != null) {
                var gr = GetRect();
                canvas.Save();
                canvas.FillStyle = "rgba(228,228,12,0.4)";
                var wd = 1;
                canvas.FillRect(gr.X - X + x - ( gr.Width / 2 ) - wd,
                                gr.Y - Y + y - ( gr.Height / 2 ) - wd,
                                gr.Width - ( gr.X - X ) + wd * 2,
                                gr.Height - ( gr.Y - Y ) + wd * 2);
                canvas.Restore();
            }
        }
Exemple #8
0
        public void DrawBase(CanvasRenderingContext2D canvas,
                 Point position,
                 ChunkLayer layer,
                 bool xFlip,
                 bool yFlip)
        {
            var drawOrderIndex = 0;
            drawOrderIndex = xFlip ? (yFlip ? 0 : 1) : (yFlip ? 2 : 3);

            int tilePieceLength = 8;

            var ac = CanvasInformation.Create(tilePieceLength * 2, tilePieceLength * 2, false);
            var i = 0;

            var localPoint = new Point(0, 0);
            foreach (TileInfo tileItem in Tiles.Array())
            {
                var tile = tileItem.GetTile();
                if (tile.Truthy())
                {
                    if (tileItem.Priority == ((int)layer == 1))
                    {
                        var _xf = xFlip ^ tileItem.XFlip;
                        var _yf = yFlip ^ tileItem.YFlip;
                        var df = DrawInfo[DrawOrder[drawOrderIndex][i]];
                        localPoint.X = df[0] * tilePieceLength;
                        localPoint.Y = df[1] * tilePieceLength;
                        tile.DrawBase(ac.Context, localPoint, _xf, _yf, tileItem.Palette);
                    }
                }
                i++;
            }
            canvas.DrawImage(ac.Canvas, position.X, position.Y);
              
        }
Exemple #9
0
        public void DrawAnimatedPalette(CanvasRenderingContext2D canvas, Point position, ChunkLayer layer, bool xFlip, bool yFlip, int animatedPaletteIndex)
        {


            var animatedPaletteCacheIndex = getAnimatedPaletteCacheIndex(xFlip, yFlip, animatedPaletteIndex, SonicManager.Instance.TilePaletteAnimationManager.GetPaletteAnimation(animatedPaletteIndex).CurrentFrame);


            CanvasInformation animatedPaletteCache = animatedPaletteCaches[animatedPaletteCacheIndex];
            if (animatedPaletteCache == null)
            {

                var drawOrderIndex = 0;
                drawOrderIndex = xFlip ? (yFlip ? 0 : 1) : (yFlip ? 2 : 3);

                int tilePieceLength = 8;

                var ac = CanvasInformation.Create(tilePieceLength * 2, tilePieceLength * 2, false);
                var i = 0;

                var localPoint = new Point(0, 0);
                foreach (TileInfo tileItem in Tiles.Array())
                {
                    var tile = tileItem.GetTile();
                    if (tile.Truthy())
                    {
                        if (tileItem.Priority == ((int)layer == 1))
                        {
                            var _xf = xFlip ^ tileItem.XFlip;
                            var _yf = yFlip ^ tileItem.YFlip;
                            var df = DrawInfo[DrawOrder[drawOrderIndex][i]];
                            localPoint.X = df[0] * tilePieceLength;
                            localPoint.Y = df[1] * tilePieceLength;
                            tile.DrawAnimatedPalette(ac.Context, localPoint, _xf, _yf, tileItem.Palette, animatedPaletteIndex);
                        }
                    }
                    i++;
                }
                animatedPaletteCaches[animatedPaletteCacheIndex] = animatedPaletteCache=ac;
            }

            canvas.DrawImage(animatedPaletteCache.Canvas, position.X, position.Y);
        }
Exemple #10
0
        public void DrawBase(CanvasRenderingContext2D canvas, Point pos, bool xflip, bool yflip, int palette, bool isAnimatedTile = false)
        {

            //we dont predraw animated tiles
            if (AnimatedTileIndexes != null && (!isAnimatedTile && AnimatedTileIndexes.Count > 0)) return;

            var baseCacheIndex = getBaseCacheIndex(xflip, yflip, palette);

            CanvasInformation baseCache = baseCaches[baseCacheIndex];

            if (baseCache == null)
            {

                var squareSize = Colors.Length;
                CanvasInformation j;
                j = CanvasInformation.Create(squareSize, squareSize, false);

                if (pos.X < 0 || pos.Y < 0)
                    return;
                var oPos = new Point(0, 0);
                if (xflip)
                {
                    oPos.X = -squareSize;
                    j.Context.Scale(-1, 1);
                }
                if (yflip)
                {
                    oPos.Y = -squareSize;
                    j.Context.Scale(1, -1);
                }
                var palette_ = SonicManager.Instance.SonicLevel.Palette;

                int colorPaletteIndex = (palette + SonicManager.Instance.IndexedPalette) % palette_.Length;
                var x = oPos.X;
                var y = oPos.Y;

                for (int _x = 0; _x < squareSize; _x++)
                {
                    for (int _y = 0; _y < squareSize; _y++)
                    {
                        var colorIndex = Colors[_x][_y];
                        if (colorIndex == 0) continue;

                        j.Context.FillStyle = palette_[colorPaletteIndex][colorIndex];
                        j.Context.FillRect(x + _x, y + _y,1,1);
                    }
                }
                baseCaches[baseCacheIndex] = baseCache = j;
            }


            canvas.DrawImage(baseCache.Canvas, pos.X, pos.Y);


        }
Exemple #11
0
        public void Draw(CanvasRenderingContext2D canvas)
        {
            var fx = ( X );
            var fy = ( Y );

            if (Invulnerable()) return;
            var cur = SonicManager.Instance.SpriteCache.SonicSprites[SpriteState];
            if (cur == null) {}

            if (cur.Loaded()) {
                canvas.Save();
                var offset = GetOffsetFromImage();
                canvas.Translate(( fx - SonicManager.Instance.WindowLocation.X + offset.X ),
                                 ( ( fy - SonicManager.Instance.WindowLocation.Y + offset.Y ) ));
                if (SonicManager.Instance.ShowHeightMap) {
                    canvas.Save();
                    var mul = 6;
                    var xj = Xsp * mul;
                    var yj = Ysp * mul;
                    canvas.BeginPath();
                    canvas.MoveTo(0, 0);
                    canvas.LineTo(xj, yj);
                    canvas.FillStyle = "rgba(163,241,255,0.8)";
                    canvas.Arc(xj, yj, 5, 0, 2 * Math.PI, true);
                    canvas.ClosePath();

                    canvas.LineWidth = 6;
                    canvas.StrokeStyle = "white"; //6C6CFC
                    canvas.Stroke();
                    canvas.LineWidth = 3;
                    canvas.StrokeStyle = "#2448D8"; //6C6CFC
                    canvas.Fill();
                    canvas.Stroke();
                    canvas.Restore();
                }

                if (!Facing) {
                    //canvas.translate(cur.width, 0);
                    canvas.Scale(-1, 1);
                    if (!CurrentlyBall && !SpinDash)
                        canvas.Rotate(-Help.FixAngle(Angle));

                    canvas.DrawImage(cur, -cur.Width / 2, -cur.Height / 2);

                    if (SpinDash) {
                        canvas.DrawImage(
                                SonicManager.Instance.SpriteCache.SonicSprites[
                                        ( "spinsmoke" + ( SonicManager.Instance.DrawTickCount % 14 ) / 2 )],
                                ( -cur.Width / 2 ) - 25,
                                -cur.Height / 2 + ( offset.Y ) - 14,
                                cur.Width,
                                cur.Height);
                    }
                } else {
                    if (!CurrentlyBall && !SpinDash)
                        canvas.Rotate(Help.FixAngle(Angle));
                    canvas.DrawImage(cur, -cur.Width / 2, -cur.Height / 2);

                    if (SpinDash) {
                        canvas.DrawImage(
                                SonicManager.Instance.SpriteCache.SonicSprites[
                                        ( "spinsmoke" + ( SonicManager.Instance.DrawTickCount % 14 ) / 2 )],
                                ( -cur.Width / 2 ) - 25,
                                -cur.Height / 2 + ( offset.Y ) - 14,
                                cur.Width,
                                cur.Height);
                    }
                }

                /*
               canvas.moveTo(-10 * scale.x, 4 * scale.y);
               canvas.lineTo(10 * scale.x, 4 * scale.y);
               canvas.lineWidth = 3;
               canvas.strokeStyle = "#FFF";
               canvas.stroke();

               canvas.moveTo(-9 * scale.x, 0 * scale.y);
               canvas.lineTo(-9 * scale.x, 20 * scale.y);
               canvas.lineWidth = 3;
               canvas.strokeStyle = "#FFF";
               canvas.stroke();

               canvas.moveTo(9 * scale.x, 0 * scale.y);
               canvas.lineTo(9 * scale.x, 20 * scale.y);
               canvas.lineWidth = 3;
               canvas.strokeStyle = "#FFF";
               canvas.stroke();*/

                /*
                canvas.strokeStyle = "#FFF";
                canvas.lineWidth = 4;
                canvas.strokeRect(-cur.width / 2, -cur.height / 2, cur.width, cur.height);
                */
                canvas.Restore();
                if (SonicManager.Instance.ShowHeightMap)
                    SensorManager.Draw(canvas, this);
                for (var i = 0; i < HaltSmoke.Count; i++) {
                    var lo = HaltSmoke[i];
                    canvas.DrawImage(
                            SonicManager.Instance.SpriteCache.SonicSprites[
                                    ( "haltsmoke" + ( SonicManager.Instance.DrawTickCount % ( 4 * 6 ) ) / 6 )],
                            ( ( lo.X - SonicManager.Instance.WindowLocation.X - 25 ) ),
                            ( ( lo.Y + 12 - SonicManager.Instance.WindowLocation.Y + offset.Y ) ));
                    if (( ( SonicManager.Instance.DrawTickCount + 6 ) % ( 4 * 6 ) ) / 6 == 0)
                        HaltSmoke = HaltSmoke.Extract(i, 1);
                }
            }
        }