FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   using String for image names
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: using String for image names  (Read 355 times)
Schlitz

schlitzntl
using String for image names
« on: Aug 4th, 2004, 11:54pm »

I apologize if this question seems somewhat remedial, however I did attempt due diligence in searching for an answer and have found nought.
 
Anyways the problem is that I want to use a String to tell image(name, x, y) what the name is.
 
Ex.
 
String name;
BImage anImage;
 
void setup()
{
name="anImage";
anImage = loadImage("theImage.gif");
}
 
void loop()
{
size(200, 200);
background(0, 0, 0);
image(name, 0, 0);
}
 
//end example
 
however I just can't seem to make it work
it gives me an error like this...
 
No applicable overload for the method named "image" was found in type "BApplet"...etc.
 
 

-Chad Schmidt
arielm

WWW
Re: using String for image names
« Reply #1 on: Aug 5th, 2004, 12:17am »

it's a simple misconception with the "image()" method.
 
the "signature" of this method is as follows:
 
image(BImage img, int x, int y)
 
in english, it means that the first parameter must be of type BImage (and not of type String as you thought...)
 
so based on the piece of code you provided, the solution is to use:
 
image(anImage, 0, 0);
 
inside your loop()
 

Ariel Malka | www.chronotext.org
Schlitz

schlitzntl
Re: using String for image names
« Reply #2 on: Aug 6th, 2004, 7:26pm »

Thanks, but I was wondering if it is at all posible to have the string act as the variable name for the purpose of using the image function so that I could for example when using a multitude of images set which image to display next in a String variable and then use that to call the image function...if that at all makes any sense...where's my coffee...
 
like I got the whole image(BImage, int, int) but can I like switch over a String like image((BImage(String), int, int) or something?
 

-Chad Schmidt
narain


Re: using String for image names
« Reply #3 on: Aug 7th, 2004, 6:36am »

Ah. A lot of people seem to be asking this question these days.
 
Quote:
so that I could for example when using a multitude of images set which image to display next in a String variable and then use that to call the image function

 
You can set which image to display next in a BImage variable, instead.
Code:
BImage nextImage = my42ndImage;
image(nextImage, 0,0);

 
To clear up any potential confusion, the new BImage variable isn't a copy of the original image. It's just, um, another name by which you can refer to the same image. So you can change the original image, draw nextImage, and it'll all work right.  
 
I bring this up because if you assigned int newInt = someInt;, newInt would be a copy. That's because ints (and floats and colors) are basic data types, while BImages are objects. It's just the way the Java language works.
« Last Edit: Aug 7th, 2004, 6:37am by narain »  
Pages: 1 

« Previous topic | Next topic »