Slow down each draw

edited April 2016 in Android Mode

Hello... I have main class. It ofcourse containse Draw(fps 24),setup... in Main draw i call funtion enemy.draw(); Enemy draw i have animation which i need to slow down rapidly...Something around 4+/- fps (I want to slow it down , not to make it laggy). Can you guys help me please? Thnaks :)

Tagged:

Answers

  • Not without you posting your code.

    Can you open up task manager and see if the memory of the application fills up fast?

  • How does your sketch determine how fast the animation is drawn? Without seeing your code (or some example code demonstrating your issue) it is very hard to help you.

  • edited April 2016

    Platform game

    Enemy enemis = new Enemy();
    
    Normal main :
    Pimage blabla
    void setup(){
    image,resolution inicialization
    frameRate(24);
    }
    
    void draw(){
    Somefunction inicialization,IF,for that runs good
    enemis.Draw();   <-- need to slow it down so it doesnt slow downt this Main draw
    }
    
  • class Enemy{
      void setup(){
            frameRate(3);  <--- i tried to slow Enemy draw here
    }
      void draw(){
            for(){
              if(){}               <--- function that i need to slow down
    }
    }
    
    }
    
  • The draw function in Enemy class doesnt have to be draw...It can be nammed like enemyMovemenet(){}.. But i still need to slow it down because its still called in Main draw 24 times a sec

  • So instead of having draw() draw your enemy every frame, you could make it only draw it every 24 frames.

  • Wrong, if you call frameRate() in any class, it's still going to impact the whole sketch. You'll need some trickery, like TfGuy44 says.

  • I have 2d array... Every time enemy moves +1 width (for cycle J).. so it moves 24 times a sec... i want it to move like one "block" per sec

  • i cant change frameRate of main draw... I have Player animation inside too... I need that to run in 24fps and enemy animaton lower fps..

  • Answer ✓
    Rec r1, r2, r3, r4;
    
    void setup(){
      size(200,200);
      r1 = new Rec(20,20);
      r2 = new Rec(50,20);
      r3 = new Rec(80,20);
      r4 = new Rec(110,20);
    }
    
    void draw(){
      background(128);
      r1.draw();
      r2.draw();
      r3.draw();
      r4.draw();
    }
    
    class Rec{
      color c;
      int x, y;
      int time;
      Rec( int ix, int iy ){
        time = -1;
        newColor();
        x = ix;
        y = iy;
      }
      void draw(){
        newColor();
        fill(c);
        rect(x,y,20,20);
      }
      void newColor(){
        if( millis() > time ){
          time = millis() + x; // x is also delay in ms.
          c = color(random(255),random(255),random(255));
        }
      }
    }
    

    Forget about setting the frame rate at all. Have each object maintain a time when it is to next be updated.

  • Thats the thing that i wanted:) Thank you

Sign In or Register to comment.