Skip to main content
edited body
Source Link

I'm fairly new to creating a 2D game in java and I'd love some help. I'm trying to create a sort of knock back effect the enemies have on you. So when you are touched by a enemy you will:

  1. lose life

  2. be knocked back a few pixels

I thought about saying something simple such as:

    if ((player.x & player.y) == (enemy.x & enemy.y)){  
        player.x += 8;
        player.xy += 8;
    }

But seeing as this will only push you back with no hope of moving while being pushed, I didn't want to use it. Is there any simple, yet effective way for going about this?

I'm fairly new to creating a 2D game in java and I'd love some help. I'm trying to create a sort of knock back effect the enemies have on you. So when you are touched by a enemy you will:

  1. lose life

  2. be knocked back a few pixels

I thought about saying something simple such as:

    if ((player.x & player.y) == (enemy.x & enemy.y)){  
        player.x += 8;
        player.x += 8;
    }

But seeing as this will only push you back with no hope of moving while being pushed, I didn't want to use it. Is there any simple, yet effective way for going about this?

I'm fairly new to creating a 2D game in java and I'd love some help. I'm trying to create a sort of knock back effect the enemies have on you. So when you are touched by a enemy you will:

  1. lose life

  2. be knocked back a few pixels

I thought about saying something simple such as:

    if ((player.x & player.y) == (enemy.x & enemy.y)){  
        player.x += 8;
        player.y += 8;
    }

But seeing as this will only push you back with no hope of moving while being pushed, I didn't want to use it. Is there any simple, yet effective way for going about this?

Source Link

Creating a knockback effect

I'm fairly new to creating a 2D game in java and I'd love some help. I'm trying to create a sort of knock back effect the enemies have on you. So when you are touched by a enemy you will:

  1. lose life

  2. be knocked back a few pixels

I thought about saying something simple such as:

    if ((player.x & player.y) == (enemy.x & enemy.y)){  
        player.x += 8;
        player.x += 8;
    }

But seeing as this will only push you back with no hope of moving while being pushed, I didn't want to use it. Is there any simple, yet effective way for going about this?