We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › rotating an image
Page Index Toggle Pages: 1
rotating an image (Read 934 times)
rotating an image
Mar 11th, 2009, 1:54am
 
Hey all,
I'm trying to write a sprite sheet class and I have this bit of code:
PGraphics buffer = createGraphics(50, 50, P2D);
   
   buffer.imageMode(CORNER);
   for(int a=0; a<360/5; a++) {
     buffer.pushMatrix();
     rotate(radians(a*5));
     buffer.image(origGraphic, 0, 0);
     graphicSheet.set(50*(a), 0, buffer.get());
     buffer.popMatrix();
   }

but when I render the graphicSheet everything is as expected except none of the images are rotated. I think it may have something to do with using a separate PGraphics object but I'm not sure. Thanks.
Re: rotating an image
Reply #1 - Mar 11th, 2009, 2:27am
 
I'm new to this syntax,but I suppose you have missed to increment the rotation angle in your code?If you don't mind please publish your code and I will try to help.
Re: rotating an image
Reply #2 - Mar 11th, 2009, 2:42am
 
well, I'm incrementing the rotation in the for loop by using (a*5). but here's the rest of my sprite sheet class.

class SpriteSheet {
 //properties
 PImage graphicSheet;
 PImage origGraphic;
 
 SpriteSheet(String filePath) {
   origGraphic = loadImage(filePath);

   graphicSheet = createImage(800, 200, ARGB);
   PGraphics buffer = createGraphics(50, 50, P2D);
   
   buffer.imageMode(CORNER);
   for(int a=0; a<360/5; a++) {
        buffer.pushMatrix();
        rotate(radians(a*5));
        buffer.image(origGraphic, 0, 0);
        graphicSheet.set(50*(a), 0, buffer.get());
        buffer.popMatrix();
   }
 }
 
 PImage getGraphic() {
   return graphicSheet;
 }
}
Re: rotating an image
Reply #3 - Mar 11th, 2009, 4:21am
 
I did not check the code but i see two possibles flaws:
shoudn't you say: buffer.rotate() ?
also shoudn't you use: buffer.beginDraw(); and buffer.endDraw(); ?

i haven't used PGraphics that much... not sure.
Re: rotating an image
Reply #4 - Mar 11th, 2009, 9:28pm
 
doesn't work how i want it to yet, but I think the beginDraw and endDraw have helped move it forward. Also the buffer.rotate. I'd tried it before without the begin and end draws and it gave a weird error, but now it's doing something. Thanks for the help.
Re: rotating an image
Reply #5 - Mar 12th, 2009, 8:22pm
 
So, different problem, but same code, so I thought I'd just post it here.

new code:
class SpriteSheet {
 //properties
 PImage graphicSheet;
 PImage origGraphic;
 
 SpriteSheet(String filePath) {
   origGraphic = loadImage(filePath);
   graphicSheet = createImage(800, 50, ARGB);
   PGraphics buffer;
   
   for(int a=0; a<360/5; a++) {
          buffer = createGraphics(50, 50, P3D);
          buffer.beginDraw();
          buffer.background(0, 0);
          buffer.imageMode(CENTER);
          buffer.translate(25, 25);
          buffer.rotate(radians(a*5));
          buffer.image(origGraphic, 0, 0);
          graphicSheet.set(50*(a), 0, buffer.get());
          buffer.endDraw();
   }
 }
 
 PImage getGraphic() {
   return graphicSheet;
 }
}

the image I am using is png with transparency, but when I run this code and display my sprite sheet there is no transparency, even though I have set the background to be transparent (or so I think). Thanks.
Re: rotating an image
Reply #6 - Mar 12th, 2009, 10:53pm
 
Funny, that's the third time I write this today: a PGraphics background is naturally transparent. Don't use background() on it, even with a fully transparent color.
Re: rotating an image
Reply #7 - Mar 13th, 2009, 12:32am
 
Yea, I tried that too and I get the same result.
Re: rotating an image
Reply #8 - Mar 13th, 2009, 11:10am
 
Re: rotating an image
Reply #9 - Mar 14th, 2009, 1:47am
 
Works beautiful now. Thank you very much.
Page Index Toggle Pages: 1