-
[RESOLVED] help with this random position
Good morning,
and thanks ahead probably FruitBeard,
I can't see why this randomness won't place the clip on the right side of the screen. It positions the first one anywhere but form the second time onward it mostly positions the clip on the left side of the screen. Is this right?
Code:
var indyX:Number = Math.floor(Math.random() * Stage.width);
var indyY:Number = Math.floor(Math.random() * Stage.height);
function attachClips():Void{
attachMovie("independencia_mc","independencia",this.getNextHighestDepth());
independencia._x = indyX;
independencia._y = indyY;
}
attachClips();
I have tried to hardcode the values instead of Stage but the result keeps being the same. I have even tried deleting the indyX or indyY values before jumping back to the maintimeline and running it again, but it hardly moves from the left side. I suppose I have to subtract about 200 or 300 pixel values so the text doesn't go offscreen but I'm quite confused with this.
Attachment 74857
-
.
Hi Cap,
use this on the first frame for a better trace etc and go from there.
PHP Code:
function attachClips():Void
{
var indyX:Number = Math.floor(Math.random() * Stage.width);
var indyY:Number = Math.floor(Math.random() * Stage.height);
attachMovie("independencia_mc","independencia",this.getNextHighestDepth());
independencia._x = indyX;
independencia._y = indyY;
trace("independencia._x = " + independencia._x);
trace("independencia._y = " + independencia._y);
}
attachClips();
Sometime it appears off the stage due to the huge space it has to randomise in.
Inside of your independencia clip, you should perhaps use this instead of the longer arrays, like so, you don't have to though
PHP Code:
var aBoldness:Array = ["true", "false"];
var aItalic:Array = ["true", "false"];
tFormatter.bold = aBoldness[Math.floor(Math.random() * aBoldness.length)];
tFormatter.italic = aItalic[Math.floor(Math.random() * aItalic.length)];
-
Hi, Fruit,
thanks for replying so quick.
I just tried that out and I believe there must be something wrong somewhere. Sometimes it traces far over 1000 pixels width and you see the text and other times it traces out less than that with an average _y and you can't see it.
this trace for example:
Attachment 74859
-
Hi again, Fruit,
just thought the previous picture might not be very clear. This is the last trace in this one...
_X:1075
_y:200
hate to have you thinking on this. Forget about it if you haven't got the time. I still need to keep working on understanding about the font embedding, so I have plenty of time...
Attachment 74861
-
.
Hi Cap,
You are not remove the independencia movieclip, try using
PHP Code:
removeMovieClip(independencia);
attachMovie("independencia_mc","independencia",this.getNextHighestDepth());
I thin you will find that it works
-
Thanks, Fruit,
still seems strange to me. My project is 1366 width, 688 height and look at this trace:
it's 361 and 411. The text is almost in the middle of the stage. It should be quite further to the left side even if the text size has to do with the positioning, shouldn't it?
Attachment 74863
-
.
Hi Cap
Remember the text is centre aligning so the registration point will be in the centre of the text, so half way point,
and then you have the rotation too.
use this inside indepencia clip along with the other code
PHP Code:
var ind:TextField = this.createTextField("ind", this.getNextHighestDepth(), 0, 0, 10, 70); ind.autoSize = "center";
what I did was make a small circle on the stage (main stage, not independencia clip stage), make it into a movieclip and call it "ball"
first frame code I used this for testing, you can remove what you don't need after, you will see that the ball is central to the text everytime.
PHP Code:
var indyX:Number; var indyY:Number;
function attachClips():Void { indyX = Math.floor(Math.random() * Stage.width); indyY = Math.floor(Math.random() * Stage.height); ball._x = indyX ball._y = indyY removeMovieClip(independencia); attachMovie("independencia_mc","independencia",this.getNextHighestDepth()); independencia._x = indyX; independencia._y = indyY; trace(ball._x); trace(ball._y); }
attachClips();
Last edited by fruitbeard; 04-10-2014 at 09:11 AM.
-
Thanks, Fruit,
great !
It's hard to find out a average Stage size where to fit the text.
thanks, seems to work perfectly. See you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|