We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › export problem
Page Index Toggle Pages: 1
export problem (Read 2053 times)
export problem
Oct 18th, 2009, 3:42am
 
Hello...

Im having a problem when im trying to export...

whenever i export and view the html page, my program is just black, it works fine in processing... but when i export it breaks, can anyone give me a hand ?

my code is

PImage baddy; //images
PImage viper;
int numOfStars = 100;
//new star array pulled from the class
Star[] st = new Star[numOfStars];

int centerxPos = 50;
int centeryPos = 50;

int starsDistance = 500; //distance between the stars
float starsSpeed = 1 ; //speed of the stars

shoot[] B;
int num_shoots=10,shoot_check=-1; //number of bullets, and check the shhot amount

baddy[] R; //baddy array pulled from the class
int num_baddys=5, baddy_check=-1; //number of bullets, and check the shhot amount

boolean hit=false; // the baddy has not been hit yet

void setup(){
 
noCursor();
smooth();
size(600,600);


 
//start the stars
 
noStroke();
centerxPos=height/2;
centeryPos=width/2;
for(int i = 0; i < numOfStars; i += 1){
   
   st[i] = new Star();
 
   
 }


 //start the shooting or bullets

    B = new shoot[50];
 for(int i=0;i<num_shoots;i++)
 {
 B[i] = new shoot();
 }
 
 //star the baddies
 
  R = new baddy[num_baddys];
 for(int i=0;i<num_baddys;i++)
 {
   R[i] = new baddy();
   R[i].baddy_size = int(random(50,5));  

 }
}

void draw(){

 background(1); // background colour
 
   //draw the baddies random position
 baddyCheck();
 
 // draw the shooting
 for(int i=0;i<num_shoots;i++)
 {
 if(B[i].bflag==1)
 {
   B[i].shoot_ypos-=5;
   fill(0,0,255);
   B[i].shoot_display();
 }
 if(B[i].shoot_ypos<0)
 {B[i].bflag=0;}
 }
 
  // draw the baddies
 
 for(int j=0;j<num_baddys;j++)
 {
 if(R[j].rflag==1)
 {
   R[j].baddy_ypos+=R[j].speed;
   R[j].baddy_display();
 }
 if(R[j].baddy_ypos>600)
 {R[j].rflag=0;}
 }

//if the baddies get hit, call the collision class

 hit = collision();
 
 
 
 
 for(int i = 0; i < numOfStars; i+= 1){
   st[i].starDraw();
    //draw stars
    }
    // if h is pressed you go into hyper  drive
    if(keyPressed) {
   if (key == 'h' || key == 'H') {
     starsSpeed = 10;

   }
   }
   
    //if s is pressed you go back to normal speed
         if(keyPressed) {
   if (key == 's' || key == 'S') {
     starsSpeed = 1;

   }
    }
    //ship image
    viper = loadImage("viper.png");
    image(viper,mouseX-42,450); //map the ship to the mouse and lock it to the bottom of the screen

}

// collision, if the bullet hits the baddy, remove the baddy

boolean collision() {  

for(int i=0; i<num_shoots; i++) {    
  for(int j=0; j<num_baddys; j++)  {
    float dx =R[j].baddy_xpos-B[i].shoot_xpos;
    float dy =R[j].baddy_ypos-B[i].shoot_ypos;
    float distance=dx*dx + dy*dy;
    if(distance<= R[j].baddy_size * R[j].baddy_size) {
        R[j].baddy_ypos=-5;
        R[j].rflag=0;
        B[i].shoot_ypos=-5;
        B[i].bflag=0;
        return(true); // remove the baddy
      }    
    }
}
return(false);
}


//the shoot class
class shoot
{
 int shoot_xpos, shoot_ypos;
 int bflag=0;

 void shoot_display()
 {
   fill (255,0,0); // colour
   rect(shoot_xpos,shoot_ypos,5,5); //the bullet
 }
}


//if mouse pressed check the bullets, if i have enough shoot.
void mousePressed()
{
   
   shoot_check++;
   if(shoot_check == num_shoots-1)
   {shoot_check=0;}
   B[shoot_check].bflag=1;
   B[shoot_check].shoot_xpos=pmouseX;
   B[shoot_check].shoot_ypos = 485;

}
//baddy check, if there are none add one... at random spots.
 void baddyCheck()
{
 baddy_check = int(random(-1,num_baddys-1));
 if(R[baddy_check].rflag!=1)
   {
   R[baddy_check].rflag=1;
   R[baddy_check].baddy_xpos= int(random(0,600)); // random Xpos of the baddies
   R[baddy_check].baddy_ypos = 0;
   R[baddy_check].speed = int(random(1,4)); // random speed of the baddies
   
   
}
}
 
 
 // the baddy class
class baddy
{
 int baddy_xpos, baddy_ypos,speed,baddy_size;
 int rflag=0;  
 void baddy_display() //display the baddy
 {

     baddy = loadImage("baddy.png");
    image(baddy,baddy_xpos,baddy_ypos,50,75); //load the baddy image and map it to the
                                              //xpos and ypos, and set the size

   
   if(keyPressed) {
   if (key == 'h' || key == 'H') {
   
     speed = 10;
                                 }  
                  }

 }  
}



class Star {  
 //position of the stars
 
 float xPos = 0, yPos = 0, zPos = 0, sxPos = 0,syPos = 0;
 void position(){
   zPos= random(1 ,600);
   xPos= random(1 ,600);
   yPos= random(1 ,600);
 }
 //draw the stars
 void starDraw(){
   if (zPos < starsSpeed){
     position();
   }
   //this is where the stars start.
   zPos-=starsSpeed;
   sxPos=(xPos*starsDistance)/(yPos)-centerxPos+100;
   syPos=(yPos*starsDistance)/(zPos)-centeryPos+100;
   if (sxPos <0 | sxPos>width){
    position();
   }
   if (syPos < 0 | syPos > height){
    position();
   }
   
   // colour and size of stars
   fill(255,255,255);
   rect(sxPos,syPos,1,1);
 }
}


