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

2015/1/21

Code

Express88 Express88

2015/1/21

#
How do you make something fall
Express88 Express88

2015/1/21

#
using code because I only know how to move something side to side.
danpost danpost

2015/1/21

#
In the act method of the class, add something like this:
setLocation(getX(),getY()+1);
The '1' can be replaced with a field name so you can vary the rate. For example:
private int ySpeed = 0;
// in act method
ySpeed++; // acceleration due to gravity
setLocation(getX(), getY()+ySpeed);
The field can be set to zero when an obstacle is encountered and set to some nominal negative value for jumping.
Express88 Express88

2015/1/21

#
Thanks
Express88 Express88

2015/1/22

#
One more thing how do you make two objects at once disappear.
danpost danpost

2015/1/22

#
Please show attempted code.
Express88 Express88

2015/1/22

#
 public void die()
    { 
        {
            Actor fish; 
            fish=getOneObjectAtOffset(0,0, Fish.class); 

            if (fish != null) 
            { 
                World world; 
                world=getWorld(); 

                world.removeObject(fish);
            }
        }
    }
    {
        Actor arrows; 
        arrows=getOneObjectAtOffset(0,0, Arrows.class); 

        if (arrows != null) 
        { 
            World world; 
            world=getWorld(); 

            world.removeObject(arrows);
        }
danpost danpost

2015/1/23

#
What method is the code from line 16 down in? Look like an undeclared block of code to me. Then, what two objects do you want removed at once?
You need to login to post a reply.