Image cycle problem! D:

edited November 2013 in Questions about Code

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()
{

}
Tagged:

Answers

  • it doesn't work (it doesn't even compile)

    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.

  • edited October 2013

    @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:

    Boton []buttons;
    int activeButtons=-1;
    Table pokeTable;
    PImage [] image = new PImage[17];
    PImage poke0,poke1,poke2,poke3,poke4,poke5,poke6,poke7,poke8,poke9,poke10,poke11,poke12,poke13,poke14,poke15,poke16,poke17;
    PImage img0,img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11,img12,img13,img14,img15,img16,img17;
    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);
    
      /*for(int i=0; i<image.length;i++)
      {
        image(image[i], i*50, i*50);
      }*/
    
      if(activeButtons!=-1)
      {
        switch(activeButtons)
        {
          case 0: //fuego
          /*int x = 50;
          int y = 50;
    
          for(int i=6; i<=11;i++)
          {
    
    
    
            if(x*i<300)
            {
              image(image[i],x*i-300,y+150);
            }
    
            else
               image(image[i], x*i,y);
           image(image[i], x*i,y);
    
          }*/
    
    
          poke6 = loadImage("poke6.png");
          poke7 = loadImage("poke7.png");
          poke8 = loadImage("poke8.png");
          poke9 = loadImage("poke9.png");
          poke10 = loadImage("poke10.png");
          poke11 = loadImage("poke11.png");
    
          image(poke6,0,150);
          image(poke7,290,150);
          image(poke8,540,150);
          image(poke9,0,375);
          image(poke10,290,375);
          image(poke11,540,375);
    
    
          break;
          case 1://agua
    
            poke12 = loadImage("poke12.png");
            poke13 = loadImage("poke13.png");
            poke14 = loadImage("poke14.png");
            poke15 = loadImage("poke15.png");
            poke16 = loadImage("poke16.png");
            poke17 = loadImage("poke17.png");
    
            image(poke12,0,150);
            image(poke13,290,150);
            image(poke14,540,150);
            image(poke15,0,375);
            image(poke16,290,375);
            image(poke17,540,375);
    
    
          break;
          case 2://planta
    
            poke0 = loadImage("poke0.png");
            poke1 = loadImage("poke1.png");
            poke2 = loadImage("poke2.png");
            poke3 = loadImage("poke3.png");
            poke4 = loadImage("poke4.png");
            poke5 = loadImage("poke5.png");
    
    
            image(poke0,0,150);
            image(poke1,290,150);
            image(poke2,540,150);
            image(poke3,0,375);
            image(poke4,290,375);
            image(poke5,540,375);
    
          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; 
    }
    
    //THIS THING IS NOT FINISHED…YET lol
    void keyPressed()
    {
      switch(key)
      {
        case '1':
        if (activeButtons==0)//fuego
        {
         img1=loadImage("img1.png");
         image(img1,0,150);
        }
    
        if(activeButtons==1)//agua
        {
         img2=loadImage("img2.png");
         image(img2,0,150);
        }
    
        if(activeButtons==2)//planta
        {
         img0=loadImage("img0.png");
         image(img0,0,150);
        }
        break;
    
        case '2':
        if (activeButtons==0)//fuego
        {
         img4=loadImage("img4.png");
         image(img4,290,150);
        }
    
        if(activeButtons==1)//agua
        {
         img5=loadImage("img5.png");
         image(img5,290,150);
        }
    
        if(activeButtons==2)//planta
        {
         img3=loadImage("img3.png");
         image(img3,290,150);
        }
        break;
    
        case '3':
        if (activeButtons==0)//fuego
        {
    
        }
    
        if(activeButtons==1)//agua
        {
    
        }
    
        if(activeButtons==2)//planta
        {
    
        }
        break;
    
        case '4':
        if (activeButtons==0)//fuego
        {
    
        }
    
        if(activeButtons==1)//agua
        {
    
        }
    
        if(activeButtons==2)//planta
        {
    
        }
        break;
    
        case '5':
        if (activeButtons==0)//fuego
        {
    
        }
    
        if(activeButtons==1)//agua
        {
    
        }
    
        if(activeButtons==2)//planta
        {
    
        }
        break;
    
       case '6':
        if (activeButtons==0)//fuego
        {
    
        }
    
        if(activeButtons==1)//agua
        {
    
        }
    
        if(activeButtons==2)//planta
        {
    
        }
    
        break;
      }
    }
    

    And this is the "Boton" class:

    class Boton
    {
      int circleX, circleY;
      int tamCir;
      color botColor;
      color botSel; //cambio de saturación cuando el mouse está encima del botón
      color current;
      boolean sobreBot;
      //PImage  
    
      public Boton(int x, int y, color c, color s) 
      {
          circleX= x;
          circleY= y;
          botColor=c;
          botSel=s;
          tamCir= 50;
          current=botColor;
          sobreBot=false; 
      }
    
      void dibujaBoton()
      {
        noStroke();
        fill(current);
        ellipseMode(CENTER);
        ellipse(circleX,circleY,tamCir,tamCir);
      }
    
       boolean isClicked(int mx, int my)
      {
        int dia = 50;
        int h = 50;
    
        if((mx >= circleX && mx <= circleX+dia) && (my >= circleY-h && my <= circleY))
        return true;
        else
        return false;
      }
    }
    
  • In order to refine it, you should really take a look at this article: :-\"
    http://wiki.processing.org/w/From_several_variables_to_arrays

Sign In or Register to comment.