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

时间:2011-09-30 13:30:15

标签: javascript jquery

我正在使用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();
    });
} 

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

我一直试图这样做一段时间,但都没有成功。希望有人能提供帮助。

由于

1 个答案:

答案 0 :(得分:1)

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

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();
    });
}