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

2017/2/9

Scoreboard doesn't work

Marrryanx Marrryanx

2017/2/9

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.Color;
/**
 * Write a description of class Scor here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Scor extends raspunsuri
{
    private int puncte = 1;
    /**
     * Act - do whatever the Scor wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public Scor() 
    {
        setImage(new GreenfootImage("Punctaj : " + puncte, 24, Color.GREEN, Color.BLACK));
    } 

    public void act() 
    {
        addPuncte();
    } 
    
    public void addPuncte()
    { 
        if(Greenfoot.mouseClicked(t2i1a.class))
        {
            puncte ++;
            setImage(new GreenfootImage("Punctaj : "+ puncte, 24, Color.RED, Color.GREEN));
        }
    }
}
scoreboard after click on t2i1a and scoreboard beforeclick on t2i1a (the same)
Super_Hippo Super_Hippo

2017/2/9

#
You can use an Actor, a World or null as a parameter for mouseClicked. Not a class.
Marrryanx Marrryanx

2017/2/10

#
Super_Hippo wrote...
You can use an Actor, a World or null as a parameter for mouseClicked. Not a class.
I don't understand.
danpost danpost

2017/2/10

#
You cannot use 'mouseClicked(Actor.class)', 'mouseClicked(World.class)' or 'mouseClicked(<<ANY>>.class)'. The parameter must be some specific visible object that can be clicked on -- a World object (or instance of World) or an Actor object (or instance of Actor). You could use 'null' to see if any click was made; then determine if it was clicked on an Actor object and then determine if that Actor object was of type 't2i1a':
if (Greenfoot.mouseClicked(null))
{
    Actor clicked = Greenfoot.getMouseInfo().getActor();
    if (clicked != null && clicked instanceof t2i1a)
    {
        // etc.
You need to login to post a reply.