STORY LOOP FURRY PORN GAMES C SERVICES [?] [R] RND POPULAR | Archived flashes: 229494 |
/disc/ · /res/ — /show/ · /fap/ · /gg/ · /swf/ | P0001 · P2575 · P5149 |
This is the info page for Flash #76799 |
Gravity Tutorial |
Creating Gravity in flash games and applications |
Start |
Start |
Credits |
Credits |
Sound Credits Sound design magical accent swell harp twinkle sparkle science fiction 01 Created By: SFX Bible Dark Atmosphere Created By: celso cano www. soundsnap.com |
Welcome to my Gravity Tutorial. In this tutorial im planning to teach you how to create a simple gravity effect. So lets set up for the simple gravity effect. Lets think about gravity in reality. When we drop a pen, what happens? It continues to gain velocity untill it hits the ground. |
Next |
Ok, to start, lets make a simple ball fall to a certain y-position on the screen before the ball stops where we will have a invisible floor. Create a ball object such as this And turn it into a movieClip with an instance name of redBall Then right afterwards we are ready for the script! phew what a effort! |
Now we have the ball ready, open up your actions tab for some coding fun! In the code, we will need to implement some code setting the gravity (the rate the speed will increase as it falls) and the fall velocity. onClipEvent(load) { gravity = 1;//sets the speed the ball will fall at fallVelocity = 0;//sets the starting velocity } onClipEvent(enterFrame) { fallVelocity +=gravity;//increases the rate the ball will fall at this._y +=fallVelocity;//uses the prvious variable to change it accordingly } |
You would of noticed when you played it, the ball didnt stop, but kept on falling forever. We are going to make it so it falls and stops at the bottom of the stage now. Change the code to the following onClipEvent(load) { gravity = 1;//sets the speed the ball will fall at fallVelocity = 0;//sets the starting velocity } onClipEvent(enterFrame) { fallVelocity +=gravity;//increases the rate the ball will fall at this._y +=fallVelocity;//uses the prvious variable to change it accordingly if((this._y+this._height/2) > Stage.height) { this._x=Stage.height - (this._height/2); fallVelocity = 0; } } |
So there you have it! a simple way to implement gravity. Fomr here, you could try to implement this in any number of types of games and software and can easily be modified for all sorts of things. Enjoy! |
ActionScript [AS1/AS2]
Frame 2stop(); if (isNaN(firstload)) { creditOpen = 1; firstload = 9; i = 0; while (i < 500) { prevValue = i - 1; _root["star" + prevValue].duplicateMovieClip("star" + i, this.getNextHighestDepth()); i++; } _root.page = 1; var buttonsnd = new Sound(); var snd = new Sound(); buttonsnd.attachSound("twinkle"); snd.attachSound("Dark_atmosphere"); _root.snd.start(0, 999); }Instance of Symbol 23 MovieClip "star0" in Frame 2onClipEvent (load) { this._x = random(550); this._y = random(400); alphaModifier = -1; maxAlpha = random(100); this._alpha = maxAlpha; } onClipEvent (enterFrame) { this._alpha = this._alpha + alphaModifier; if (this._alpha < 10) { alphaModifier = 1; } if (this._alpha > maxAlpha) { alphaModifier = -1; } }Instance of Symbol 38 MovieClip "creditsList" in Frame 2onClipEvent (enterFrame) { if (_root.creditOpen < 1) { this._x = this._x + 10; if (this._x > (Stage.width / 2)) { this._x = Stage.width / 2; } } }Instance of Symbol 40 MovieClip "redBall" in Frame 2onClipEvent (load) { counter = 48; gravity = 1; fallVelocity = 0; } onClipEvent (enterFrame) { fallVelocity = fallVelocity + gravity; this._y = this._y + fallVelocity; if ((this._y + (this._height / 2)) > Stage.height) { this._y = Stage.height - (this._height / 2); fallVelocity = 0; } if ((this._y + (this._height / 2)) >= Stage.height) { counter--; } if (counter < 1) { counter = 48; this._y = 96; } }Frame 3stop();Frame 4stop();Frame 5stop();Instance of Symbol 40 MovieClip "redBall" in Frame 5onClipEvent (load) { this.gravity = 0.2; this.fallVelocity = 0; } onClipEvent (enterFrame) { this.fallVelocity = this.fallVelocity + this.gravity; this._y = this._y + this.fallVelocity; if (this._y > Stage.height) { this.fallVelocity = 0; this._y = 96; } }Frame 6stop();Instance of Symbol 40 MovieClip "redBall" in Frame 6onClipEvent (load) { counter = 48; gravity = 1; fallVelocity = 0; } onClipEvent (enterFrame) { fallVelocity = fallVelocity + gravity; this._y = this._y + fallVelocity; if ((this._y + (this._height / 2)) > Stage.height) { this._y = Stage.height - (this._height / 2); fallVelocity = 0; } if ((this._y + (this._height / 2)) >= Stage.height) { counter--; } if (counter < 1) { counter = 48; this._y = 96; } }Frame 7stop();Symbol 11 Buttonon (release) { getURL ("http://www.newgrounds.com", "_blank"); }Symbol 20 Buttonon (release) { _root.play(); }Symbol 21 MovieClip Frame 1function timerHandler() { if (!loadingComplete) { var _local2 = _root.getBytesLoaded() / _root.getBytesTotal(); bar._xscale = 100 * _local2; if (_local2 == 1) { loadingComplete = true; if (AUTO_PLAY) { startMovie(); } else { gotoAndStop ("loaded"); } return(undefined); } } } function startMovie() { _root.play(); } _root.stop(); stop(); var AUTO_PLAY = false; var loadingComplete = false; timerHandler();Instance of Symbol 12 MovieClip in Symbol 21 MovieClip Frame 1onClipEvent (enterFrame) { _parent.timerHandler(); }Symbol 21 MovieClip Frame 2stop();Symbol 32 Buttonon (release) { _root.buttonsnd.start(0, 1); play(); _root.creditOpen = 3; _root.page++; }Symbol 36 Buttonon (press) { _root.creditOpen = 0; }Symbol 46 Buttonon (press) { gotoAndStop (4); }Symbol 48 Buttonon (press) { gotoAndStop (5); }Symbol 51 Buttonon (press) { gotoAndStop (6); }Symbol 54 Buttonon (press) { gotoAndStop (7); }Symbol 56 Buttonon (press) { gotoAndStop (2); }
Library Items
Symbol 1 Sound [twinkle] | ||
Symbol 2 Sound [Dark_atmosphere] | ||
Symbol 3 Graphic | Used by:21 | |
Symbol 4 Graphic | Used by:5 | |
Symbol 5 MovieClip | Uses:4 | Used by:21 |
Symbol 6 Graphic | Used by:21 | |
Symbol 7 Graphic | Used by:10 11 | |
Symbol 8 Graphic | Used by:10 11 | |
Symbol 9 Graphic | Used by:10 11 | |
Symbol 10 MovieClip | Uses:7 8 9 | Used by:11 |
Symbol 11 Button | Uses:10 7 8 9 | Used by:21 |
Symbol 12 MovieClip | Used by:21 | |
Symbol 13 Graphic | Used by:21 | |
Symbol 14 Graphic | Used by:20 | |
Symbol 15 Graphic | Used by:20 | |
Symbol 16 Graphic | Used by:20 | |
Symbol 17 Graphic | Used by:20 | |
Symbol 18 Graphic | Used by:20 | |
Symbol 19 Graphic | Used by:20 | |
Symbol 20 Button | Uses:14 15 16 17 18 19 | Used by:21 |
Symbol 21 MovieClip | Uses:3 5 6 11 12 13 20 | Used by:Timeline |
Symbol 22 Graphic | Used by:23 | |
Symbol 23 MovieClip | Uses:22 | Used by:Timeline |
Symbol 24 Font | Used by:25 27 28 30 33 35 37 41 44 47 53 55 57 | |
Symbol 25 Text | Uses:24 | Used by:26 |
Symbol 26 MovieClip | Uses:25 | Used by:Timeline |
Symbol 27 Text | Uses:24 | Used by:Timeline |
Symbol 28 Text | Uses:24 | Used by:29 32 |
Symbol 29 MovieClip | Uses:28 | Used by:32 |
Symbol 30 Text | Uses:24 | Used by:31 32 |
Symbol 31 MovieClip | Uses:30 | Used by:32 |
Symbol 32 Button | Uses:28 29 31 30 | Used by:Timeline |
Symbol 33 Text | Uses:24 | Used by:34 36 |
Symbol 34 MovieClip | Uses:33 | Used by:36 |
Symbol 35 Text | Uses:24 | Used by:36 |
Symbol 36 Button | Uses:33 34 35 | Used by:Timeline |
Symbol 37 Text | Uses:24 | Used by:38 |
Symbol 38 MovieClip | Uses:37 | Used by:Timeline |
Symbol 39 Graphic | Used by:40 | |
Symbol 40 MovieClip | Uses:39 | Used by:Timeline |
Symbol 41 Text | Uses:24 | Used by:Timeline |
Symbol 42 Graphic | Used by:43 | |
Symbol 43 MovieClip | Uses:42 | Used by:Timeline |
Symbol 44 Text | Uses:24 | Used by:45 46 48 51 54 56 |
Symbol 45 MovieClip | Uses:44 | Used by:46 48 51 54 56 |
Symbol 46 Button | Uses:44 45 | Used by:Timeline |
Symbol 47 Text | Uses:24 | Used by:Timeline |
Symbol 48 Button | Uses:44 45 | Used by:Timeline |
Symbol 49 Graphic | Used by:50 | |
Symbol 50 MovieClip | Uses:49 | Used by:Timeline |
Symbol 51 Button | Uses:44 45 | Used by:Timeline |
Symbol 52 Font | Used by:53 55 57 | |
Symbol 53 Text | Uses:24 52 | Used by:Timeline |
Symbol 54 Button | Uses:44 45 | Used by:Timeline |
Symbol 55 Text | Uses:24 52 | Used by:Timeline |
Symbol 56 Button | Uses:44 45 | Used by:Timeline |
Symbol 57 Text | Uses:24 52 | Used by:Timeline |
Instance Names
"star0" | Frame 2 | Symbol 23 MovieClip |
"creditsList" | Frame 2 | Symbol 38 MovieClip |
"redBall" | Frame 2 | Symbol 40 MovieClip |
"redBall" | Frame 5 | Symbol 40 MovieClip |
"redBall" | Frame 6 | Symbol 40 MovieClip |
"bar" | Symbol 21 MovieClip Frame 1 | Symbol 5 MovieClip |
Special Tags
FileAttributes (69) | Timeline Frame 1 | Access local files only, Metadata not present, AS1/AS2. |
ExportAssets (56) | Timeline Frame 1 | Symbol 1 as "twinkle" |
ExportAssets (56) | Timeline Frame 1 | Symbol 2 as "Dark_atmosphere" |
Labels
"loaded" | Symbol 21 MovieClip Frame 2 |
|