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

2017/6/11

Clicking

Venbha Venbha

2017/6/11

#
wait i was thinking,.. how to make clicking movement? like i am making a piano game in which when you click run and click on the keys, they make a sound. but the the thing is, what is the code for clicking ??
Super_Hippo Super_Hippo

2017/6/11

#
//in the Key class
public void act()
{
    if (Greenfoot.mousePressed(this))
    {
        //play some sound
    }
}
//Alternatively, in your world
private Key key = new Key();

//...
addObject(key, 50, 50);

//...
public void act()
{
    if (Greenfoot.mousePressed(key))
    {
        //play some sound
    }
}
Take that as an example. If you do it in your world, you will most likely have an array of keys and not just one key.
Venbha Venbha

2017/6/13

#
Super_Hippo wrote...
//in the Key class
public void act()
{
    if (Greenfoot.mousePressed(this))
    {
        //play some sound
    }
}
//Alternatively, in your world
private Key key = new Key();

//...
addObject(key, 50, 50);

//...
public void act()
{
    if (Greenfoot.mousePressed(key))
    {
        //play some sound
    }
}
Take that as an example. If you do it in your world, you will most likely have an array of keys and not just one key.

Thankyou i will try that

Venbha Venbha

2017/6/14

#
Venbha wrote...
Super_Hippo wrote...
//in the Key class
public void act()
{
    if (Greenfoot.mousePressed(this))
    {
        //play some sound
    }
}
//Alternatively, in your world
private Key key = new Key();

//...
addObject(key, 50, 50);

//...
public void act()
{
    if (Greenfoot.mousePressed(key))
    {
        //play some sound
    }
}
Take that as an example. If you do it in your world, you will most likely have an array of keys and not just one key.

Thankyou i will try that

IT WORKS!!!
You need to login to post a reply.