jQuery .animate()改变游戏角色的面向位置



我正在使用jQuery制作一款游戏,但使用的是我发现的其他人制作的简单示例,并在其基础上进行构建。

下面是我正在使用的示例:http://motyar.blogspot.com/2010/04/angel-dreams-jquery-game.html

我需要改变chase()函数,这样当天使追逐梦想时,我希望能够使用天使面向不同方向的不同图像。所以基本上,如果天使必须爬上去捕捉梦,它就会使用天使面朝上的形象。向下,向左,向右,甚至是倾斜也是一样的。

我想让它看起来像角色(天使)实际上是在追逐梦想,因为无论它走到哪里,它都会面对梦想。

下面是天使追逐梦想时触发的函数:

 function chase(x, y, dream) {
    //angel gets the dream 
    angel.animate({
        top: y,
        left: x 
    }, 1000, function () {
        //explode the dream
        explode(x, y, dream);
        //you lose
        lose();
    });
} 

这个例子没有错。我只需要添加能够旋转角色(天使)的功能,并面向它在追逐梦想时移动的方向。请看我提供的示例链接。我需要修改该示例来执行我上面解释的操作)

我已经尝试了一段时间,但一直没有成功。希望有人能帮忙。

谢谢

我建议有多个天使朝不同方向看的图像,并根据她在屏幕上的方向显示一个合适的图像(你必须确定这个逻辑)。

function chase(x, y, dream) {
    // if angel is going left load the "looking left" image
    //     angel.attr('src', 'angel_left.gif');
    // if angel is going right load the "looking right" image
    //     angel.attr('src', 'angel_right.gif');
    //angel gets the dream 
    angel.animate({
        top: y,
        left: x 
    }, 1000, function () {
        //explode the dream
        explode(x, y, dream);
        //you lose
        lose();
    });
} 

最新更新