Processing 2.0 on Eclipse ADT need help

edited October 2013 in Android Mode

Hi,

I had tried using the sample/tutorial given by Jer Thorp and had tried implementing it on Eclipse ADT. I had imported the android-core.jar from the processing 2.0 into the Eclipse Libs folder. However when I copied the sample codes into Eclipse ADT, it highlights the "background(mouseY * (255.0/800), 100, 0);" in the "draw method as below and state that "The method background(int, float) in the type PApplet is not applicable for the arguments (double, int, int)".

public void draw() {
//Set the background colour, which gets more red as we move our finger

//down the screen.
background(mouseY * (255.0/800), 100, 0);
//Chane our box rotation depending on how our finger has moved right-to-left
boxRotation += (float) (pmouseX - mouseX)/100;

   //Draw the ball-and-stick
   line(width/2, height/2, mouseX, mouseY);
   ellipse(mouseX, mouseY, 40, 40);

   //Draw the box
   pushMatrix();
     translate(width/2, height/2);
     rotate(boxRotation);
     rect(0,0, 150, 150);
   popMatrix();
 };

And if I change the code from"255.0" to "255" such as "background(mouseY * (255/800), 100, 0);", the emulator can execute the application successfully using Eclipse ADT, however the colouring functionality when I hover around will be lost. Could anyone please help me or teach me how to fix this ?

Thanking you in anticipation.

Answers

  • Moved to the Android category.

    In Processing PDE, all numbers like 255.0 are float numbers. In classical Java, thus in Eclipse, these are double numbers. Hence the error message you got. Just cast the first parameter to an int.

  • I have tried casting the first parameter to an int as in background(mouseY * (int)(255.0/800), 100, 0);

    however this had cause it to lose its functionality when I tested in the emulartor

  • edited October 2013 Answer ✓

    You must cast the entire value to anint,not just part of it. In other words, you must move the cast to outside a set of parentheses, e.g:

    background((int) (mouseY * (255.0/800)), 100, 0);
    

    Or, perhaps more simply, you can declare255.0to be afloatby adding an "f" to the end:

    background(mouseY * (255.0f/800), 100, 0);
    
  • YAY! it worked , Thank you! :)

Sign In or Register to comment.