处理中旋转时图像消失
我正在使用 Processing 语言来做一个小游戏,但我在图像和旋转方面遇到了问题。如果我不对其进行旋转,我的精灵会显示良好,但如果旋转它就会完全消失。这是旋转代码:
void display(boolean alternate) {
pushMatrix();
if(!isHead && !isTail && alternate) rotate(radians(180));
rotate(radians(90*direction));
image(snake, x, y, linkSize, linkSize);
popMatrix();
}
当direction
为0,或alternate
为true且direction
为2时,则显示图像。否则,不显示图像。我不确定这是否重要,但蛇是一个具有 alpha 透明度的 .png 图像。 Snake 的声明为 snake = loadImage("SnakeLink.png");
。
I'm using the Processing language to do a little game, but I'm having trouble with images and rotation. My sprite displays fine if I apply no rotation to it, but it disappears completely if it is rotated. Here's the rotation code:
void display(boolean alternate) {
pushMatrix();
if(!isHead && !isTail && alternate) rotate(radians(180));
rotate(radians(90*direction));
image(snake, x, y, linkSize, linkSize);
popMatrix();
}
When direction
is 0, or alternate
is true and direction
is 2, then the image displays. Otherwise, no image is displayed. I'm not sure if it matters or not, but snake is a .png image with an alpha transparency. The declaration for snake is snake = loadImage("SnakeLink.png");
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您实际上是从原点(左上角)旋转图像,因此它从屏幕上消失。
您必须平移到图像的中心,旋转,平移回其原点,然后显示它。
You are actually rotating the image from it's origin (top left corner), so it disappears from the screen.
You have to translate to the center of the image, rotate, translate back to it's origin and then display it.