This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2008-12-26 00:45:43

bart9032
Scratcher
Registered: 2008-06-16
Posts: 100+

Flash!

I'm making a game on flash (you would be wondering why I have flash pro 8) and I need some help making the code to make it do the following: slide when moving, gravity, cpu   moving and when to do the attacks.
I'm only a beginner at flash, although I got it 4 weeks ago.

Please give the code for it and I can show a picture I made in flash for every code posted.


Hi, my name is Bartholomew JoJo 'Bart' Simpson. Nice to meet you,
Actually, no I am not Bart Simpson. I am bart9032  cool

Offline

 

#2 2009-01-01 20:04:17

terminator355
Scratcher
Registered: 2008-07-31
Posts: 100+

Re: Flash!

moving:

Code:

onClipEvent (load) {
     xSpeed = 0;
     ySpeed = 0;
}
onClipEvent (enterFrame) {
     xSpeed *= 0.8; //change 0.8 to your prefference, higher slower stop lower faster  stop
     ySpeed += 0.8;
     _x += xSpeed;
     _y += ySpeed;
     if (Key.isDown(Key.RIGHT)) {
          xSpeed += 5;
     }
     if (Key.isDown(Key.LEFT)) {
          xSpeed -= 5;
     }
    if (Key.isDown(Key.UP)) {
          ySpeed -= 5;
     }
     if (Key.isDown(Key.DOWN)) {
          ySpeed += 5;
     }
}

Last edited by terminator355 (2009-01-01 20:04:50)


No new stuff for now guys  wink  join me for some Black Ops on xbox: termhn or for some rock band on PS3: rocket232

Offline

 

#3 2009-01-04 21:56:05

fullmoon
Retired Community Moderator
Registered: 2007-06-04
Posts: 1000+

Re: Flash!

Here's how to do key press events (I think)

Code:

keyListener:Object=new Object
keyListener.onKeyDown=function(){
keyPressed=String.fromCharCode(Key.getAscii());
testKey="z"
//the testKey variable is the key that activates a function
if(keyPressed==testKey){
doSomething();
}
}
Key.addEventListener(keyListener)

For keys like the arrows and spacebar, you can ignore the eventListener garbage and simply use:

Code:

if(Key.isDown(Key.SPACE)){
doSomething():
}

Finally, you might consider adding a hidden button that responds to key press events.
Hope this helps!


http://i302.photobucket.com/albums/nn100/fullmoon32/wow.jpg

Offline

 

Board footer