PDA

Click to See Complete Forum and Search --> : dynamic text and speed



bwong
07-01-2002, 05:48 PM
I have an object that I move with the arrow keys. If you open up movement-thrust.fla example in program files\macromedia\flash mx\samples\fla you will see what I am working with. If you replace the current action script for the bug with this:


onClipEvent (load) {
// declare and set initial variables
thrust = 1;
decay = 1;
maxSpeed = 5;
xthrust = 1;
flames._visible = 0;
ySpeed = -1;
xSpeed = -1;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
//Move right
xSpeed += xthrust;
flames._visible = 0;
}
if (Key.isDown(Key.LEFT)) {
// move left
xSpeed -= xthrust;
flames._visible = 0;
}
//
if (Key.isDown(Key.UP)) {
//move up
ySpeed += thrust;
}
if (Key.isDown(Key.DOWN)) {
//move down
ySpeed -= thrust;
}
// maintain speed limit
speed = Math.sqrt((xSpeed*xSpeed)+(ySpeed*ySpeed));
if (speed>maxSpeed) {
xSpeed *= maxSpeed/speed;
ySpeed *= maxSpeed/speed;
}
//
// move beetle based on calculations above
_y -= ySpeed;
_x += xSpeed;
//
// Keep the bug from moving off screen.
if (_y<0) {
_y = 0;
}
if (_y>232) {
_y = 232;
}
if (_x<0) {
_x = 0;
}
if (_x>465) {
_x = 465;
}
}


You will see what I am working with.

Eventually I want to apply this script to the hot air balloon in this picture:

http://board.flashkit.com/board/images/ieimages/2002/06/1.gif

My problem is that I would like to somehow output a correlation between the xSpeed, ySpeed, and the various forces. I would like to do this using dynamic text. For example, when the ySpeed=2, I would like the gravity to be 20,000 and the air pressure to be 40,000.

Does anyone have any ideas on how I can do this?

Thanks.
Brian

muckyMuckMan
07-07-2002, 04:52 PM
You could just assign variables to dynamic text fields.

Try this:


// Create some text fields to display your variables
_root.createTextField("tfGravity", 1, 10, 10, 40, 20);
tfGravity.autoSize = true;
tfGravity.variable = "gravity";
_root.createTextField("tfAirPressure", 2, 10, 30, 40, 20);
tfAirPressure.autoSize = true;
tfAirPressure.variable = "airPressure";

// You can put this pretty much anywhere
// Also, I don't know what kind of calculations you're doing, so I
// just put these types of calculations in.
gravity = ySpeed*10000;
airPressure = 2*gravity;

I hope this helps.

L8r.