P5js/Openprocessing Character moving question?

42 Views Asked by At

I'm trying to get mario to move side to side. The character is moving fine, but everytime the x-position changes the draw function seems to create a new image.

enter image description here [The code results like this ]

function draw(){
image(player,posx,posy,60,60);

if(keyIsPressed){
    if(key=="ArrowRight"){
        player=loadImage("Marioright.png");
        posx+=10;
    }
    if(key=="ArrowLeft"){
        player=loadImage("Marioleft.png");
        posx-=10;
    }
}

}

1

There are 1 best solutions below

1
On

You need to redraw the background every frame in your draw function as well :)