Google Chrome Image() function problem

I made an animation in p5 Javascript. This animaiton has a backgroundimage. This Image is displayed perfectly in firefox and all other browsers except Google Chrome.

Can somebody help me?

My JS code:

var canvas;
var backgroundimage;

var type1_Rect = [];
var type1_Rect_amount = screen.width * 0.2;
var type1_Rect_speed = 1;
var type1_Rect_size = 1;

//-----------------------
var type2_Rect = [];
var type2_Rect_amount = screen.width * 0.1;
var type2_Rect_speed = 0.7;
var type2_Rect_size = 2;
var j = 0;
//------------------------

var i = 0;
function windowResized() {
    resizeCanvas(window.innerWidth, window.innerHeight);
}
function setup() {
    backgroundimage = loadImage("wallpaper/wallpaper.png"); //The Backgroundimage

    canvas = createCanvas(window.innerWidth, window.innerHeight);
    canvas.position(0, 0);
    canvas.style('z-index', '-10');

    for (i = 0; i < type1_Rect_amount; i++) {
    type1_Rect[i] = {
        x: random(0, screen.width),
        y: random(0, screen.height),

        display: function() {
            fill(255);
            noStroke();
            rect(this.x, this.y, type1_Rect_size, type1_Rect_size);
        },

        move: function() {
            this.y = this.y - type1_Rect_speed;

            if(type1_Rect[i].y <= 0) {
                type1_Rect[i].y = window.innerHeight;
            }
        }
    }
}
i = 0;

//-------------------------------------
for (j = 0; j < type2_Rect_amount; j++) {
type2_Rect[j] = {
    x: random(0, screen.width),
    y: random(0, screen.height),

    display: function() {
        fill(255);
        noStroke();
        rect(this.x, this.y, type2_Rect_size, type2_Rect_size);
    },

    move: function() {
        this.y = this.y - type2_Rect_speed;

        if(type2_Rect[j].y <= 0) {
            type2_Rect[j].y = window.innerHeight;
        }
    }
}
}
j = 0;
 //---------------------------------------
}

function draw() {

image(backgroundimage, 0, 0);      //Backgroundimage

fill(255);
      //text(screen.width, 50, 50);
      //text(type1_Rect_amount, 50, 70);
      //text(type2_Rect_amount, 50, 90);

while (i < type1_Rect_amount) {
type1_Rect[i].display();
type1_Rect[i].move();

i++;
}
i = 0;

      //----------------------------
while (j < type2_Rect_amount) {
type2_Rect[j].display();
type2_Rect[j].move();

j++;
}
j = 0;
      //----------------------------
}

Answers

Sign In or Register to comment.