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

2013/5/26

How can I do it...

Miikku Miikku

2013/5/26

#
How can I do Speed up button what increase my character speed?
Miikku Miikku

2013/5/27

#
Helps?
Miikku Miikku

2013/5/27

#
I mean something like this to my character class...
if (Greenfoot.mouseClicked("SpeedUp.class")
{
      //soldier speed up...
      move(5);
}
danpost danpost

2013/5/27

#
Well, you cannot use a String for the 'mouseClicked' method; it must either be a reference to an object or 'null'. It should be some type of reference to the button object that is used to speed up the soldier (whether you use 'this' in the button 'act' method, 'getObjects(Button.class).get(0)' on the world object, or a pre-defined field holding a reference to the Button object -- 'speedButton'). There are other alternatives to these, but hopefully, that should be enough to get you going for now.
Miikku Miikku

2013/5/27

#
So what I put to soldier class?
Miikku Miikku

2013/5/27

#
Helps??
Kartoffelbrot Kartoffelbrot

2013/5/27

#
int speed = 0;

public void act()
{
//this means this object -> the soldier you play
if(Greenfoot.mouseClicked(this))
{
move(speed);
}
//this is only an EXAMPLE:
if(Greenfoot.isKeyDown("a"))
{
speed--;
//whenever the speed should be lower or higher you. Only write speed++; or speed--; .
}
}
If this code shouldn't be in the soldier class, say it.
You need to login to post a reply.