渲染旋转图像
为什么以下代码没有以一定角度渲染图像。 (我希望图像渲染在图像上的锚点上)。我认为它正在围绕屏幕旋转。我该如何解决这个问题?
public void drawWeapon(Graphics2D g) {
int iconSize = main.SOutput.iconSize;
int ePosX =(int) (getPosX() * iconSize
- (int) main.player.getPosX() *iconSize)/iconSize;
int ePosY =(int) (getPosY() * iconSize
- (int) main.player.getPosY() *iconSize)/iconSize;
int PosX = ePosX + (main.SOutput.resX/2)*iconSize
+ main.SOutput.xPaddingSide;
int PosY = ePosY + (main.SOutput.resY/2)*iconSize
- getImageSizeY()*iconSize;
if (inventory[0][main.gui.itemSelected] != null){
g.rotate(facingLeft?scincePressed:-scincePressed);
g.drawImage(inventory[0][main.gui.itemSelected].item.getImage(),
PosX + (facingLeft?0:getImageSizeX() * iconSize/2), PosY +
(getImageSizeY() * iconSize/2), getImageSizeX() * iconSize/2,
getImageSizeY() * iconSize/3, null);
g.rotate(facingLeft?-scincePressed:scincePressed);
}
}
Why is the following code not rendering the image at an angle.
(I want the image to be rendered on an anchored point on the image). I think that it is rotating around the screen. How can I fix this?
public void drawWeapon(Graphics2D g) {
int iconSize = main.SOutput.iconSize;
int ePosX =(int) (getPosX() * iconSize
- (int) main.player.getPosX() *iconSize)/iconSize;
int ePosY =(int) (getPosY() * iconSize
- (int) main.player.getPosY() *iconSize)/iconSize;
int PosX = ePosX + (main.SOutput.resX/2)*iconSize
+ main.SOutput.xPaddingSide;
int PosY = ePosY + (main.SOutput.resY/2)*iconSize
- getImageSizeY()*iconSize;
if (inventory[0][main.gui.itemSelected] != null){
g.rotate(facingLeft?scincePressed:-scincePressed);
g.drawImage(inventory[0][main.gui.itemSelected].item.getImage(),
PosX + (facingLeft?0:getImageSizeX() * iconSize/2), PosY +
(getImageSizeY() * iconSize/2), getImageSizeX() * iconSize/2,
getImageSizeY() * iconSize/3, null);
g.rotate(facingLeft?-scincePressed:scincePressed);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用这种工作方式:
在代码中,这将是:
您也可以尝试
Graphics2D.rotate(theta, originX, originY);
You should use this way of working:
In code, it would be:
You might also try
Graphics2D.rotate(theta, originX, originY);