java awt 长方形,如何在JAVA中旋转AWT矩形?

I am creating a small java 2D game and i want to know if there is any way to rotate AWT rectangle

AffineTransform origXform = g2d.getTransform();

AffineTransform newXform = (AffineTransform) origXform.clone();

newXform.rotate(angle, pivotX, pivotY); // pivotX ,pivotY is the starting

point of the hand image

g2d.setTransform(newXform);

Rectangle arm = new Rectangle(bowX + 5, bowY + 55, 60, 5);

g2d.drawImage(playerBowReadyImg, bowX, bowY, null); //hand image

on the above code i simply draw the hand image which rotates based on the mouse position, i also set the rectangle on the hand but the problem is rectangle is not rotating along with the hand image.

also i am not using rectangle for any drawing purpose but to detect the collision.

however using g2d.draw(arm); draws the rotated rectangle but it not actually rotate the rectangle it just draws the rotated one.

any suggestion is appreciated.

Ok my question is marked as duplicate so i tried the answers i find there but the code i get only rotate my rectangle for the draw purpose only.

2b9nC.png

now to be more specific the arrow in the image can only detect the collision for the blue rectangle (the original position) instead of the red one (rotated rectangle).

again i don't want to actually draw the rectangle but want to detect the collision when the arrow collide with the rectangle.

解决方案

Returns a new Shape object defined by the geometry of the specified Shape after it has been transformed by this transform.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值