Beispiel #1
0
        public Game(HTMLCanvasElement canvas)
        {
            _mainCanvas         = canvas;
            _mainCanvasRenderer = _mainCanvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);

            _shadowCanvas = new Bridge.Html5.HTMLCanvasElement()
            {
                Width  = _mainCanvas.Width,
                Height = _mainCanvas.Height
            };
            _shadowCanvas2D = _shadowCanvas.GetContext(Bridge.Html5.CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);


            Resize();

            _player = new Player();

            _lastDraw = DateTime.Now;

            _world         = new World(_player, "map1.json");
            _world.Loaded += () => {
                Window.SetTimeout(GameTick, 1000 / TickRate);
                Window.RequestAnimationFrame(GameFrame);
                _player.X = 500;
                _player.Y = 500;
            };
        }
Beispiel #2
0
        public override void apply(Bridge.Html5.CanvasRenderingContext2D ctx, GlyphInstance glyph)
        {
            var margin      = (int)glyph.format.size;
            var totalWidth  = glyph.width + blur * 2 + margin;
            var totalHeight = glyph.height + blur * 2 + margin;

            for (var i = 0; i < quality; i++)
            {
                ctx.Save();
                ctx.BeginPath();
                ctx.Rect(glyph.x - blur, glyph.y + blur + margin, totalWidth, -totalHeight - margin);
                ctx.Clip();

                drawShadow(ctx, glyph, totalWidth, 0, -1);
                drawShadow(ctx, glyph, totalWidth, 1, -1);
                drawShadow(ctx, glyph, totalWidth, 1, 0);
                drawShadow(ctx, glyph, totalWidth, 1, 1);
                drawShadow(ctx, glyph, totalWidth, 0, 1);
                drawShadow(ctx, glyph, totalWidth, -1, 1);
                drawShadow(ctx, glyph, totalWidth, -1, 0);
                drawShadow(ctx, glyph, totalWidth, -1, -1);

                ctx.Restore();
            }
        }
Beispiel #3
0
 private void drawGlow(Bridge.Html5.CanvasRenderingContext2D ctx, int offsetX, int offsetY)
 {
     ctx.ShadowColor   = colorString;
     ctx.ShadowBlur    = blur;
     ctx.ShadowOffsetX = offsetX;
     ctx.ShadowOffsetY = offsetY;
 }
Beispiel #4
0
 private void drawShadow(Bridge.Html5.CanvasRenderingContext2D ctx, GlyphInstance glyph, double totalWidth, int offsetX, int offsetY)
 {
     ctx.ShadowColor   = colorString;
     ctx.ShadowBlur    = blur;
     ctx.ShadowOffsetX = (float)(totalWidth) + offsetX;
     ctx.ShadowOffsetY = offsetY;
     ctx.FillText(glyph.text, (int)(glyph.x - totalWidth), (int)glyph.y);
 }
        public CanvasContext(CanvasElement canvas, InputElement input)
            : base(canvas.Width, canvas.Height)
        {
            imageCache = new Dictionary<string, ImageElement>();

            this.input = input;
            input.Type = InputType.Text;
            input.Value = "A";
            input.OnInput = (e) =>
            {
                if(input.Value == "")
                {
                    KeyPressed("Back");
                }
                KeyPressed(input.Value.Substr(Math.Max(0, input.Value.Length - 1), input.Value.Length));
                input.Value = "A";
            };

            context = canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            context.FillStyle = "#000000";
            context.LineWidth = 2;
            context.TextBaseline = CanvasTypes.CanvasTextBaselineAlign.Middle;

            double canvasLeft = context.Canvas.GetBoundingClientRect().Left;
            double canvasRight = context.Canvas.GetBoundingClientRect().Left;

            context.Canvas.AddEventListener(EventType.Click,
                (e) =>
                {
                    Click(e.As<MouseEvent>().ClientX + Document.Body.ScrollLeft - (int)canvasLeft,
                        e.As<MouseEvent>().ClientY + Document.Body.ScrollTop - (int)canvasRight);
                    if (ContentView.Active == true)
                    {
                        input.Focus();
                    }
                });

            Window.OnResize = (e) => ResizeContent();
        }
 public override void apply(Bridge.Html5.CanvasRenderingContext2D context)
 {
     //throw new System.NotImplementedException();
 }
 public override void apply(Bridge.Html5.CanvasRenderingContext2D context, GlyphInstance glyph)
 {
     throw new System.NotImplementedException();
 }
Beispiel #8
0
        private void GetImageData(HTMLCanvasElement canvas)
        {
            int height = canvas.Height;
            int width = canvas.Width;

            if (CanvasRenderingContext == null)
            {
                CanvasRenderingContext = canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            }

            if (Image == null)
            {
                // the data to manipulate
                Image = CanvasRenderingContext.CreateImageData(width, height);
            }
            else
            {
                //var color = new Color() { Red = 0, Green = 0, Blue = 0 };

                //for (int y = 0; y < height; y++)
                //{
                //    for (int x = 0; x < width; x++)
                //    {
                //        Image.SetPixel(x, y, color);
                //    }
                //}
            }
        }
Beispiel #9
0
 /// <summary>
 /// Creates a pattern using the specified image (a CanvasImageSource). It repeats the source in the
 /// directions specified by the repetition argument. This method returns a CanvasPattern.
 /// </summary>
 /// <param name="image"></param>
 /// <param name="repetition"></param>
 /// <returns></returns>
 public virtual CanvasPattern CreatePattern(CanvasRenderingContext2D image, CanvasTypes.CanvasRepetitionTypes repetition)
 {
     return(null);
 }
Beispiel #10
0
 public override void apply(Bridge.Html5.CanvasRenderingContext2D context)
 {
     context["filter"] = "blur(" + (int)as3.Math.max(blurX, blurY) + "px)";
 }
Beispiel #11
0
 public override void apply(Bridge.Html5.CanvasRenderingContext2D context, GlyphInstance glyph)
 {
     apply(context);
 }
Beispiel #12
0
 public override void apply(Bridge.Html5.CanvasRenderingContext2D ctx)
 {
     drawGlow(ctx, 0, -1);
 }