2

这是关于JAVA中的动画。在所有图片上使用相同尺寸时我取得了成功。但是,如果我将所有图片尺寸保持在相同的尺寸(宽度和高度)上,我会在玩家打孔时遇到一些错误。在玩家的手接触敌人身体之前,敌人已经死亡

但是在我的情况下,空闲、运行和打孔的其他人则具有不同的维度。面向左侧的打孔动画变得非常奇怪。如果他的手向左打,但他的身体向右移动。这是因为我画的x&y是一样的。

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

我使用 png 因为支持透明

我认为这可以通过 2 个选项来解决 1. 修复我的碰撞检测 2. 在某些情况发生时修复我的图像的绘制位置

4

1 回答 1

2

试图描绘你的问题,希望这会有所帮助。我是直接从脑海中输入的,所以代码中可能有错误

  1. 修复联盟欺骗我会试试这个

     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
    }
    

我认为这样的事情应该可以解决联盟问题我认为这是马里奥在世嘉上的游戏

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

    手臂动画的相同顺序,最终我会为躯干,左臂,右臂使用不同的方法动画,例如按键左箭头躯干向左行走动画,按左臂键移动左臂,按右臂键移动右臂,这就是 3 让说左臂,现在你需要另外 3 个用于当你的 char 向右移动时。

    这就是我会尝试做的事情。

于 2011-06-11T19:22:13.837 回答