简体   繁体   English

为什么我不能删除和绘制相同的java对象?

[英]Why can't I remove and draw the same java object?

I try to do homework, and I write breakout game. 我尝试做作业,然后写下突破游戏。 Now,I write the basic function of this game finish.but I want to increase Bonus When ball crash the bonusbricks,I write method to check them and get the color form object that ball crash. 现在,我写了这个游戏结束的基本功能。但是我想增加奖金当球撞击奖励砖时,我写方法检查它们并获得球撞击的颜色形式对象。

} else if(color == Color.BLACK){ 
        double xBonus = ball.getX() +20;
        double yBonus = ball.getY() +20;
        remove(ball);
        ball = new GOval(xBonus, yBonus, BALL_RADIUS+20, BALL_RADIUS+20);
        ball.setFilled(true);
        ball.setFillColor(Color.RED);
        add(ball);

GObject collider = getCollidingObject(); I use collider to detect the object that ball crash but when the ball crash the bonus brick. 我使用对撞机来检测球撞击的物体,但是当球撞到奖励砖时。 The ball has increase size but collider is detect new ball object to be the bricks and bounce ball though game edge. 球的大小增加但是对手通过游戏边缘检测到新的球对象是砖和反弹球。 Please help me .. Sorry,for my wrong grammatically. 请帮帮我..抱歉,我的语法错误。

I believe you want to use * 20 on your ball.getX and ball.getY assignments. 我相信你想在你的ball.getX和ball.getY作业上使用* 20。

It sounds like the new ball object is not in the same instance as the original game panel. 听起来新球对象与原始游戏面板不在同一个实例中。 You should make sure you are accepting the new ball object in the same instance on the panel that the game is played. 您应确保在播放游戏的面板上的同一实例中接受新的球对象。

If you show some more of your code I may be able to be more specific. 如果您显示更多代码,我可能会更具体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM