خرید بک لینک

Vote count: 0

Im having a problem with drawing images. Everything works fine when i use c.fillRect() but the drawImage() isnt working for some reason. The image is in the same directory as the file and the variable box is defined outside of the function.

        window.onload = function () {
            var canvas = document.getElementById("map");
            var c = canvas.getContext("2d");

            var s = {
                rows: 10,
                cols: 10,
                width: 60.2,
                height: 60.2
            };


            var box;

            init();

            function init() {
                box = new Image();
//here
                box.src = "box.png";

                drawCanvas();
            }

            function drawCanvas() {
                c.clearRect(0,0,700,700);

                for (var i=0; i<s.rows; i++) {
                    for (var n=0; n<s.cols; n++) {
                        var x = n*s.width;
                        var y = i*s.height;
//here
                        c.drawImage(box,x,y);
                        //c.fillRect(x,y,60,60);

                    }
                }
            }
        }

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 20 ارديبهشت 1395 ساعت: 10:35

صفحه بندی