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 › Image transparancy complication
Page Index Toggle Pages: 1
Image transparancy complication (Read 1875 times)
Image transparancy complication
Sep 14th, 2009, 3:35pm
 
Ok so here is the problem, I've got the cat to appear transparent but for some reason the back ground wont go over it so the instances of the cat stack on top of each other and block out the background. I think processing needs some work, but im sure there is a way around this. The other part that bugs me is that it doesn't even do it incorrectly consistently; some times a gray box, white, or even on occasion you can see the desktop or other windows.
everything you need to run the program is here, you may need to look to see what im talking about.

<code>
animal meow;
PImage outside, house, back, cat;

void setup()
{
 size(200, 150);

 outside = loadImage( "outside.png" );
 house = loadImage( "house.png" );
 cat = loadImage( "kitty.png" );
 back = outside;

 meow = new animal(cat, 0);
 
 frameRate(50);
}

void draw()
{
 background(0);
 meow.update();
 meow.draw();
}




class animal
{
 PImage img;
 int imgCol, imgRow, //animation, direction
     currentX, targetX, patience;
     
 animal (PImage img, int x)
 {
   this.img = img;
   currentX = x;
   patience = 1;
 }
 
 void update()
 {
   patience--;
   if ( patience == 0)
   {
     patience = int ( random(80, 110));
     targetX = int ( random(-65, 305));
     imgCol=30;
   }
   walk();
 }
 
 void draw()
 {
   image (back, -currentX, 10);
   copy (cat, imgCol, imgRow, 30, 30, 65, 95, 30, 30);
 }
 
 void walk()
 {
   imgCol = -imgCol + 30;
   
   if ( targetX < currentX )
   {
     currentX--;
     imgRow = 30;
   }
   else if ( targetX > currentX )
   {
     currentX++;
     imgRow = 0;
   }
   else
     imgCol = 60;
   println(imgCol);
 }
}

</code>

http://picasaweb.google.com/lh/photo/0CEWGEDn3q21F8XMIuUUXg?feat=directlink
http://picasaweb.google.com/lh/photo/9BZNYLFYe4Z-kKXHHG1rtA?feat=directlink
http://picasaweb.google.com/lh/photo/tEcHR62zGhW0prc82LcEJA?feat=directlink

I'd much appreciate your help as i will need this knowledge for many projects i plan on doing and am in progress of making
Re: Image transparancy complication
Reply #1 - Sep 14th, 2009, 4:53pm
 
cant find your images. can you correct it
Re: Image transparancy complication
Reply #2 - Sep 15th, 2009, 1:50am
 
Quote:
I think processing needs some work
All suggestions are welcome...

What is your platform? Rendering bugs might be related to your OS, your graphics card or whatever. Processing is working quite fine for most of us.

I haven't fully understood what issue you have, but I see you use copy() to draw the image of the cat. In this function, "No alpha information is used in the process" so you loose transparency around the cat, if any.
Re: Image transparancy complication
Reply #3 - Sep 15th, 2009, 11:15pm
 
yes i realize there is no alpha commands used, the nature of the program implies that the cat PImage is a 90x60 PNG with a transparent background which i created using the latest gimp. this is done so that the image underneath it is seen clearly so as to present a cat walking about a room. but instead a mutation in a aforementioned colored box created by multiple instances of walking cat.

it is apparent the my image storage is having problems

the program has been run on several (4, and 1 XP) up to date vista machines with identical results.
Re: Image transparancy complication
Reply #4 - Sep 15th, 2009, 11:34pm
 
the images should be working now
Re: Image transparancy complication
Reply #5 - Sep 15th, 2009, 11:46pm
 
Hoshasei wrote on Sep 15th, 2009, 11:15pm:
yes i realize there is no alpha commands used, the nature of the program implies that the cat PImage is a 90x60 PNG with a transparent background which i created using the latest gimp.


Right, so to echo PhilLo, copy() isn't going to be very fruitful, since it doesn't copy alpha channels.  What happens when you just use image(img, imgCol, imgRow);
per the example in PImage reference

Image links still appear to be broken.

--Ben
Re: Image transparancy complication
Reply #6 - Sep 16th, 2009, 10:46am
 
Re: Image transparancy complication
Reply #7 - Sep 16th, 2009, 5:10pm
 
do the pictures work now
Re: Image transparancy complication
Reply #8 - Sep 16th, 2009, 7:19pm
 
yes.
Re: Image transparancy complication
Reply #9 - Sep 18th, 2009, 9:59am
 
so now that the pictures work does anyone no how to fix it.
Re: Image transparancy complication
Reply #10 - Sep 18th, 2009, 10:22am
 
You may not be aware that both PhilLo and I answered your question.  image() will place your image with full transparency information.  copy() will copy the portion of the image you want, but ignore the alpha channel.  If you want your sprites to work as intended, I'd suggest splitting them into six .png files and preloading them into a PImage[] cat.  Or if you really need them on one sheet, I'd look into textures.

--Ben
Re: Image transparancy complication
Reply #11 - Sep 18th, 2009, 10:23am
 
Didn't BenHem already offer a possible solution
Re: Image transparancy complication
Reply #12 - Sep 18th, 2009, 1:38pm
 
Ah, you should have said it was about putting several sprites in the same image...
It is a useful and common practice. You can workaround the problem of copy() by using get() on an intermediary image:
Code:
 void draw() // The one of animal class
{
image(back, -currentX, 10);
PImage curCat = cat.get(imgCol, imgRow, 30, 30);
image(curCat, 65, 95, 30, 30);
}
Re: Image transparancy complication
Reply #13 - Sep 19th, 2009, 9:22am
 
wow thanks that works perfectly
Page Index Toggle Pages: 1