i cant give you the images, cuz im unable to post links yet.
Re: export problem
Reply #1 - Oct 18th, 2009, 12:10pm
 
Generic remarks: you should put size() as first instruction of setup(), as advised by the reference.
And you should not load the images each time you draw something, it is a waste of CPU and I/O.
If you want to do the loading in a class, which is understandable, make the image static and load it only if the reference is null.

That shouldn't resolve your issue in line, alas... I am not sure what is your problem. If the images are in the jar, you don't need to sign the applet. Have you any error in the Java console?
Re: export problem
Reply #2 - Oct 19th, 2009, 1:22am
 
thanks for your help mate...

I've played around a bit with what you said, however its still black when i export it...

i really don't know how to fix it, i'm still a newbie to processing.
Re: export problem
Reply #3 - Oct 19th, 2009, 2:35am
 
Let's re-iterate my last sentences in a more verbose mode  Roll Eyes:
- Are your images in data folder? If so, check they are in the exported jar file (open it with any archive manager);
- Do you have any error in the Java console? Displaying this console depends on your browser, in IE you have to activate it in the advanced preferences, in Firefox you just go to Tools > Java console.
Re: export problem
Reply #4 - Oct 19th, 2009, 3:33am
 
hey mate...

i sent you a PM so i could show you some images... im unable to post links when i post here yet.

hopefully you can help me Smiley
Re: export problem
Reply #5 - Oct 19th, 2009, 4:09am
 
OK, but I answer here, as some advices might be of general interest.

Well, the black screen doesn't help...
Neither does the list of files in export folder. I meant to look inside the .jar file itself.
And you show the browser's console which isn't very useful either, although I see a JavaScript error, but since you provide a truncated image instead of plain text, I can't see what is the problem.

To display the Java console, you have to set this in Java Web Start settings: type javaws -viewer in your terminal, discard the cache view, go to Advanced tab, Java Console item, check first option (Display console).
It shows output of Processing (the println) and Java errors when you start an applet. Very useful.

You should also check why you have a JavaScript error, but is probably unrelated as the exported HTML file doesn't have any JS.
Re: export problem
Reply #6 - Oct 19th, 2009, 4:29pm
 
how would i look inside the jar file ?

I have to leave for work in a minute, so i will try all of these things when i get home.

thank you alot for all your understanding and help

Re: export problem
Reply #7 - Oct 19th, 2009, 4:40pm
 
hey, i think i found something that might actually help, i did enabled that java thing in the terminal and it gave me this

Java Plug-in 1.5.0
Using JRE version 1.5.0_19 Java HotSpot(TM) Client VM
User home directory = /Users/Jonathan


----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
p:   reload proxy configuration
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------

MRJ Plugin for Mac OS X v1.0.1
[starting up Java Applet Security @ Tue Oct 20 09:38:20 EST 2009]
Tue Oct 20 09:38:20 EST 2009 JEP creating applet game1 (file:/Users/Jonathan/Documents/QUT/2009%20-%20Sem%202/KIB205%20Programming%20Fo
r%20Visual%20Design%20&%20Artists%20/Assignments/Assignment%203/FINAL/game1/appl
et/)
The file "baddy.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
Exception in thread "Animation Thread" java.lang.NullPointerException
     at processing.core.PGraphics.image(PGraphics.java:2197)
     at processing.core.PApplet.image(PApplet.java:7214)
     at game1$baddy.baddy_display(game1.java:207)
     at game1.draw(game1.java:107)
     at processing.core.PApplet.handleDraw(PApplet.java:1426)
     at processing.core.PApplet.run(PApplet.java:1328)
     at java.lang.Thread.run(Thread.java:613)
Re: export problem
Reply #8 - Oct 19th, 2009, 8:25pm
 
you look into the jar by simply renaming it to rar and opening it with a rar packing programm like winrar on windows...
Re: export problem
Reply #9 - Oct 19th, 2009, 11:25pm
 
thanks mate...

i did that, and it doesnt seem to be exporting the images...

how would i go about exporting it with the images? i thought it just did that ?
Re: export problem
Reply #10 - Oct 19th, 2009, 11:30pm
 
hey guys, i exported it... then copied and pasted the images into the exported folder, now it works fine...

thanks alot your your time and help with resolving this issue for me.
Re: export problem
Reply #11 - Oct 20th, 2009, 2:12am
 
Cedric wrote on Oct 19th, 2009, 8:25pm:
you look into the jar by simply renaming it to rar and opening it with a rar packing programm like winrar on windows...

Cedric, .jar files are actually .zip files, not .rar files! Rar is a proprietary format, it can be freely opened but can be created only with WinRAR, which, as the name implies, exists only for the Windows platform. That's why, along with the fact that WinRAR isn't free, I never recommend it, there are excellent alternatives like IZArc or 7-Zip. Both for Windows, but there are good alternatives for Unix/MacOS systems.
That's what I meant by "archive manager", above... Smiley

blinker_182, your images should be automatically exported in the jar file if you put them in the data folder, as I wrote earlier.
Re: export problem
Reply #12 - Oct 20th, 2009, 4:14am
 
i just had them in my sketch folder, i didn't create a data folder...

i thought it didn't really matter...
Re: export problem
Reply #13 - Oct 20th, 2009, 6:48am
 
PhiLho is right. it just worked for me as winrar can open rar zip etc...
I probably thought jar=rar, makes sense... but its actually a zip.
Page Index Toggle Pages: 1