简体   繁体   English

图像在处理中旋转时消失

[英]Image disappear on rotation in Processing

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.direction为0,或者alternate为true, direction为2时,显示图像。 Otherwise, no image is displayed.否则,不显示图像。 I'm not sure if it matters or not, but snake is a.png image with an alpha transparency.我不确定它是否重要,但蛇是具有 alpha 透明度的.png 图像。 The declaration for snake is snake = loadImage("SnakeLink.png");蛇的声明是snake = loadImage("SnakeLink.png"); . .

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.您必须平移到图像的中心,旋转,平移回它的原点,然后显示它。

translate(image.width/2, image.height/2);
rotate(radians);
translate(-image.width/2, -image.height/2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM