We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Guys! I have big problem! I'm trying to use a cycle to paint images in my window, but it doesn't work (it doesn't even compile). Can you help me? Here's the code:
Boton []buttons;
int activeButtons=-1;
Table pokeTable;
PImage [] image = new PImage[17];
PFont font;
void drawButtons()
{
for(int i=0; i<buttons.length;i++)
{
if(i==activeButtons)
buttons[i].current=buttons[i].botSel;
else
buttons[i].current=buttons[i].botColor;
buttons[i].dibujaBoton();
}
}
void setup()
{
size(800,750);
background(255);
font=createFont("Haettenschweiler-48.vlw",48);
buttons = new Boton[3];
buttons[0] = new Boton(width/2,700,color(240,128,7), color(200,32,60)); //charmander
buttons[1] = new Boton(width/3,700,color(123,221,240), color(13,78,190)); //squirtle
buttons[2] = new Boton(2*width/3,700,color(135,234,36), color(11,200,23)); //bulbasaur
pokeTable = new Table("tablaPoke.txt");
for (int i=0; i<image.length; i++)
{
image[i] = loadImage("poke"+i+".png");
}
}
void draw()
{
background(255);
drawButtons();
textFont(font,48);
fill(150);
textAlign(CENTER,TOP);
text("¿Qué pokemon inicial escojo?",width/2,height/16);
if(activeButtons!=-1)
{
switch(activeButtons)
{
case 0:
for(int i=6;i<=11;i++)
{
int x = 100;
image("poke"+i+".png",x + 50, 300);
x++;
}
break;
case 1:
for(int i=12;i<=17;i++)
{
int x = 100;
image("poke"+i+".png",x + 50, 300);
x++;
}
break;
case 2:
for(int i=0;i<=6;i++)
{
int x = 100;
image("poke"+i+".png",x + 50, 300);
x++;
}
break;
}
}
}
void mouseClicked()
{
int x = mouseX;
int y = mouseY; //coordenadas
for (int i=0; i<buttons.length; i++)
if (buttons[i].isClicked(x,y))
activeButtons = i;
}
void keyPressed()
{
}
Answers
how doesn't it work? what is the error? where?
we can't compile the above without Boton and Table classes. an idea of the contents of the txt file would help. ditto images.
but this is obviously wrong:
image("poke"+i+".png"...
image() expects a PImage, not a filename. image[i] in your case, i think.
PImage [] image
and rename this, there is an image() method and it'll get confusing.
@koogs -> perhaps Boton is related to the example in her previous post below: /:)
forum.processing.org/two/discussion/256/animated-buttons#Item_6
Haha yeah, the Boton thing works atm. actually, the whole thing works, but I want to refine it. I had to get rid of a class called "Pokemon", look:
And this is the "Boton" class:
In order to refine it, you should really take a look at this article: :-\"
http://wiki.processing.org/w/From_several_variables_to_arrays