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;
}
}
}
You need to redraw the background every frame in your draw function as well :)