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

2014/7/31

setTransparency of a third object

Nubbit Nubbit

2014/7/31

#
Hello! I'm constructing a classic platform-game for a school-assignment and I want the attributes of my objects to change when they touch certain stuff in the world. At this moment i want the player to touch one thing and this will set the transparency of certain blocks to 255 and also make them "physical" meaning that the player can jump on to the blocks and move ahead from there. i was trying things like :
GreenBrick greenBrick = (GreenBrick)getOneIntersectingObject(GreenBrick.class);
        Girl girl = (Girl)getOneIntersectingObject(Girl.class);
        if(girl != null)
        {
            greenBrick.getImage().setTransparency(255);
            
        }
which made greenfoot really upset (which probably is understandable.. but not to me really ^.^) again, in short : When the player runs on to (touches) an object in the world, this will change the attributes and transparency of a third object. Thanks in advance!
NikZ NikZ

2014/7/31

#
You are getting the image of GreenBrick, but it is not saved anywhere. You'll have to create a GreenfootImage to save it in. Furthermore, you need GreenBrick to SET the image that was made transparent.
NikZ NikZ

2014/7/31

#
Also, setTransparency(255) will turn them opaque, if you want them invisible, set it to 0.
danpost danpost

2014/7/31

#
What class is the code given in? I ask because it seems weird to check for two different intersectors, the girl AND the green brick. Also, you are calling 'getImage' on 'greenBrick' without first checking to see if 'greenBrick' contained something other than 'null'.
NikZ NikZ

2014/7/31

#
So it looks like you have an object and if GreenBrick AND Girl touch this thing, than the brick will become opaque? If you want ALL GreenBricks, try getWorld().getObjects(GreenBrick.class). This will return a list of all GreenBricks. Then use a for loop to turn every GreenBrick opaque.
davmac davmac

2014/7/31

#
You are getting the image of GreenBrick, but it is not saved anywhere. You'll have to create a GreenfootImage to save it in. Furthermore, you need GreenBrick to SET the image that was made transparent.
This isn't correct. The image isn't saved anywhere, but it doesn't need to be, because setTransparency(...) is called on it directly. There's no need to 'set' the image back (using setImage) because it's the same image. Just to be clear, getImage() doesn't return a copy of an actor's image, it returns the image itself. If you modify this image, the actor's appearance will change.
Nubbit Nubbit

2014/7/31

#
Nubbit Nubbit

2014/7/31

#
Nubbit Nubbit

2014/7/31

#
*Edit I don't know why my 2 last posts dissapeared but here we go again: The code is written in the object(called greenblob) that the girl is meant to touch to make the brick visible and physical. All i want is the girl to touch the greenblob which would make the greenbricks less transparent and turning them in to solid objects that she can walk on. I do realize that the code is strange with both greenBrick and girl, thing is that i'm really new to this and i haven't quite understood what "getOneIntersectingObject" does. I got it from reading through these forums searching for setTransparency(), which gave me the code to make the girl invisible when she touches the greenblob. Thanks for the quick answers :] Basicly the pseudo-code is if Girl touches GreenBlobb make Greenbrick pysical and visible + make BlueBrick transparent and non-physical.
NikZ NikZ

2014/7/31

#
Is this what you mean? http://www.greenfoot.org/topics/find/44078
NikZ NikZ

2014/7/31

#
NikZ NikZ

2014/7/31

#
I believe what is going on in the video is what you're looking for.
Nubbit Nubbit

2014/8/1

#
haha yepp, thats the one, thanks!
You need to login to post a reply.