开发者

Image disappear on rotation in Processing

开发者 https://www.devze.com 2023-03-18 07:55 出处:网络
I\'m using the Processing language to do a little game, but I\'m having trouble with images and rotation. My s开发者_开发百科prite displays fine if I apply no rotation to it, but it disappears complet

I'm using the Processing language to do a little game, but I'm having trouble with images and rotation. My s开发者_开发百科prite 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");.


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消