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

2012/3/3

img help

Tomc84 Tomc84

2012/3/3

#
Is it possible to can one objects img from another object when they interact then get rid of it with a counter? I would like to change the hollow to a pow then to nothing, but as it stands my img will change but the wrong object, when I tried to put the same code into the hollow object it would change but not go away and my counter was messed up. import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class YuruichiSit here. * * @author (your name) * @version (a version number or a date) */ public class Yuruichi extends Support { private int hollowKilled; private int imgCounter; public Yuruichi() { hollowKilled = 0; imgCounter = 50; } /** * Act - do whatever the YuruichiSit wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(); fightHollow(); } public void move() { if (Greenfoot.isKeyDown("up")) { setLocation(getX() ,getY() -1); } if (Greenfoot.isKeyDown("down")) { setLocation(getX() ,getY() +1); } if (Greenfoot.isKeyDown("right")) { setLocation(getX() +2,getY() ); setImage("YuruichiRunRight.png"); } if (Greenfoot.isKeyDown("left")) { setLocation(getX() -2,getY() ); setImage("YuruichiRun.png"); } } public void fightHollow() { Actor Hollow = (Hollow) (getOneObjectAtOffset(0, 0, Hollow.class)); if (Hollow != null) { //hollowKilled ++; //setImage("comicpunch.png"); //remove(Hollow.class); if (imgCounter == 0 ) { remove(Hollow.class); setImage("comicpunch.png"); hollowKilled ++; } else { imgCounter --; } } } }
DonaldDuck DonaldDuck

2012/3/4

#
I don't know if I know what you mean but from what I see, you should be calling remove(Hollow) as you already have a reference to a specific object. Also, you can't change your hollow to a pow if you remove the hollow. It looks like you shouldn't remove the hollow, but change to Hollow.setImage("comicpunch.png"); so it changes the image of the object at the offset instead of the image of the current object.
You need to login to post a reply.