exotichilt.blogg.se

Greenfoot sound
Greenfoot sound









If (speed = turbo1 & turbo.isPlaying()) turbo.stop() If (speed = drive1 & drive.isPlaying()) drive.stop() If (speed = idle1 & idle.isPlaying()) idle.stop() If (Greenfoot.isKeyDown("backspace")) change1 = turbo1 If (Greenfoot.isKeyDown("5")) change1 = reverse1 If (Greenfoot.isKeyDown("8")) change1 = drive1 Turn(change) //turn(amount) is basically setRotation(getRotation()+amount) GreenfootSound drive = new GreenfootSound("drive.wav") Public class Køremand extends SmoothMover Also, using 'turn' instead of 'setRotation' seemed appropriate. Just needed to move the 'change' and 'change1' fields to inside the method as variables and use them to control the behavior. }Because we are not changing any values outside the method, the 'isKeyDown' method will work ok. If (Greenfoot.isKeyDown("backspace")) change1 = speed If (Greenfoot.isKeyDown("5")) change1 = -1

greenfoot sound

If (Greenfoot.isKeyDown("8")) change1 = kør Therefore, if you need to check for more than one value for that key, you need to hold that returned key in a local String variable. Keep in mind that once a key is returned using 'getKey', the internal keyboard buffer pointer is advanced to the next position and that last keystroke cannot be recalled by calling 'getKey' again. In order to catch a key-up event, you need to continually check for it by way of the act method or a method the act method calls. As a single check for a key-up event, it would be virtually impossible to have a value other than 'null' set there. Finally, line 19 will always (as far as I know) set 'key' to 'null'. Also, the 'change' field should be reset to zero at the beginning of the method (actually, it should be a variable that is local to the method instead of an instance field). Either way, you need more limitation of the value of the 'change1' field if only the four values are valid. You either need to change the method you are using from 'isKeyDown' to 'getKey' or put a timer control on the actions performs by the key conditions. The value of 'change' and 'change1' will probably be changing about 3 to 5 times for very quick keystrokes and a multitude of times if the key is pressed casually. First, when using 'isKeyDown' without any type of control, it is difficult to have a changing value stop at a particular number. I think there are a couple of inherent problems here. If(Greenfoot.isKeyDown("backspace")) change1=change1+speed If (Greenfoot.isKeyDown("8")) change1=change1+kør * the 'Act' or 'Run' button gets pressed in the environment. * Act - do whatever the Skydemand wants to do. String key = Greenfoot.getKey() // saves the key returned

greenfoot sound

GreenfootSound reverse = new GreenfootSound("reverse.wav") GreenfootSound idle = new GreenfootSound("idle.wav")

greenfoot sound

GreenfootSound turbo = new GreenfootSound("turbo.wav") GreenfootSound driving = new GreenfootSound("drive.wav") Public class nyKøremand extends SmoothMover * Write a description of class Skydemand here. Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)











Greenfoot sound