Translate() public method

public Translate ( double x, double y ) : void
x double
y double
return void
        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();
        }
Example #2
0
        private void updatePositionsForPlaying(CanvasRenderingContext2D canvas)
        {
            canvas.Scale(RealScale.X, RealScale.Y);
            if (SonicToon.Ticking)
            {
                while (true)
                {
                    if (SonicToon.Ticking)
                        break;
                }
            }
            canvas.Translate(ScreenOffset.X, ScreenOffset.Y);
            //canvas.FillStyle = "#000000";
            //canvas.FillRect(0, 0, WindowLocation.Width * Scale.X, WindowLocation.Height * Scale.Y);

            WindowLocation.X = (int)(SonicToon.X) - WindowLocation.Width / 2;
            WindowLocation.Y = (int)(SonicToon.Y) - WindowLocation.Height / 2;

            BigWindowLocation.X = (int)(SonicToon.X) - BigWindowLocation.Width / 2;
            BigWindowLocation.Y = (int)(SonicToon.Y) - BigWindowLocation.Height / 2;

            BigWindowLocation.X = (int)(BigWindowLocation.X - WindowLocation.Width * 0.2);
            BigWindowLocation.Y = (int)(BigWindowLocation.Y - WindowLocation.Height * 0.2);

            BigWindowLocation.Width = (int)(WindowLocation.Width * 1.8);
            BigWindowLocation.Height = (int)(WindowLocation.Height * 1.8);


        }
        /* 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();
        }
Example #4
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);
                }
            }
        }