View Full Version : [AS2] "pressure sensitive" jumps?
ThePersonWhoKnew
07-15-2009, 08:13 PM
Well I'm making a game and I'm wondering if theres a possible way in flash AS2 that you could make jumps pressure sensitive. for example like when you tap the jump button rly quick instead of the jump being the same, it's shorter. like the longer you hold the higher the jump. (like super mario bros and other games like that) well here's my code. Is there anything that could be altered to make it like that? well here is the code:
onClipEvent(load){
gravity = 0.01;
jump = -15;
}
onClipEvent(enterFrame){
this.gravity++;
_y += this.gravity;
while (_root.ground.hitTest(_x, _y, true)){
_y--;
gravity = 0;
}
if(Key.isDown(Key.UP) && _root.ground.hitTest(_x, _y+1, true)){
this.gravity += jump;
}
}
VexForge
07-15-2009, 09:00 PM
Hi! I wrote this little script. It plusses to the 'pressure' variable 0.1 (10 times a second)... This is purely as a test. How much that fits to add is up to you, or how often for that matter. Where it clears the interval is where you put your jump code and multiply 'jump' with 'pressure' ... Atleast that's the idea :) ...or you could make an if statement saying that if 'pressure' is higher than 1.0, then jump high, if not, jump low :)
var pressure:Number = 0;
var keyListener:Object = new Object();
keyListener.onKeyDown = function(){
if(Key.isDown(Key.UP)){
addPressureInterval = setInterval(addPressure,100);
}
}
keyListener.onKeyUp = function(){
if(Key.getCode() == Key.UP){
trace("JUMP");
}
}
Key.addListener(keyListener);
function addPressure(){
if(Key.isDown(Key.UP)){
pressure += 0.1;
trace(pressure);
} else {
addPressureInterval.clearInterval();
pressure = 0;
}
}
ThePersonWhoKnew
07-15-2009, 10:57 PM
Wow seems kind of confusing but I get the idea! :D well it was a little glitchy, but You helped me and I think I can get it to work soon. Thanks tho! :D
VexForge
07-15-2009, 11:02 PM
Great you liked it :) Yeah, I noticed it's a little glitchy, but nothing that can't be worked out. Good luck :)
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.