Loading...
Logo
Processing Forum
I would like to load a library object in an class I created. I am not too sure how to code it.

I want to load the Gif class from the gifAnimation library into a class 

In my main class

I have 

Copy code
  1. import gifAnimation.*;

  2. drone myDrone;

  3. public void setup() {
  4.   myDrone = new drone();
  5.   size(400,400,P2D);
  6.   frameRate(20); 
  7. }


  8. void draw() 
  9. {
  10.   background(0);
  11.   myDrone.circle();
  12. }


then in my object (called drone) I have : 


Copy code
  1. class drone
  2. {

  3.   Gif drone_up = new Gif(this, "drone_up.gif");
  4.   Gif drone_front = new Gif(this, "drone_front.gif");
  5.   Gif drone_left = new Gif(this, "drone_left.gif");
  6.   Gif drone_right = new Gif(this, "drone_right.gif");

  7.  drone()
  8.  {
  9.     
  10.   
  
etc...

but get that the constructor Gif is undefined - error

Is it because the " this" is not pointing at the main class ?

not sure I am going in the right direction here

ponnuki.net

Replies(3)

 Is it because the " this"  is not pointing at the main class ?
Yes, well guessed. This is a common question (should be addressed in the wiki?) and fortunately, the solution is simple:
Copy code
  1. public void setup() {
  2.   myDrone = new drone(this);
  3.   size(400,400,P2D);
  4.   frameRate(20); 
  5. }

  6. class drone
  7. {
  8.   PApplet pa;
  9.   Gif drone_up;
  10.   Gif drone_front;
  11.   Gif drone_left;
  12.   Gif drone_right;

  13.   drone(PApplet mainClass)
  14.   {
  15.     pa = mainClass;
  16.     drone_up = new Gif(pa, "drone_up.gif");
  17.     drone_front = new Gif(pa, "drone_front.gif");
  18.     drone_left = new Gif(pa, "drone_left.gif");
  19.     drone_right = new Gif(pa, "drone_right.gif");
  20.   }    
  21. // [...]
  22. }
In this case, you don't actually need to store the PApplet reference, if you don't use it outside of the constructor.
Thanks ! 

Where can I read more about PApplet ? I tried some search on processing.org but it's pointing to page that doesn't exist anymore. 

gef

ponnuki.net