P5 copy() and animation question

Does anyone know if there is an easy way to make these aliens move faster and be better? https://www.openprocessing.org/sketch/433119

When the alien is by itself, it moves faster and looks better than in the array. I just change the dx = dx + 5 line. https://www.openprocessing.org/sketch/428281

when I try to change the speed in lines 43 and 53 in the array sketch, it looks terrible.

Thank you,

Answers

  • Answer ✓

    if there is an easy way to make this go faster and be better

    What are your thoughts about making it better? When it is by itself, the speed is 35. Is that what you mean by better? You can implement the same value in your first sketch. I did some minor modifications below.

    Kf

    var w = 64;
    var h = 64;
    var dx = 0;
    var topAlien = []; 
    var fr = 0;
    var speed = 35;
    
    function preload(){
      aliens = loadImage("Spaceinvaders1.png");
    }
    function setup() {
      createCanvas(windowWidth, windowHeight);
      for (var i = 0; i < 10; i++) {
        topAlien.push(new Alien1(i*80,speed));
      }
      frameRate(2);
    }
    
    function draw() {
      background(0);
      update();
      for (var i=0; i< topAlien.length; i++) {
        topAlien[i].display(fr);
      }
    }
    
    function update(){
      fr=(fr+1)%2;    //Simplify version of your code below
      //fr = fr + 1;
      //if (fr >= 2){
      //  fr = 0;
      //}
    }
    
    function Alien1(dx,sp){
      this.dx = dx;  
      this.speed=sp;
    }
    
    Alien1.prototype.display = function(type) {
      this.dx = this.dx + this.speed;
      if (type == 0){
          copy(aliens, 242, 104, 65, h, this.dx, 100, w, h);
      }else{
          copy(aliens, 338, 104, 65, h, this.dx, 100, w, h);  
      }
    }
    
  • Thanks for your help.

    In answer to your question about making it better, when I changed the speed (in the array sketch), it ruins the graphics.

    On my finished product, I want really good graphics.

    Also, now or soon, I need to add the other rows of aliens. Since the graphics get messed up when I change the speed, adding more aliens is going to be tough.

Sign In or Register to comment.