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

2019/6/6

showText won't disappear

excitedbubbles excitedbubbles

2019/6/6

#
We have code that shows text when you hover over a character and disappears when it's not touching, but if the cursor is still on it while the character is moving, it will stay in place and not disappear. We tried to fix this but haven't gotten very far. Here is our code:
private boolean hovering = false;
    public void HealthCheck()
    {
        List Enemyobjects = getObjectsInRange(100, Enemies.class);
        if (ImageScrollWorld.PlayerPhase == false)
        {
            if (Enemyobjects.size() > 0)
            {
                if (EnemyAtkCounter < 1)
                {
                    if (HP > 0)
                    {
                        HP = HP - (Enemies.ATK - DEF);                           
                        EnemyAtkCounter++;
                        getWorld().showText(HP+"/"+totalHP, getX(), getY()+10);
                    }
                    else if (HP <= 0 && totalHP == 25)
                    {
                        getWorld().showText("", getX(), getY()+10);
                        getWorld().removeObject(this);
                    }
                }
                else
                {
                    EnemyAtkCounter = 0;
                    ImageScrollWorld.PlayerPhase = true;
                }
            }
        }

        if (Greenfoot.mouseMoved(null))
        {  
            if (Greenfoot.mouseMoved(this) && !hovering)
            {
                getWorld().showText(HP + "/" + totalHP, getX(), getY()+10);
                hovering = true;
            }
            if (!Greenfoot.mouseMoved(this) && hovering)
            {
                getWorld().showText("", getX(), getY()+10);
                hovering = false;
            }
        }
    }
Sorry for weird screenshot... Thanks
Super_Hippo Super_Hippo

2019/6/6

#
In what class is this code? If this is in an Actor class which doesn't do anything else than showing these values, you could print the numbers on its image instead of using showText. Then you should be able to control it easier.
excitedbubbles excitedbubbles

2019/6/7

#
The code is in our Allies and Enemies classes, which has more than just showing the text.
Super_Hippo Super_Hippo

2019/6/7

#
You can only remove a showText message if you re-write something at the same position. So if you want to do it with showText, I would suggest to save the position where you write it and then, when removing it, you use those x and y coordinates instead of the current position of the actor.
excitedbubbles excitedbubbles

2019/6/10

#
I'm not sure if we're on the same page here...we tried what you said but it didn't do anything. This only happens if the mouse is hovering over the Actor while it's moving, otherwise we get the desired result.
danpost danpost

2019/6/10

#
Change line 38 to the following:
if (Greenfoot.mouseMoved(null) && !Greenfoot.mouseMoved(this) && hovering)
The addition of this first condition will stop the resetting of hovering as soon as the mouse stops moving.
excitedbubbles excitedbubbles

2019/6/12

#
It still doesn't work, the text behaves the same.
excitedbubbles excitedbubbles

2019/6/13

#
what the hell who are you?????? help us idiot
You need to login to post a reply.