00:00
00:00
Newgrounds Background Image Theme

Enoughforcast just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Foss: Shake Screen.

3,721 Views | 43 Replies
New Topic Respond to this Topic

Foss: Shake Screen. 2005-10-23 07:09:04


It's not a very long code, although it can be really useful for games, for example ogres walking, rocks falling from the sky, etc...
Just paste this code on the frame you want to be shakey.

var XX:Number = 20; //Feel free to change.
var YY:Number = 20; //Feel free to change.
var startshake:Boolean = false;
var shakeavailable:Boolean = true;
_root.onEnterFrame = function(){
function shakescreen(){
if(shakeavailable){
startshake = true;
X = random(XX) - XX / 2;
Y = random(YY) - YY / 2;
_root._x += X;
_root._y += Y;
}else{

}
}
shakescreen();
}

And this on the frame where you want it to stop shaking.

_root._x = 0;
_root._y = 0;
shakeavailable = false;


BBS Signature

Response to Foss: Shake Screen. 2005-10-23 07:11:10


Sweet, i could probably use that

Response to Foss: Shake Screen. 2005-10-23 07:18:49


Great to see FOSS: Main hasn't died completely.

Response to Foss: Shake Screen. 2005-10-23 07:23:20


Let me tell you a short story.
One day when i was flashing, I bumped into a little problem. So the problem Is. I couldn't get a code for the screen to shake. It was terribly frustrating i spent almost 3 hours fucking up some codes to try and make one. But finaly 'YOU' have brought peace above this land and earth. I beg of you.....to make one which doesn't make the whole thing you've drawn fly of the page >:(


Murad136, heres your fucking credit ;3

BBS Signature

Response to Foss: Shake Screen. 2005-10-23 07:24:13


Heres a code that just makes one MC shake.

onClipEvent (enterFrame) {
function shake(){
shakex=random(20)-10
shakey=random(20)-10
shakex*=0.7
shakey*=0.7
if(shakex<1 && shakey<1){
_parent._x=0
_parent._y=0
}
}
setInterval(shake,100)
_parent._x-=shakex
_parent._y-=shakey

Response to Foss: Shake Screen. 2005-10-23 08:16:42


I believe this is better than Toasts:

function shakeScreen(sLength:Number) {
numVez++;
_root._x = (random(20))-10;
_root._y = (random(20))-10;
if (numVez === sLength) {
clearInterval(ss);
_root._x=0, _root._y=0;
}
}
numVez = 0;
ss = setInterval(shakeScreen, 10, 50);

Change the last number (currently 50) to how long you want the shake to last. Just place the code on the frame where the shaking happens.


Sup, bitches :)

BBS Signature

Response to Foss: Shake Screen. 2005-10-23 08:20:22


no i dont believe its better!!!!!!1111111111 :)

Response to Foss: Shake Screen. 2005-10-23 08:26:07


Bah, I can make a timer too, but I was supposing calculating how much frames you want it to last is more annoying than just putting my code on the last frame.

Toast pwnz j00.


BBS Signature

Response to Foss: Shake Screen. 2005-10-23 08:26:38


At 10/23/05 08:20 AM, Reddz wrote: no i dont believe its better!!!!!!1111111111 :)

11 Lines Vs. 20 Lines, also mine uses setInterval which means it doesn't need to be stopped on another frame.. O_o


Sup, bitches :)

BBS Signature

Response to Foss: Shake Screen. 2005-10-23 08:30:07


But stopping ti on another frame is probably more useful. And any6way, the code cou have been adapted by others.

Well done Toast, I knew it already but this brings enlightenment to some.


I'm back! on a temporary basis. No-one can remember who I am! but I don't really mind.

Response to Foss: Shake Screen. 2005-10-23 08:31:40


At 10/23/05 08:30 AM, Devenger wrote: But stopping ti on another frame is probably more useful.

Not if you're making a game.


Sup, bitches :)

BBS Signature

Response to Foss: Shake Screen. 2005-10-23 08:33:04


At 10/23/05 08:26 AM, -liam- wrote:
At 10/23/05 08:20 AM, Reddz wrote: no i dont believe its better!!!!!!1111111111 :)
11 Lines Vs. 20 Lines, also mine uses setInterval which means it doesn't need to be stopped on another frame.. O_o

Dude, people don't care whether it's 20 lines or 11, I just think putting a code on the frame where it stops is easier than calculating the number of frames you want it to last.

HAHA, 1 LINE: (3 in NG format)

var XX:Number = YY = 20; var shakeavailable:Boolean = true; _root.onEnterFrame = function(){ function shakescreen(){ if(shakeavailable){_root._x += X = random(XX) - XX / 2; _root._y += Y = random(YY) - YY / 2; }}shakescreen();}


BBS Signature

Response to Foss: Shake Screen. 2005-10-23 08:38:24


At 10/23/05 08:33 AM, -Toast- wrote: Stuff

Fair enough, for animating yours may be better but for games mine is more useful.

4 Lines, even after auto-format:

function shakeScreen(sLength:Number) {
numVez++, _root._x=(random(20))-10, _root._y=(random(20))-10;
numVez === sLength ? (clearInterval(ss), _root._x=0, _root._y=0) : 0;
}
numVez=0, ss=setInterval(shakeScreen, 10, 50);

=)


Sup, bitches :)

BBS Signature

Response to Foss: Shake Screen. 2005-10-23 08:41:04


