转向点脚本不起作用

发布于 2024-11-24 02:29:34 字数 636 浏览 3 评论 0原文

我已经想出了一个非常基本的脚本来实现这一点,但它似乎不起作用。我的脚本中的注释代码正在工作,但我的新功能不起作用。有人可以告诉我为什么这个脚本不起作用吗?

public int _x = 0;
public int _y = 0;
Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.icon);

public void move_to(int fx, int fy, int tx, int ty){
    if(fx<tx){
        fx+=1;
    }else
    if(fx>fy){
        fx-=1;
    }
    if(fy<ty){
        fy+=1;
    }else
    if(fy>fy){
        fy-=1;
    }
}

@Override
public void onDraw(Canvas canvas) {
    canvas.drawColor(Color.BLACK);
    canvas.drawBitmap(_scratch, _x, _y, null);
    //_y+=1;
   // _x+=1;
    move_to(_x, _y, 50, 100);
}

I've come up with an extremely basic script to move towards a point but it does not seem to be working. the commented code that's in my script was working, but my new function is not working. Could somebody please tell me why this script is not working.

public int _x = 0;
public int _y = 0;
Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.icon);

public void move_to(int fx, int fy, int tx, int ty){
    if(fx<tx){
        fx+=1;
    }else
    if(fx>fy){
        fx-=1;
    }
    if(fy<ty){
        fy+=1;
    }else
    if(fy>fy){
        fy-=1;
    }
}

@Override
public void onDraw(Canvas canvas) {
    canvas.drawColor(Color.BLACK);
    canvas.drawBitmap(_scratch, _x, _y, null);
    //_y+=1;
   // _x+=1;
    move_to(_x, _y, 50, 100);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

朱染 2024-12-01 02:29:34

我想你想要这个:

public void move_to(int fx, int fy, int tx, int ty){
    if(fx<tx){
        fx+=1;
    }else
    if(fx>tx){
        fx-=1;
    }
    if(fy<ty){
        fy+=1;
    }else
    if(fy>ty){
        fy-=1;
    }
}

I think you want this:

public void move_to(int fx, int fy, int tx, int ty){
    if(fx<tx){
        fx+=1;
    }else
    if(fx>tx){
        fx-=1;
    }
    if(fy<ty){
        fy+=1;
    }else
    if(fy>ty){
        fy-=1;
    }
}
池予 2024-12-01 02:29:34

在 move_to 中更改 fx 和 fy。也许您想更改 _x 和 _y。

In move_to you change fx and fy. Maybe you want to change _x and _y instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文