Posted on



This video looks at how to add and delete elements from an array using the JavaScript array functions push() and splice().

Next video:

Support this channel on Patreon:

Contact:

Send me your questions and coding challenges!:

Link to code on Github:

p5.js:

For More p5.js Videos:

Help us caption & translate this video!

📄 Code of Conduct:

Nguồn:https://hdwallpaperslovely.com/

40 Replies to “7.4: Adding and Removing Objects – p5.js Tutorial”

  1. I want to have my "cell" duplicate itself twice (not at the same time) with a 15% chance that it will. How do I do that? Thanks for the help!

  2. You are an excellent teacher! I often find myself reviewing fundamentals to stay sharp and nothing's worse than wasting time in an incoherent video or verbose documentation. Your flow is just right – informative, concise, and even entertaining so thank you!

  3. The bubbles disappearing with splice is the same thing many games do with things like bullet decals, casings, particles.

  4. How should I make an object in p5.js, by using the
    var bubble = function (){}
    method or should I use
    function bubble(){}

    What's the difference

  5. * Need help!! Facing the issue while doing the same task in processing..

    Bubble[] bubbles = new Bubble[50];

    void setup() {
    size(600, 400);
    for(int i = 0; i < bubbles.length; i++)
    {
    bubbles[i] = new Bubble();

    }
    }

    void draw() {
    background(0);
    for(int i = 0; i < bubbles.length; i++)
    {
    bubbles[i].move();
    bubbles[i].display();
    }
    }

    void keyPressed() {
    bubbles.splice(0,5); //here is the issue!!
    }

    ======

    class Bubble {
    float x = random(0, width);
    float y = random(0, height);

    void display() {
    stroke(255);
    fill(255, 0, 150, 50);
    ellipse(x, y, 24, 24);
    }

    void move() {
    x = x + random(-1, 1);
    y = y + random(-1, 1);
    }
    }

  6. I'm having a really hard time understanding why you need the for loops in the example he uses. Why can I not just have the constructor function and the mousePressed function and that work? Why is the for loops a necessity? Why is the bubbles.length loop needed to have the mousePressed event work? Please help me understand this, someone. It's hard to look this stuff up on the internet and get a direct answer to my very specific question without someone here that can guide me through it.

  7. Hi, Daniel, thanks for your videos. Im very enjoying with them. Here im trying to make some effect like, once you mouseDragged the circle, and with 1click , they will spread to random direction(out of screen). so, is there anyway to override the move() function of the constructor function of Bubble? thanks!

  8. i reaaly like when you use analogy to explain things because programming is so abstract, and is nice to come with a picture of what's going on in the program

  9. For some reason mouseDragged does not work for me, although mousePressed works perfectly. Did anything change in P5 that prevents this from working? – It does work wiht mouseMove however, but that's not the same

Leave a Reply

Your email address will not be published. Required fields are marked *