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

2013/1/18

Sprites Movements !!! NEED HELP IMMEDIATELY PLEASE :(

SpritesKing SpritesKing

2013/1/18

#
uhhh ok here goes.. im here trying to animate sprites and all seems to be working but now im just trying to do when i hit "space" i can animate all attack sprites instead of holding it. and if i hold it the attack will just keep coming and stops whenever you stop holding space. i need lots of help !
danpost danpost

2013/1/18

#
You are probably using the 'isKeyDown' method instead of the 'getKey' method. As long as the key is down, the method will be run repeatedly with 'isKeyDown' because many cycles pass between the time the key is pressed and the time it is released. The 'getKey' method will return a value at the moment a key that is pressed is released. There are two ways to deal with the issue. (1) add a boolean field to the class called 'spaceDown' and when 'isKeyDown' becomes true while 'spaceDown' is false, set 'spaceDown' to true and run the animation; when the 'isKeyDown' becomes false while 'spaceDown' is true, set 'spaceDown' back to false.
// add instance field
private boolean spaceDown;
// is act or method it calls
if(!spaceDown && Greenfoot.isKeyDown("space"))
{
    spaceDown=true;
    animate();
}
if(spaceDown && !Greenfoot.isKeyDown("space")) spaceDown=false;
or (2) use 'getKey()'. First be aware that once a keystroke is returned with this method, that keystroke cannot be retrieved by way of the method again. Therefore, it is best to set a local field to the value returned.
String key=Greenfoot.getKey();
if("space".equals(key)) animate();
The code is simple, however, has drawbacks; first, if you are checking for keys using 'getKey' elsewhere, it may not run right; and, the action will always occur when the key is released instead of when the key is pressed which would usually give a better 'feel' to the game.
SpritesKing SpritesKing

2013/1/18

#
i am actually using the .equals method. and i just posted my scenario ! :) with codes i think i have problems with my animation codes do you mind checking that out? !? thanks you sooo much for your time
danpost danpost

2013/1/18

#
Actually, the animation looks pretty good. The only improvement might be to not have zelda looking right immediately after stopping while going left. Easy fix: in the 'nomal' class code, in the 'if' block that checks that none of the five keys are pressed, after setting the image (line 75), add the following line:
if(dir == -1) mirror();
If you believe that it is not quite what you want, explain clearly and I will try to help. Same with any other issues you may have. BTW, good job so far; and the music goes well with it.
SpritesKing SpritesKing

2013/1/18

#
now im trying to run the whole attack with just one hit of "space" and i dont have the skills for it .... as you can see , i am now currently trying to add score and fix the attacks. and after a certain score new enimies will spawn and starts to attack.
SpritesKing SpritesKing

2013/1/18

#
btw i already fixed that problem thanks :)
You need to login to post a reply.