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

2014/2/27

Launching object

1
2
cyclobs cyclobs

2014/2/27

#
Hello GF, I want to launch the Pear vertically when Link touches it, but I can't get it to work. Here's my code so far: Thanks
  public void act() 
    {
        jump();
    }

    public void jump() 
    {
        if (
isTouching(Link.class));
        {
            setLocation(getX(), getY()-20);
        }  
    }
}
davmac davmac

2014/2/27

#
In what way does it not work?
cyclobs cyclobs

2014/2/27

#
When the game starts, the pear moves vertically even when Link isn't touching the Pear
davmac davmac

2014/2/27

#
That doesn't seem like it should happen. Could you upload the scenario?
cyclobs cyclobs

2014/2/27

#
How can I upload a scenario?
davmac davmac

2014/2/27

#
Click the "share" button.
cyclobs cyclobs

2014/2/27

#
I don't see a share button where can I find that one? Because I only have the options: quote, code, image, youtube, link, list, header, bold,itlaic, underline & strike.
davmac davmac

2014/2/27

#
In Greenfoot itself, click the share button.
cyclobs cyclobs

2014/2/28

#
Thanks i uploaded it right away: http://www.greenfoot.org/scenarios/10962
danpost danpost

2014/2/28

#
You will need to upload the scenario again. But, this time make sure to check the 'Publish source code' checkbox so the code is available for others to look at (to help fix).
cyclobs cyclobs

2014/3/3

#
Sorry for the delay! http://www.greenfoot.org/scenarios/10962 anyway thanks for helping
danpost danpost

2014/3/3

#
The scenario is actually doing what you want. The problem is due to your Link images. There is a awful lot of transparent space around the outer edges of the image, making intersecting with other objects occur long before it appears that the images are intersecting. You can use an image editor that supports transparency to crop the image; or you can download my Image Transparency Adder and edit your images with it. I noticed that you had the bird eat the pear AND the pear eat the bird. Only one of the two will occur during intersection. If you want both to be removed, then put the intersection code in only one of the two classes and remove both actors together.
cyclobs cyclobs

2014/3/3

#
Thank you for your fast reaction. I will fix this!
danpost danpost

2014/3/3

#
You better use something other than my scenario to edit the image for now. I found a flaw in it which will need to be dealt with (it does not remove ALL the excess transparency along the edges).
cyclobs cyclobs

2014/3/3

#
Thanks anyways, But I want to move the pear vertically and when it hits the bird or the edge of the world, it should remove and spawn another. Ps im new to greenfoot Thank you !
There are more replies on the next page.
1
2