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

2013/4/8

image help

GrimCreeper312 GrimCreeper312

2013/4/8

#
i have images that have transparent background so when they get shot the bullet hits an invisible part and disappears how would i fix this so that when the bullet hits the actual image i then disappears
JetLennit JetLennit

2013/4/8

#
You could try editing the photo to decrease the extra
GrimCreeper312 GrimCreeper312

2013/4/8

#
i have to the best that i could with photoshop
danpost danpost

2013/4/8

#
You could get the color of the image at the location the head of the bullet was at. If it is not transparent, then apply damage.
GrimCreeper312 GrimCreeper312

2013/4/8

#
how would that work with say a class called boss
danpost danpost

2013/4/8

#
Need to know the name of the bullet class and which class the detection code should be in.
GrimCreeper312 GrimCreeper312

2013/4/8

#
CaB() is the bullet & CaLa() is another bullet that needs to work if the detection code is supposed to be in the object being shot then its Boss()
danpost danpost

2013/4/8

#
It might be easiest to do this from the bullet classes (but can be accomplished from the Boss class, also). The idea is to first get the location of the point that the head of the bullet is at. This can be done simply by moving the bullet half of its length, recording the location and moving the bullet back.
move(getImage().getWidth()/2);
int headX = getX(), headY = getY();
move(-getImage().getWidth()/2);
Now, we need the location of the top-left corner of the image of the boss.
if (!getIntersectingObjects(Boss.class).isEmpty())
{
    Boss boss = (Boss)getOneIntersectingObject(Boss.class);
    int homeX = boss.getX()-boss.getImage().getWidth()/2;
    int homeY = boss.getY()-boss.getImage().getHeight()/2;
    // put previous code here
Finally the difference in the coordinates is the offset of the point in the image to test:
    // previous code here
    int imageX = headX-homeX;
    int imageY = headY-homeY;
    Color color = boss.getImage().getColorAt(imageX, imageY);
    if (color.getAlpha()>48) // code to apply damage
GrimCreeper312 GrimCreeper312

2013/4/9

#
so would it look like this and does it go in the checkCollision() method
if (!getIntersectingObjects(Boss.class).isEmpty())  
{  
    Boss boss = (Boss)getOneIntersectingObject(Boss.class);  
    int homeX = boss.getX()-boss.getImage().getWidth()/2;  
    int homeY = boss.getY()-boss.getImage().getHeight()/2; 
    move(getImage().getWidth()/2);  
    int headX = getX(), headY = getY();  
    move(-getImage().getWidth()/2); 
    int imageX = headX-homeX;  
    int imageY = headY-homeY;  
    Color color = boss.getImage().getColorAt(imageX, imageY);  
    if (color.getAlpha()>48) { Boss.life--; }
danpost danpost

2013/4/9

#
You may want to remove the bullet along with 'Boss.life--;'.
You need to login to post a reply.