How to put a gif with Canvas

前端 未结 6 1339
孤街浪徒
孤街浪徒 2020-12-23 23:43

I\'m creating a game, and in my game, when the HERO stay near the MONSTER, a gif will be showed, to scare the player. But I have no idea how to do this. I tried to put PHP o

6条回答
  •  悲&欢浪女
    2020-12-23 23:48

    I'm also not quite sure what your problem is, but instead of:

    if((xHero >= xMonster-10)||(xHero <= xMonster + 10))
    {
    
    /*gif here*/
    
    }
    

    you probably want:

    if (xHero >= xMonster-10 && xHero <= xMonster + 10)
    {
    
    /*gif here*/
    
    }
    

    || means OR

    && means AND

    In your code using OR makes the condition always true; that's probably not what you want.

提交回复
热议问题