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:)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.