Forum Topic: Gravity in adobe flash

(85 views • 4 replies)

This topic is 1 page long.

<< < > >>
Shouting

CyberFox01

Reply To Post Reply & Quote

Posted at: 11/5/09 11:12 AM

CyberFox01 NEUTRAL LEVEL 01

Sign-Up: 11/05/09

Posts: 5

Ok first of all, don't flame for not using 5 hours rummaging topic which could hold the answer.

on to topic

i have a VERY simple flash game i trying to add gravity to.

"
onClipEvent (enterFrame)
{
var speed:Number = 3;
var gravity1:Number = 0;
var gravity2:Number = 2;
}

onClipEvent (enterFrame) // Center Pos (266.7 ,190.9)
{
gravity1 = gravity1 + gravity2;
this._y = this._y + gravity1;

if (Key.isDown(38))
{
this._y = this._y - speed;
}
if (Key.isDown(40))
{
this._y = this._y + speed;
}
if (Key.isDown(37))
{
this._x = this._x - speed;
}
if (Key.isDown(39))
{
this._x = this._x + speed;
}
}
"

this code is in in a movie clip object

the problem with it is that it doesent change the variables.
like: "gravity1 = gravity1 + gravity2;" would add 2 for each frame 2 ,4 ,6 ,8....
but it does not, it stays at 2.

some1 enlighten me?

(Sorry if i posted in the wrong section)


None

Toast

Reply To Post Reply & Quote

Posted at: 11/5/09 11:24 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,925

the enterFrame event means the actions will be executed every 1/fps seconds. You're telling flash every frame that gravity 1 = 0, and then you're telling it that gravity1 = 0 + gravity2, so gravity1 will always be equal to gravity2. You need to have your first statements in a load event (eg onClipEvent(load){) instead of enterframe. That will tell flash that gravity1 is equal to 0 when the frame is loaded, but won't set it back to 0 again on the next frame.

pseudocode
on load:
gravity1 = 0;
gravity2 = 2;

on enterFrame:
gravity1 += gravity2;


None

DashDingo

Reply To Post Reply & Quote

Posted at: 11/5/09 11:31 AM

DashDingo EVIL LEVEL 15

Sign-Up: 06/25/04

Posts: 5,163

At 11/5/09 11:24 AM, Toast wrote: stuff

Yeah, he's got the right idea. You set gravity1 to 0 every frame, which obviously is causing the trouble. Change:

onClipEvent (enterFrame){
var speed:Number = 3;
var gravity1:Number = 0;
var gravity2:Number = 2;
}

to:

onClipEvent (Load){
var speed:Number = 3;
var gravity1:Number = 0;
var gravity2:Number = 2;
}

If Load doesn't work, it may be onLoad, I'm not sure.

BBS Signature

None

Toast

Reply To Post Reply & Quote

Posted at: 11/5/09 11:43 AM

Toast DARK LEVEL 09

Sign-Up: 04/02/05

Posts: 8,925

Actually I'm pretty sure load isn't in uppercase. onClipEvent(load), not onClipEvent(Load)

the latter will not work


None

CyberFox01

Reply To Post Reply & Quote

Posted at: 11/5/09 11:44 AM

CyberFox01 NEUTRAL LEVEL 01

Sign-Up: 11/05/09

Posts: 5

At 11/5/09 11:31 AM, DashDingo wrote:
At 11/5/09 11:24 AM, Toast wrote: stuff
Yeah, he's got the right idea. You set gravity1 to 0 every frame, which obviously is causing the trouble. Change:

onClipEvent (enterFrame){
var speed:Number = 3;
var gravity1:Number = 0;
var gravity2:Number = 2;
}

to:

onClipEvent (Load){
var speed:Number = 3;
var gravity1:Number = 0;
var gravity2:Number = 2;
}

If Load doesn't work, it may be onLoad, I'm not sure.

how stupid of me. ad that has been buggin me for 3 hours now ^^

anyways thanks a lot.


All times are Eastern Standard Time (GMT -5) | Current Time: 11:13 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!