Bah, I guess j00 win, if I added a timer it would take a line or two :(


BBS Signature

Response to Foss: Shake Screen. 2005-10-23 08:41:33


-liam- stop owning him at such a crap subject anyways one of these days we are going to have to let toast think he has the best idea


- Matt, Rustyarcade.com

Response to Foss: Shake Screen. 2005-10-23 08:41:50


What about my code?

onClipEvent(shake my screen dude)
}
PS: (Thanks!)
}

?... Lol, sike, This is really helpful for me though, im glad someone posted this..

Response to Foss: Shake Screen. 2005-10-23 08:58:20


At 10/23/05 08:41 AM, Reddz wrote: What about my code?

not bad! 4 lines! :P

onClipEvent(shake my screen dude)
}
PS: (Thanks!)
}


_root.onEnterFrame = function(){
NP = function(say,noProblem){
trace("Dude, no problem :D");
}
Key.isDown(Key.SPACE) ? NP(21,57): null;
}


Lol, just press space, it works :D


im glad someone posted this..

:D


BBS Signature

Response to Foss: Shake Screen. 2005-10-23 09:04:17


At 10/23/05 08:41 AM, Ninja-Chicken wrote: -liam- stop owning him at such a crap subject

=(

function shakeScreen(sLength:Number) {
numVez++, _root._x=(random(20))-10, _root._y=(random(20))-10, numVez === sLength ? (clearInterval(ss), _root._x=0, _root._y=0) : 0;
}
numVez=0, ss=setInterval(shakeScreen, 10, 50);

Autoformatted = 3 lines =P (Just in case anyone was looking for a shake screen code that was only 3 lines).


Sup, bitches :)

BBS Signature

Response to Foss: Shake Screen. 2005-10-23 11:35:08


How havn't we thought about that before? :D

_root.onEnterFrame = function() { _root._x = _root._y += random(20)-10; }

One pure line.


BBS Signature

Response to Foss: Shake Screen. 2005-10-23 11:37:37


At 10/23/05 09:04 AM, -liam- wrote: Autoformatted = 3 lines =P (Just in case anyone was looking for a shake screen code that was only 3 lines).

I see you cheating with all those commas instead of semi colons heh :D

Response to Foss: Shake Screen. 2005-10-23 11:45:27


At 10/23/05 11:35 AM, -Toast- wrote: _root.onEnterFrame = function() { _root._x = _root._y += random(20)-10; }

Not very useful for games though =P Mines easy to use, just set the interval every time it's needed. Plus that doesn't count as 1 line because it would be 3 after auto formatting.

At 10/23/05 11:37 AM, T-H wrote: I see you cheating with all those commas instead of semi colons heh :D

hehe :)


Sup, bitches :)

BBS Signature

Response to Foss: Shake Screen. 2005-10-23 11:48:19


You are teh c00l Liam

Response to Foss: Shake Screen. 2005-10-23 12:13:56


It CAN be useful for games if you make it a function instead of onEnterFrame.


BBS Signature

Response to Foss: Shake Screen. 2005-10-23 12:14:32


liam i pwn j00 at AS

if (orc.stomping == 1) {
function (orcshake) {
makeScreenShake._x = t3h pwn;
makeScreenShake._y = t3h pwn;
makeScreenShake._z = t3h 3d pwn;
makeScreenShake._unknownVariable = t3h 4th dimension pwn;
screen = pwnage game;
}
}
function (make pwnage game);
function (kill liam and steal his pwnage);
function (take over portal and rule the earth);


No more animated sigs. :(

BBS Signature

Response to Foss: Shake Screen. 2005-10-23 12:17:06


liam would you add this to our game please : ), have it so when you shoot the pistol, has minor shake, shoot the shotgun, large shake, shoot the m4 and its inbetween, but its until you let go of the mouse button so it lasts longer.

i'll come on MSN now.


WEBSITE

BLOG ~ Dont fuck around with my dog. All that I can see I steal. ~

NG FFR ~ Automatic for the people.

BBS Signature

Response to Foss: Shake Screen. 2005-10-23 12:23:03


Mogly, that is a sweet idea

Response to Foss: Shake Screen. 2005-10-26 08:09:33


At 10/23/05 12:17 PM, -Mogly- wrote: liam would you add this to our game please : ), have it so when you shoot the pistol, has minor shake, shoot the shotgun, large shake, shoot the m4 and its inbetween, but its until you let go of the mouse button so it lasts longer.

i'll come on MSN now.

Lol, I actually made this FOSS for a game i am working on - when the huge beats walk they make the screen shake.


BBS Signature

Response to Foss: Shake Screen. 2005-10-26 08:11:26


Or, for it on a MC you can use;


onClipEvent (enterFrame) {
function shake(){
shakex=random(20)-10
shakey=random(20)-10
shakex*=0.7
shakey*=0.7
if(shakex<1 && shakey<1){
_parent._x=0
_parent._y=0
}
}
setInterval(shake,100)
_parent._x-=shakex
_parent._y-=shakey
}

From 'ere


"Actually, the server timed out trying to remove all your posts..."

-TomFulp

Response to Foss: Shake Screen. 2005-10-26 08:14:13


Bufu already posted this.


BBS Signature

Response to Foss: Shake Screen. 2005-10-26 08:15:20


At 10/26/05 08:14 AM, -Toast- wrote: Bufu already posted this.

Whoops! I meant kipling, sorry :P


BBS Signature