游戏图片越界

游戏图片越界:

                 越界是指Tank可以跑到窗口之外的位置,所以我们要限制Tank的活动范围。

        比如移动的时候坐标到达边界,就在移动方法中让坐标的最大值或最小值固定在窗口内。

 

 

1 if (x < 0) {    //越界处理
2             x = 0;
3         } else if (x > Constants.WIDTH - this.width) {
4             x = Constants.WIDTH - this.width;
5         } else if (y < 0) {
6             y = 0;
7         } else if (y > Constants.HEIGHT - this.height) {
8             y = Constants.HEIGHT - this.height;
9         }
View Code

 

 

随笔说:

        越界处理应该在移动方法后面添加,不然还是会跑出一点点距离。

 

posted @ 2017-08-27 04:05  B_Lasting_尊  阅读(124)  评论(0编辑  收藏  举报