View Full Version : [FMX] Math is Sour
Selky
May 20th, 2005, 12:55 PM
Im working on some simple tests using Math in flash. The first thing I tried was a small marble game where you could click-and-drag, then release, and it would fly off in the opposite direction you dragged going at a certain speed depending on how far you pulled back. Except it didn't work.... It always shoots off in some random direction.... Might anyone have an idea of what my source code should look like? (im using the school comp and dont have the actual source.)
rhamej
May 21st, 2005, 12:09 AM
You may want to post the code to get some help. There are a ton of different ways to do what you want.
So how is Schlitterbahn lately? I just moved from SA :)
Selky
May 23rd, 2005, 01:13 PM
schlitterbahn is choice, but it's constantly overcrowded. I live on the comal river though, so I dont have to worry about it. Anyways, my hardrive just fried at home, so I'm sourceless. But I need to find the complete opposite angle of my mouse to a marble, so when I release, it goes in that direction. Aside from that, everything else works.
stringy
May 23rd, 2005, 03:30 PM
maybe something like this will get you started
marble.onPress = doDrag;
marble.onRelease = noDrag;
function doDrag() {
this.sx = this._x;
this.sy = this._y;
this.startDrag();
}
function noDrag() {
this.ex = this._x;
this.ey = this._y;
this.dx = (this.sx-this.ex)/5;
this.dy = (this.sy-this.ey)/5;
this.onEnterFrame = move;
stopDrag();
}
function move() {
this._x += this.dx;
this._y += this.dy;
this.dx *= .9;
this.dy *= .9;
if (Math.abs(this.dx)<1 && Math.abs(this.dy)<1) {
delete this.onEnterFrame;
}
}
Selky
May 25th, 2005, 12:48 PM
Lemme try and figure out what this does with my somewhat limited understanding of AS. Please clarify if you can.
Sets up the joint
marble.onPress = doDrag;
marble.onRelease = noDrag;
function doDrag() {
This I'm not clear on.... What is .sx and .sy?
this.sx = this._x;
this.sy = this._y;
I was trying to achieve more of a pull back and shoot effect. Like those cyber 9 ball pool games...
this.startDrag();
}
function noDrag() {
I think .ex, .ey, .dx, and .dy have to do with the marbles position on previouse frames?
this.ex = this._x;
this.ey = this._y;
this.dx = (this.sx-this.ex)/5;
this.dy = (this.sy-this.ey)/5;
this.onEnterFrame = move;
stopDrag();
}
function move() {
this._x += this.dx;
this._y += this.dy;
I guess a decay effect...
this.dx *= .9;
this.dy *= .9;
I guess this stops the marble when it slows down to much, but what does "Math.abs" and "delete this.enterFrame" technically do?
if (Math.abs(this.dx)<1 && Math.abs(this.dy)<1) {
delete this.onEnterFrame;
}
}
stringy
May 25th, 2005, 12:58 PM
Lemme try and figure out what this does with my somewhat limited understanding of AS. Please clarify if you can.
Sets up the joint
marble.onPress = doDrag;
marble.onRelease = noDrag;
function doDrag() {
This I'm not clear on.... What is .sx and .sy?
this.sx = this._x;
this.sy = this._y;
I was trying to achieve more of a pull back and shoot effect. Like those cyber 9 ball pool games...
this.startDrag();
}
function noDrag() {
I think .ex, .ey, .dx, and .dy have to do with the marbles position on previouse frames?
this.ex = this._x;
this.ey = this._y;
this.dx = (this.sx-this.ex)/5;
this.dy = (this.sy-this.ey)/5;
this.onEnterFrame = move;
stopDrag();
}
function move() {
this._x += this.dx;
this._y += this.dy;
I guess a decay effect...
this.dx *= .9;
this.dy *= .9;
I guess this stops the marble when it slows down to much, but what does "Math.abs" and "delete this.enterFrame" technically do?
if (Math.abs(this.dx)<1 && Math.abs(this.dy)<1) {
delete this.onEnterFrame;
}
}
sx,sy are the _x,_y of the marble before dragging.
ex,ey - _x,_y after dragging
dx,dy are the amounts it will move each frame so the more you drag it back, the faster it will moveforwards when released.
Math.abs just converts to a positive value as velocity could be negative and hence would always be less than 1
delete this.onEnterFrame just saves a little on cpu
edit/try it with a mc instance name marble.
Selky
May 25th, 2005, 01:01 PM
cool. I love you stringy. Was I about right on everything else though?
stringy
May 25th, 2005, 01:47 PM
cool. I love you stringy. Was I about right on everything else though?
Yes you were.
I think if you want to take your game any furthur you need to look at multiple hitTests and trigonometry- it will get more difficult.
Selky
May 26th, 2005, 12:11 PM
My math teacher said the same thing......... I dont take algebra 2 and precal until next year though.....you wouldn't know somewhere I could get a head start in math by chance, would you?
stringy
May 26th, 2005, 02:55 PM
My math teacher said the same thing......... I dont take algebra 2 and precal until next year though.....you wouldn't know somewhere I could get a head start in math by chance, would you?
You might want to look at Senoculars 3D tutorial, there may be some useful things for you there.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.