第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

當(dāng)所有其他精靈都移動時,為什么 Carpaint 不移動?

當(dāng)所有其他精靈都移動時,為什么 Carpaint 不移動?

蕪湖不蕪 2022-11-02 15:33:14
我有一個用于在動畫中移動精靈的代碼——除了我的一個精靈之外,所有精靈都在移動,我不知道為什么。有人可以解釋嗎?我的精靈類:abstract class SimpleSprite {   // basic x,y movement,keeps a master list of Sprites   public static final ArrayList<SimpleSprite> sprites = new ArrayList<SimpleSprite>();   float x, y, dx, dy; // position and velocity (pixels/TIMER_MSEC)   public SimpleSprite(float x, float y, float dx, float dy) {      // initial position and velocity      this.x = x;      this.y = y;      this.dx = dx;      this.dy = dy;      sprites.add(this);   }   public void update() { // update position and velocity every n milliSec      // default - just move at constant velocity      x += dx; // velocity in x direction      y += dy; // velocity in y direction   }   abstract public void draw(Graphics2D g2d);       // just draw at current position, no updating.}我的精靈不起作用:class Carpaint extends SimpleSprite {    public Carpaint(float x, float y, float dx, float dy) {        super(x, y, dx, dy);    }    @Override    public void draw(Graphics2D g2d){        g2d.setColor(Color.pink);        g2d.fillRect(50, 50, 40, 60);        g2d.setColor(Color.black);        g2d.drawRect(50, 50, 40, 60);        g2d.drawRect(60, 60, 20, 40);        g2d.fillRect(45, 50, 5, 15);        g2d.fillRect(90, 50, 5 , 15);        g2d.fillRect(45, 95, 5, 16);        g2d.fillRect(90, 95, 5, 16);    }}我的主要:public static void main(String[] args) {    // create and display the animation in a JFrame    final JFrame frame = new JFrame("Animation 2 (close window to exit)");    Animation2 animationPanel = new Animation2(600, 500);    frame.add(animationPanel);    frame.pack();    frame.setLocationRelativeTo(null);    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    frame.setVisible(true);    // add some sprites...    new Square(0, 0, 3, 2, 40);    new Ball(500, 0, -3, 3, 20);    new Ball(0, 500, 2, -5, 30);    new Carpaint(100, 100, 20, -6);}我預(yù)計(jì)所有精靈都會移動,但汽車不會移動(參見此處:https ://i.gyazo.com/0219127277d2543735b3a4727e7c7e72.mp4 )
查看完整描述

1 回答

?
慕尼黑8549860

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個贊

答案來自@RealSkeptic - 我沒有參考xand來粉刷汽車y。新代碼:


class Carpaint extends SimpleSprite {

    public Carpaint(float x, float y, float dx, float dy) {

        super(x, y, dx, dy);

    }

    @Override

    public void draw(Graphics2D g2d){

        g2d.setColor(Color.pink);

        g2d.fillRect((int) x, (int) y, 40, 60);

        g2d.setColor(Color.black);

        g2d.drawRect((int) x, (int) y, 40, 60);

        g2d.drawRect((int) x + 10, (int) y + 10, 20, 40);

        g2d.fillRect((int) x-5, (int) y, 5, 15);

        g2d.fillRect((int) x + 40, (int) y, 5 , 15);

        g2d.fillRect((int) x - 5, (int) y + 45, 5, 16);

        g2d.fillRect((int) x + 40, (int) y + 45, 5, 16);

    }

}


查看完整回答
反對 回復(fù) 2022-11-02
  • 1 回答
  • 0 關(guān)注
  • 94 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號