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

2018/4/29

game like playing skipping

intanmuliawati intanmuliawati

2018/4/29

#
is there a way to make a rope can rotate around the object (human), like we play skipping? thankyou
danpost danpost

2018/4/29

#
Taking advantage of undocumented behavior (which could change in some future version of greenfoot -- but not likely), you could do the following. The rope changes directions from up to down and from down to up. During one of those changes, you would remove and re-add the rope into the world; at the other change, you would do likewise with those actors to be in front of the rope.
intanmuliawati intanmuliawati

2018/5/1

#
oh well I understand, but can you give me a code to make a rope changes directions from up to down.thanks for helping
danpost danpost

2018/5/1

#
intanmuliawati wrote...
oh well I understand, but can you give me a code to make a rope changes directions from up to down.thanks for helping
I would think you would have an animation set of images for that (if I understand what you are wanting correctly).
intanmuliawati intanmuliawati

2018/5/3

#
I've made the Rope change direction from top to bottom, but how to remove and re-add the rope into the world? should I make 2 objects for a rope to differentiate the rope in front of the human and the rope behind the human? sorry for my bad english
danpost danpost

2018/5/3

#
intanmuliawati wrote...
I've made the Rope change direction from top to bottom, but how to remove and re-add the rope into the world? should I make 2 objects for a rope to differentiate the rope in front of the human and the rope behind the human? sorry for my bad english
That is not a horribly bad idea. You avoid using undocumented behavior that way.
intanmuliawati intanmuliawati

2018/5/3

#
oh okey.so how to remove and re-add the rope? iam still confused with that.maybe you can give me the code.or you have another way?
intanmuliawati intanmuliawati

2018/5/3

#
public class Tali extends Actor { private GreenfootImage images= new GreenfootImage; private int jeda=5,num=0,deltay=10; public void addedToWorld(World Taman) { for (int i=1; i<images.length;i++){ images=new GreenfootImage("tali"+i+".png"); } setImage(images); } public void act() { // Add your action code here. if(jeda==0)jeda=5; if(jeda==1){ setImage(images); num++; if(num>=images.length) { getWorld().removeObject(this); num=0; } } if(jeda>0)jeda--; } } this is my code for class rope
danpost danpost

2018/5/3

#
public class Tali extends Actor
{
    private GreenfootImage[] images = new GreenfootImage[10];
    private int jeda;

    public Tali()
    {
        for (int i=0; i<images.length; i++) images[i] = new GreenfootImage("tali"+(i+1)+".png");
        setImage(images[0]);
    }
    
    public void act() 
    {
        if (++jeda%5 == 0)
        {
            if (jeda/5 < images.length) setImage(images[jeda/5]);
            else
            {
                getWorld().removeObject(this);
            }
        }
    }
}
Here is a cleaned up version of your class. I combined num in with jeda to reduce the number of fields to work with. Also, I used a class constructor instead of overriding the addedToWorld method to build the array of images. We can start with this to make the fore and aft rope You will now need another class for the rope in the other state. The code will be exactly the same except for line 8, where (i+1) should be replaced with (10-i) to reverse the order of the images. Then, in both classes before the line that removes the actor, add an actor of the other one into the world. In the above code used in the other class, you would insert at line 19:
getWorld().addObject(new Tali(), getX(), getY());
Finally, in your world constructor, add a line setting the paint order of the actors in your world.
intanmuliawati intanmuliawati

2018/5/6

#
oh very well thankyou,let me try ur code :)
intanmuliawati intanmuliawati

2018/5/6

#
i got a problem again public class Taman extends World { public Taman() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(700, 495, 1); addObject(new Tali(),338,252); prepare(); addObject(new Tali2(),338,252); } private void prepare() { Human human = new Human(); addObject(human,314,337); } this is the code of my world class,how to remove second rope when the game is start ? and then the first rope that should behind the human, at the first time the rope is behind the human but after removing and then re-add to the world the rope is in front of the human.so how to make the first rope still in behind the human? thank you
danpost danpost

2018/5/6

#
intanmuliawati wrote...
<< Code Omitted >> this is the code of my world class,how to remove second rope when the game is start ? and then the first rope that should behind the human, at the first time the rope is behind the human but after removing and then re-add to the world the rope is in front of the human.so how to make the first rope still in behind the human? thank you
Only add one of them into the world in the world constructor and add a setPaintOrder line there with one of the rope actor class names in it. The actors will do the switching. Before they remove themselves, have them add the other type into the world.
intanmuliawati intanmuliawati

2018/5/7

#
public class Taman extends World
{
    
    public Taman()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(700, 495, 1);
        addObject(new Tali(),338,252);
        setPaintOrder(Tali2.class);
        prepare();
        
        
      
    }
    

    private void prepare()
    {
        Human human = new Human();
        addObject(human,314,337);
        
        
        
    }
    
    
       
    }
public class Tali extends Actor
{
    private GreenfootImage[] images = new GreenfootImage[10];
    private int jeda;
 
    public Tali()
    {
        for (int i=0; i<images.length; i++) images[i] = new GreenfootImage("tali"+(i+1)+".png");
        setImage(images[0]);
    }
     
    public void act() 
    {
        if (++jeda%5 == 0)
        {
            if (jeda/5 < images.length) setImage(images[jeda/5]);
            else
            {
                
                getWorld().addObject(new Tali2(), getX(), getY());
                getWorld().removeObject(this);
            }
        }
    }
}
public class Tali2 extends Actor
{
    private GreenfootImage[] images = new GreenfootImage[10];
    private int jeda;
 
    public Tali2()
    {
        for (int i=0; i<images.length; i++) images[i] = new GreenfootImage("tali"+(10-i)+".png");
        setImage(images[0]);
    }
     
    public void act() 
    {
        if (++jeda%5 == 0)
        {
            if (jeda/5 < images.length) setImage(images[jeda/5]);
            else
            {
                
                getWorld().addObject(new Tali(), getX(), getY());
                getWorld().removeObject(this);
            }
        }
    }
}
at the first time class tali(first rope) is behind the human, but after the object from class tali(first rope) is removing and then re-add again to the world by the class tali2 ,the rope is going to be in front of the human.so both of them became in front of the human.how to make the first rope still behind the human when it re-add to the world?what means "have them add the other type into the world"? iam sorry if i ask u many question.i should make this game for my school assigment
danpost danpost

2018/5/7

#
intanmuliawati wrote...
at the first time class tali(first rope) is behind the human, but after the object from class tali(first rope) is removing and then re-add again to the world by the class tali2 ,the rope is going to be in front of the human.so both of them became in front of the human.how to make the first rope still behind the human when it re-add to the world?what means "have them add the other type into the world"? iam sorry if i ask u many question.i should make this game for my school assigment
danpost wrote...
add a setPaintOrder line there with one of the rope actor class names in it.
intanmuliawati intanmuliawati

2018/5/7

#
it works.thank you so much danpost :)
You need to login to post a reply.