PDA

View Full Version : Help with Math.Round



wyclef
July 15th, 2003, 09:08 AM
Hello :elderly:

I'm running into some problems with math.round not working how I'd like it to work. I'm using a pixel font, and if the text does not land on a whole pixel, it becomes blurry. I suspect it might be an easy fixed to the trained eye so I've posted the script. Thanks! ;)

function setDragMask() {

ts.dragger.onPress = function() {
this.released = false;
startDrag(this, false, this._x, 0, this._x, ts.theMask._height-this._height);
// The scrolling animation
ts.theText.onEnterFrame = function() {
trace("enterframe");

scrollAmount = (this._height - (ts.theMask._height/1.3))/(ts.theMask._height - ts.dragger._height);

ts.dragger._height = 30;
// Set a new target y position
targY = -ts.dragger._y*scrollAmount;

Math.round()(this._y -= Math.round((this._y-targY)/5));
this._y -= (this._y-targY)/5;
trace(Math.abs(this._y)+' = '+Math.abs(targY));
trace(Math.abs(this._y)+'<='+Math.abs(targY+1)+'&&'+Math.abs(this._y)+'>='+Math.abs(targY-1));
if ( (Math.abs(this._y)<=Math.abs(targY)+1)&&(Math.abs(this._y)>=Math.abs(targY)-1)) {
trace('inside');
if(ts.dragger.released == true) {
trace('delete');
delete this.onEnterFrame;
}
}
}
}

thoriphes
July 15th, 2003, 09:25 AM
this._y -= Math.round((this._y-targY)/5);
this._y = Math.round(this._y)

pom
July 15th, 2003, 09:26 AM
Math.round()(this._y -= Math.round((this._y-targY)/5));doesn't mean anything. It should be
Math.round( whatYouWantToround ) ;

wyclef
July 15th, 2003, 09:33 AM
Does this look better? I tried it and it seems to work, but the scrolling isn't as smooth any more. I'm wondering if that's just the compromise for forcing it on a whole pixel?


// --------------------------------------------------------------------------------------
function setDragMask() {

ts.dragger.onPress = function() {
this.released = false;
startDrag(this, false, this._x, 0, this._x, ts.theMask._height-this._height);
// The scrolling animation
ts.theText.onEnterFrame = function() {
trace("enterframe");

scrollAmount = (this._height - (ts.theMask._height/1.3))/(ts.theMask._height - ts.dragger._height);
// Adjust the height of the dragger to reflect the amount of content available to see
ts.dragger._height = 30;
// Set a new target y position
targY = -ts.dragger._y*scrollAmount;

Math.round(this._y -= Math.round((this._y-targY)/5));
this._y -= Math.round((this._y-targY)/5);
this._y = Math.round(this._y)

trace(Math.abs(this._y)+' = '+Math.abs(targY));
trace(Math.abs(this._y)+'<='+Math.abs(targY+1)+'&&'+Math.abs(this._y)+'>='+Math.abs(targY-1));
if ( (Math.abs(this._y)<=Math.abs(targY)+1)&&(Math.abs(this._y)>=Math.abs(targY)-1)) {
trace('inside');
if(ts.dragger.released == true) {
trace('delete');
delete this.onEnterFrame;
}
}
}
}

thoriphes
July 15th, 2003, 09:51 AM
Math.round returns a value. simply doing Math.round by itself is pointless if it's not passed to a variable.

Math.round(this._y -= Math.round((this._y-targY)/5));makes no difference from
this._y -= Math.round((this._y-targY)/5);

wyclef
July 15th, 2003, 09:55 AM
That makes sense, because it makes no difference if I take Math.round out of that line and run the script. So what do you think would make this thing not blurry font? :toad:

wyclef
July 15th, 2003, 11:06 AM
How does this look?



ts.dragger.onPress = function() {
this.released = false;
startDrag(this, false, this._x, 0, this._x, ts.theMask._height-this._height);
// The scrolling animation
ts.theText.y = ts.theText._y; // <<---------------new
ts.theText.onEnterFrame = function() {
trace("enterframe");
scrollAmount = (this._height - (ts.theMask._height/1.3))/(ts.theMask._height - ts.dragger._height);
// Adjust the height of the dragger to reflect the amount of content available to see
ts.dragger._height = 30;
// Set a new target y position
targY = -ts.dragger._y*scrollAmount;
this.y -= (this.y-targY)/5; // <<---------------new

this._y = Math.round(this.y); // <<---------------new
//
trace(Math.abs(this._y)+' = '+Math.abs(targY));
trace(Math.abs(this._y)+'<='+Math.abs(targY+1)+'&&'+Math.abs(this._y)+'>='+Math.abs(targY-1));
if ( (Math.abs(this._y)<=Math.abs(targY)+1)&&(Math.abs(this._y)>=Math.abs(targY)-1)) {
trace('inside');
if(ts.dragger.released == true) {
trace('delete');
delete this.onEnterFrame;
}
}
}
}

thoriphes
July 15th, 2003, 11:07 AM
I think you mean:
this._y = Math.round(this._y);;)

wyclef
July 16th, 2003, 12:18 AM
I'm not sure.....:moustache