Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
diabloj

Khan Academy Java Script problem, help?

Recommended Posts

Posted · Original PosterOP

Solved

 

So, now that it's almost New Year's Eve I'm trying to make an animated card using Khan Academy's Java Script Editor. I've ran into a few problems though, but maybe some of you can help?

I've created a function that uses a multidimensional array to store the X and Y positions of a "Rocket". Then I've assigned a random array of numbers for the Rockets' "Explosion points". Then I want to pass in the X and Y position of that Explosion point and then use another function to generate the explosion, because I want to remove the rocket (using the .shift function)

 

The "yey" text in the Explosion function is just a substitute for what would be an explosion like animation.

 

 

Here's the code:

//Initliazationbackground(95, 0, 0);var timer=0;var posX=[];var posY=[];var StartRandomPoint=[];StartRandomPoint.push([random(0,400),0]);var ExplPoint=[];var Stop=[];var RocketNr;//StartRandomPoint[RocketNr][0], [RocketNr][1]//       =//StartRandomPoint[XPos to RocketNr][YPos to RocketNr] var Explosion = function(posX, posY){    text("yey",posX[RocketNr], posY[RocketNr]);    rect(posX[RocketNr], posY[RocketNr],10,10);    };     var draw = function() {    background(95, 0, 0);    timer+=1;       for (var RocketNr = 0; RocketNr < StartRandomPoint.length               ; RocketNr++) {        noStroke();        fill(255);        ellipse(StartRandomPoint[RocketNr][0],         StartRandomPoint[RocketNr][1], 10, 10);                if(StartRandomPoint[RocketNr][1]<ExplPoint[RocketNr]             ){                          text("Yey", StartRandomPoint[RocketNr][0],              ExplPoint[RocketNr]);            }                      // Increase the y position each time          StartRandomPoint[RocketNr][1] -= 2.5;                if(timer>70){            StartRandomPoint.push([random(20,380),400]);            timer=0;           ExplPoint[RocketNr]=random(180,60);            }                 // rect(100,60,20,120);       while(StartRandomPoint[RocketNr][1]<ExplPoint[RocketNr]){                posX=StartRandomPoint[RocketNr][1];        posY=ExplPoint[RocketNr];        StartRandomPoint.shift();        Explosion(posX,posY);     }    }};

Main rigg: AMD Phenom II 1090t @ 4.0GHz | AMD Radeon HD 6950 ASUS Crosshair IV Formula NZXT Switch 810 Coolit C240 A.L.C.

Laptop: HP Elitebook 8470p + Samsung 830 240GB

HiFi: Laptop(foobar) -> Halide Design HD DAC -> Sansui SAP201V -> Vienna Acoustics Haydn Grand (or DT 770) 

Link to post
Share on other sites
Posted · Original PosterOP

It's not showing any errors, but the text in the Explosion function doesn't appear, probably because the posX[RocketNr] and posY[RocketNr] is not properly passed into the function. If I just write text("yey", 100, 100); it works. So the function is called.


Main rigg: AMD Phenom II 1090t @ 4.0GHz | AMD Radeon HD 6950 ASUS Crosshair IV Formula NZXT Switch 810 Coolit C240 A.L.C.

Laptop: HP Elitebook 8470p + Samsung 830 240GB

HiFi: Laptop(foobar) -> Halide Design HD DAC -> Sansui SAP201V -> Vienna Acoustics Haydn Grand (or DT 770) 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


×