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

2014/10/27

to make a transparant graphic

Nirmala Nirmala

2014/10/27

#
hey.. i download this game : http://www.greenfoot.org/scenarios/4027 , and i change the tower graphic by some image that have transparant canvas/ background, but when i play, the background become black. Can some body help me?
Super_Hippo Super_Hippo

2014/10/27

#
You mean the background of the image which should be transparent is black or the background of the world? Is it a PNG image?
Nirmala Nirmala

2014/10/27

#
yes..that's .png image, i mean it should be transparent image not the background of the world
Super_Hippo Super_Hippo

2014/10/27

#
Did you modify the image with a program which doesn't support transparency? For example MS Paint?
danpost danpost

2014/10/27

#
If you are trying to draw a transparent image onto an opaque image (the background of the world, maybe), then the background image will remain opaque. When drawing on a base image, no pixel of the base image will have less transparency than it initially had.
Nirmala Nirmala

2014/10/27

#
no.... i use this image http://i39.servimg.com/u/f39/15/94/16/22/tower-10.png , please help me.. i'm so confused T_T, u can download the game and replace the tower 1 image by that .. and u will understand exactly what i meean >.<
Super_Hippo Super_Hippo

2014/10/27

#
Below the tower, there is an Actor called 'Node' which has a black image when you create the tower. You can't see it in the picture of the other tower because its image is not transparent. As looking over it a bit, the reason for the nodes is the way how the pathfinding works, I think. What you could do is, draw the image of the new tower onto the image of the old one. Then you can keep the background is it was and the black node stays invisible. But, I think you can just comment out the following lines in the Node class. At least I don't see a reason for the black image yet. Maybe it was for testing purposes, I don't know.
1
2
3
4
5
6
7
8
9
public void setAsTower()
{
    gesperrt = true;
    //img.setColor(Color.BLACK);
    //img.fill();
    //setImage(img);
    NodeCost = world.towercost;
    F = direkterWeg + bisherigerWeg + world.towercost;
}
danpost danpost

2014/10/27

#
You may want to replace the commented lines with this line:
1
getImage().clear();
or else because by not setting any image, it gets the default greenfoot image (a little green foot).
Super_Hippo Super_Hippo

2014/10/27

#
I think the Node had some other image before. When the tower is placed, it turns black. (The 'setImage(img)' was quite useless there because the actual image was changed, I think.) But I just deleted the game folder, so I am not 100% sure. At least I didn't see the green foot when testing it out. :)
danpost danpost

2014/10/27

#
The line I gave then can still be used in the method that places the tower.
Nirmala Nirmala

2014/10/27

#
thanks sir.. it worked ^^, but i have another problem sir, i make another world class to make Tittle Screen, here's the code
1
2
3
4
5
6
7
8
9
10
public TScreen()
   {   
       // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
       super(700, 400, 1);
   }
   public void act(){
       if(Greenfoot.isKeyDown("enter"))
       {
           Greenfoot.setWorld(new world());
       }
but after i press "Enter", the start menu didn't appear, i don't know how to fix that T_T
danpost danpost

2014/10/28

#
I added the World subclass TScreen to it as written above and, upon pressing "Enter", it proceeded to a new wor;ld object of type 'world'. I even tried having TScreen extend world (as well as World) and it worked both ways.
Nirmala Nirmala

2014/10/28

#
it doesn't work sir, after pressing "Enter", only the background of world class appear, the GUI didn't appear, and we can only place a tower but the enemy didn't come
danpost danpost

2014/10/28

#
Yes. After adding the 'TScreen' world and having that be the initial world, the 'started' method in the 'world' world is no longer executed (the project is not started with that world being the active world). Just add the line:
1
started();
as the last line in the 'world' class constructor ('public world()').
You need to login to post a reply.