random help

Subscribe to random help 9 posts

avatar for phore_eyes phore_eyes 427 posts
Flag Post

how would i make it so that a movieclip randomly appers on the screen and stays there???

 
avatar for dx0ne dx0ne 100 posts
Flag Post

var t:MovieClip;

n = _root.getNextHighestDepth();

t = attachMovie(“foo”,"foo"+n,n);

t._x = Math.random() * Stage.width;

t._y = Math.random() * Stage.height;

where foo is linkage name for movieclip in library

 
avatar for WMDs WMDs 8 posts
Flag Post

Aarhhh thanks :D

(Was looking for that!)

 
avatar for phore_eyes phore_eyes 427 posts
Flag Post

also how would i make it so that like in ragdoll avalanch things fall randomly from the cieling

 
avatar for Phoenix00017 Phoenix00017 7375 posts
Flag Post

Well, dx’s code shows you how to pick a random start position. Just make the ._y value above the stage. Then you need some sort of motion function that changes the _y positions of each movie clip by whatever speed you’ve assigned to it (probably want those to be bounded random numbers as well). There are lots of tuts out there for making things move on screen.

 
avatar for Cloud_9ine Cloud_9ine 2448 posts
Flag Post

use a code like a movement code but have it so it goes down on its own and without a key press. you can also do a gravity simulation

 
avatar for phore_eyes phore_eyes 427 posts
Flag Post

how do you make gravity???

 
avatar for IndieFlashArcade IndieFlashAr... 433 posts
Flag Post

Gravity is pretty simple. Ok, say you have a ball MovieClip (ball) and you want to give it some gravity. I’m assuming that the ball will have some velocity (vx, vy : velocity on x and y axis) and a gravity constant (gravity). Here’s the code:

var gravity:Number = 0.03;

this.onEnterFrame = function():Void {
  //apply gravity to y velocity (pulls down)
  ball.vy += gravity;

  //move the ball
  ball._x += ball.vx;
  ball._y += ball.vy;
}
 
avatar for phore_eyes phore_eyes 427 posts
Flag Post

thanks