java - 构造函数 (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;
}
}
}
这里有什么问题?我很抱歉如此含糊,但这确实是旧代码,我对这个场景是全新的。我将尝试回答任何澄清问题。
解决方案
推荐阅读
- c# - 我的车旋转时出现 Unity Logic 错误
- spring-boot - 如何使用本地日期时间
- python - 排除 rglob 返回的路径中任何位置的模式
- javascript - 为什么我的 barbajs 转换在与包裹捆绑时停止工作?
- python - 如何在代数的“if”语句中使用变量?
- azure - 无法在 Azure 中创建 Spot 实例 VM
- encryption - HSM9000 主机命令 (NG/NH) 解密加密的 PIN
- c - 为什么 calloc 仅适用于代码的特定部分?
- html - 无法在另一个溢出 div 内的 div 上滚动
- python - Python中带有数组的大型数据集