java - 如何在游戏中实现图形而不是使用像素点?
问题描述
我的游戏对象 Cat 工作得非常好,但我正在尝试包含更多图形。因此,我想使用的不仅仅是一个类似于猫的点,而是一个图像。
import java.awt.Color;
import java.awt.Graphics;
public class Cat extends GameObject{
private float _acc=1f;
private float _dcc=0.5f;
private KeyInput input;
public Cat(int x , int y , ID id , KeyInput input )
{
super(x,y,id);
this.input=input;
}
@Override
public void tick()
{
y-=velY;
//Vertical movement
if(input.keys[2]) velY -= _acc;
if(input.keys[3]) velY += _acc;
else if(!input.keys[3] && !input.keys[2])
{
velY=2;
}
velY = clamp(velY,3,1);
}
@Override
public void render(Graphics g)
{
//this part draws a dot that resembles a Cat
g.setColor(Color.red);
g.fillRect((int)x,(int)y,40,40);
}
private float clamp(float vel,float max,float min )
{
if(vel>max)return max;
if(vel<min)return min;
return vel;
}
}
解决方案
推荐阅读
- kubernetes - 如何为每个 Openshift 项目实现特定的 /etc/resolv.conf
- ios - iOS - 调度队列:NSOperationQueue 崩溃
- c# - 更改自动生成的 WCF 客户端的 XmlReaderSettings
- python-3.x - 从使用 GIS 库(如 geopandas、folium)的 Python 脚本制作 .exe
- vb.net - 保留我使用 vb.net 在 datagridview 的框中选中的值
- angular - 如何仅在请求时间超过 n 时显示加载栏
- c++ - 为什么我的 boost::filesystem::ofstream 不能与 std::ios_base::out 一起使用?
- apache-flink - 为可查询状态找到合适的任务管理器主机地址
- javascript - Polymer 2.0 纸张输入文件自定义样式
- python - 转移数据并创建新列 - python数据框