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 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); }
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); }
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) { 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); } } }