Hi there,
I followed a random motion tutorials found somewhere on the web. I have a small word made of 10x10 black squares. When someone clicks the word, all the squares start moving around randomly.
What I want to do now is when someone clicks on a moving square, all the squares move back to a given position (obviously, they stop moving randomly).
Is this possible? This is the code I'm using:
I know that I should have it has a function, but I don't even know how to make this bit of code in a function :tired:Code:onClipEvent (load) { //data you may want to change width = 500; height = 400; speed = Math.round(Math.random()*1)+1; } onClipEvent (enterFrame) { //x movement if (x_new>this._x) { sign_x = 1; } else { sign_x = -1; } dx = Math.abs(x_new-this._x); if ((dx>speed) || (dx<-speed)) { this._x += sign_x*speed; } else { x_new = Math.random()*width; } //y movement if (y_new>this._y) { sign_y = 1; } else { sign_y = -1; } dy = Math.abs(y_new-this._y); if ((dy>speed) || (dy<-speed)) { this._y += sign_y*speed; } else { y_new = Math.random()*height; } }
Any help would be greatly appreciated.




Reply With Quote