Sprite exchange

Asked

Viewed 35 times

0

Hello, I’m trying to animate the Sprite when it receives damage (changing to a white Sprite), but I’m not getting it, according to the eclipse itself says the error is in ''{'' but in my view they are all correct, and I can not find error in my code.

if(!isDamaged) {
        else if(dir==left_dir){
            g.drawImage(leftPlayer[index], this.getX()-Camera.x,this.getY()-Camera.y,null);
        }   else {
                g.drawImage(playerDamageLeft, this.getX() -Camera.x,this.getY()- Camera.y,null);
        }
        }
        if(!isDamaged) {
            if(dir==up_dir) {
            g.drawImage(upPlayer[index], this.getX()-Camera.x,this.getY()-Camera.y,null);
        }   else {
                g.drawImage(playerDamageUp, this.getX() -Camera.x,this.getY()- Camera.y,null);
            }
        }

        if(!isDamaged) {
            else if(dir==down_dir){
            g.drawImage(downPlayer[index], this.getX()-Camera.x,this.getY()-Camera.y,null);
        }   else {
                g.drawImage(playerDamageDown, this.getX()-Camera.x,this.getY()- Camera.y,null);
            }
        }

1 answer

1

Are you having problems with the keys and the disposition of if..else

In this first code snippet:

if(!isDamaged) {
            else if(dir==left_dir){
                g.drawImage(leftPlayer[index], this.getX()-Camera.x,this.getY()-Camera.y,null);
            }   else {
                    g.drawImage(playerDamageLeft, this.getX() -Camera.x,this.getY()- Camera.y,null);
            }
        }

else if is inside the firstif, then there shouldn’t be else, the corrected version would be:

    if(!isDamaged) {
        if(dir==left_dir){
            g.drawImage(leftPlayer[index], this.getX()-Camera.x,this.getY()-Camera.y,null);
        }   else {
            g.drawImage(playerDamageLeft, this.getX() -Camera.x,this.getY()- Camera.y,null);
        }
    }

The same is happening in the last block

Browser other questions tagged

You are not signed in. Login or sign up in order to post.