2011-06-11 99 views
2

这是关于JAVA中的动画。在所有图片上使用相同的尺寸时,我获得了成功。但是,如果我将所有图片尺寸保持在相同的尺寸(宽度和高度),我会得到一些错误,当玩家拳打。在玩家的手碰到敌人身体之前,敌人死了JAVA:2D游戏冒险。碰撞检测问题

但是其他与我的情况在空闲,跑步和冲击有不同 维度。面向左边的冲孔动画变得非常奇怪。 他的手应该撞到左边,但他的身体向右移动。这 是因为我画的x & y是一样的。

我该如何解决?需要说明:d

我使用PNG堂妹支持透明

我认为这是可以用2选项修复时一定条件下发生

回答

2

1.修复我的碰撞检测 2.修正描绘位置我的形象试图描绘你的问题,希望这会有所帮助。 我直接从我的头typeing,所以有代码

  1. 威力错误固定coalision decection 我会尝试这个

    Image fist 
    Image enemy 
        //in paint 
    
    g2D.drawImage(fist,x,y,this); 
    
    g2D.drawImage(enemy,x1,y1,this); 
    
    Rectangle2D myFist = new Rectangle2D.Double(x,y,fist.getWidth(this),fist.getHeight(this)); 
    Rectangle2D myEnemy = new Rectangle2D.Double(x1,y1,enemy.getWidth(this),enemy.getHeight(this)); 
    if (myEnemy.contains(myFist){ 
    //action u want to happend 
    } 
    

我觉得这样的事情应该可以解决coalision问题 我认为这是马里奥在赛格的一场比赛

  1. 修复描绘位置

    //arm image can be the same image if u want 
        Image leftArm; 
        Image rightArm; 
        image headLegsAndTorsoLeft; 
        image headLegsAndTorsoRight; 
        //where am i looking in game if true i look to the leftside of user thats playing 
        boolean turnedLeft 
        //in paint 
        if(turnedLeft){ 
        //this lets it look like he is turned to the left with his right arm in the visible behind his left. 
        //draw right arm 
        g2D.drawImage(rightArm,x,y,this); 
        //draw body moved a bit in x coor 
           g2D.drawImage(headLegsAndTorsoLeft,x-3,y,this); 
        // draw left arm a bit more in x coor 
        g2D.drawImage(leftArm,x-6,y,this); 
        }else{ 
        //this lets it look like he is turned to the right with his left arm in the visible behind his right. 
        // draw left arm 
         g2D.drawImage(leftArm,x,y,this); 
        //draw body moved a bit in x coor 
         g2D.drawImage(headLegsAndTorsoRight,x-3,y,this); 
    //draw right arm a bit more in x coor 
         g2D.drawImage(rightArm,x-6,y,this); 
         } 
    

    相同的顺序武器动画,ultimatly我会用不同的方法动画的躯干,leftarm,rightarm 类似的keyPressed LEFTARROW躯干不走动画左,打左左臂键移动手臂,打右臂键移动右臂,那3让我们说左手臂,现在你需要另一个3当你的字符移到右边。

    这就是我将如何尝试做事情。

+1

嗯... thx ... 我想我会选择解决我的煤矿侦察...... – Kenjiro 2011-06-12 03:20:47