This site requires JavaScript, please enable it in your browser!
Greenfoot back
vegtio
vegtio wrote ...

2014/11/13

How do i delay the time of removal for my actor when spawned(and does not stop entire world)?

vegtio vegtio

2014/11/13

#
My problem is that my actor "kneepower" is removed so fast that it does not appear to spawn at all. What I need is, it to delay the time it is removed.
  public void kneeOnCommand()
  {
   if(Greenfoot.isKeyDown("x"))
   {
        World myLevel1 = getWorld();
        myLevel1.addObject(kneepower, 0, 0);
        kneepower.setLocation(getX()+35, getY()+10);
        kneepower.setRotation(getRotation());
         myLevel1.removeObject(kneepower);
   }  
   
        if(Greenfoot.isKeyDown("z"))
        {
            World myLevel1 = getWorld();
            myLevel1.addObject(kneepower, 0, 0);
            kneepower.setLocation(getX()-35, getY()+10);
            kneepower.setRotation(getRotation());
            myLevel1.removeObject(kneepower);
   }
  }
danpost danpost

2014/11/14

#
You are adding and removing the 'kneepower' object within the same act cycle. Line 6 adds one and line 9 removes it -- all in the same instant; line 15 adds one and line 18 removes it. If you want it to be removed later, you need to move the removal statement (lines 9 and 18) to a separate 'if' block that asks for the conditions required to remove the object. There are other considerations as well (1) if the actor moves, then the kneepower object may need to move with it (2) if the actor turns, the kneepower object may need to be removed at that time (3) you need to decide on what will cause its removal otherwise -- like, do you want to put a time limit on it (using game-time, not real time) or do you want it to remain until the key that triggered it is released; or, maybe you have some other way in mind.
danpost danpost

2014/11/14

#
As I do not know exactly what your character is or what you want it to be capable of (the behavior of it), I cannot say for sure whether what I perceive is ok or not. But, it seems that you are allowing the kneepower to be on either side of the player regardless of the direction the player is facing. In other words, the kneepower could be facing either way regardless of the side of the player it is on. Somehow, it just does not appear right. Just saying.
You need to login to post a reply.