View Full Version : code to get whole pixel values
mprzybylski
January 25th, 2005, 03:04 PM
I was wondering what the code to get something to go to a whole pixel value is. I'm using pixel fonts inside of a movieclip and when the movie clip is moved through actionscript and lands in a different spot with easing, the fonts look bad because i suspect that they are no longer on pixel values. any help is greatly appreciated. thanks in advance.
Thinker2501
January 25th, 2005, 03:11 PM
use Math.floor() on the amount you are using to shift the clip forces it to a whole number, rounding down. Math.ceil() rounds up. :beer:
icio
January 25th, 2005, 03:13 PM
well, the function you're looking for is Math.round(), but because the textbox is embeded in a movieclip you can't use it directly. the easiest way here i think it is use a combination of localToGlobal() and globalToLocal(). something like this, maybe:
var point:Object = new Object();
point.x = yourTextBox._x;
point.y = yourTextBox._y;
this.localToGlobal(point);
point.x = Math.round(point.x);
point.y = Math.round(point.y);
this.globalToLocal(point);
yourTextBox._x = point.x;
yourTextBox._y = point.y;you'd probably be able to condense that code - but i've not got flash on this computer atm, so i can't try it.
hope this helps :thumb:
mprzybylski
January 25th, 2005, 03:44 PM
the thing is, i have a long movieclip strip that i'm using easing on, with tons of textboxes in it. to do that for every textbox would be really tedious. the Math.floor didn't work because of what cyberathlete said about it being inside of a movie clip. i went in and set all values of every text box in every movie clip to whole pixel values but it still looks weird. is there something in the easing equation that makes it not proper? this is my easing equation:
on the large movie clip that is being moved at the Y axis:
onClipEvent (load) {
_y = 20;
speed = 3;
}
onClipEvent (enterFrame) {
_y += (targetY -_y )/ speed;
}
and the buttons that move it:
logo_mc.onRelease = function() {
_global.targetY = 20;
};
(that's just an example button, there are others that move it as well)
any ideas?
SmurfMX
January 25th, 2005, 04:00 PM
You could just use int() to chop off the decimals.
icio
January 25th, 2005, 04:30 PM
@ smurfmx - i've never heard of "int()", but that's not to say it doesn't work. the problem with that method is that it will only round the current positions of the movieclip within it's parent - not the global positions, which is what you need to do.
@mprzybylski - put all of the textboxes in a movieclip. put that movieclip into another movieclip that will be moved. then replace mc with the name of the movieclip. make sure the movieclip is originally on whole pixels.
i changed the code a little:
onClipEvent (load) {
_y = 20;
speed = 3;
}
onClipEvent (enterFrame) {
_y += (targetY -_y )/ speed;
var point:Object = new Object();
point.x = 0; //desired x coord for movieclip containing textboxes
point.y = 0; //desired y coord for movieclip containing textboxes
this.localToGlobal(point);
point.x = Math.round(point.x);
point.y = Math.round(point.y);
this.globalToLocal(point);
mc._x = point.x; //where "mc" is the name of the movieclip containing all of the textboxes
mc._y = point.y; //where "mc" is the name of the movieclip containing all of the textboxes
}
think that should work :thumb:
brainy
January 25th, 2005, 04:32 PM
int() is deprecated as of Flash 5. This is probably due to your easing equation, when you divide the difference like that, you'll never actually reach the target. You can do something like this:
onClipEvent (load) {
_y = 20;
speed = 3;
}
onClipEvent (enterFrame) {
var dy=(targetY-_y)/speed;
if (Math.round(dy)==0) _y=targetY;
else _y+=dy;
}
That way it keeps easing untill it's very close to the target, and then it sets the position to the real target.
mprzybylski
January 25th, 2005, 04:59 PM
brainy, that helped a bit but not fully.
cyber, i dont think thats an option at this point really, would have to take out tons of text boxes and re align them.
icio
January 25th, 2005, 05:25 PM
select them all click to select the first one, and then shift+click to select more textboxes. press ctrl+x to cut them, and then ctrl+shift+v to paste-in-place them back into position into a new movieclip.
then use this movieclip as described above.
mprzybylski
January 25th, 2005, 05:46 PM
well the textboxes are all buried inside of diff movieclips all over the stage (the clip is very long and i'd have to move the clip around to even be able to get to it, then copy/paste stuff, then move and back into position, its just not an option unfortunately :\
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.