首页 > 解决方案 > 构造函数 (java.awt.Polygon) 未定义

问题描述

我的代码返回错误:构造函数 VectorSprite(java.awt.Polygon) 未定义

import java.awt.Polygon;


public class Rock extends VectorSprite{
    int size;
    public Rock(){
      super(new Polygon(new int[] {20, 15, 30 ,50, 40, 35}, new int[]{5,  30,  45, 15, 10, 5},6)); //error here

        velocityx = (float)Math.random() * 6 - 3;
        velocityy = (float)Math.random() * 6 - 3;

    }

    public Rock (int size){
        this();
        this.size = size;
    }
    @Override
    public void updatePosition(){
        angle += Math.PI/180;
      super.updatePosition();
    }
    public void rockspawn(float x, float y){
       float randAng;
       randAng = (float)Math.random() * (float)Math.PI * 2;

       posx = x + ((float)Math.cos(randAng)*150);
       posy = y + ((float)Math.sin(randAng)*150);

    }
}

VectorSprite 的构造函数给出了错误。它看起来像这样:

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;

public class VectorSprite {
    float posx;
    float posy;
    Color color;
    Polygon shape;
    float velocityx;
    float velocityy;
    double angle;

int[] xp = {20,50 ,30 };
int[] yp = {15,10 ,30 };

    public VectorSprite(){
    posx = 30;
    posy = 30;
    color = Color.GREEN;
    shape = new Polygon(xp,yp,3);
    velocityx = 0;
    velocityy = 0;
    }
   public void draw(Graphics g) {
       g.drawPolygon(shape);
   }
   public void updatePosition() {
      posx = posx + velocityx  ;  
      for (int i = 0; i < shape.npoints; i++){
        shape.xpoints[i] += velocityx;
        shape.ypoints[i] += velocityy;

      }         
}

}

这里有什么问题?我很抱歉如此含糊,但这确实是旧代码,我对这个场景是全新的。我将尝试回答任何澄清问题。

标签: java

解决方案


推荐阅读