-
Changing a AS objects diameter of rotation dependant on position of mouse
Hi guys,
This is for a personal art project, however I have hit a potential (Actionscript) brick wall!
I want the diameter of the 'balls' orbit to change dependant on the position of the mouse but keep the point of rotation exactly the middle of the stage at all times.
I.e. if the mouse is hovering over the exact center (both X+Y) of the stage then the 'ball' should have a tiny diameter of rotation (but contstantly follows the orbit in clockwise direction) whilst if you move the mouse towards the edge of the stage then the diameter of the orbit of the ball will increase.
Here is the AS which controls a blank movieclip;
var sp:Sprite = new Sprite();
orb1.addChild(sp)
var g: Graphics =sp.graphics
orb1.x = (stage.mouseX);
orb1.y = (stage.mouseY);
g.moveTo(stage.mouseX, stage.mouseY);
//stage.stageWidth/2,stage.stageHeight/2)
g.lineStyle(1.5,0x000000,10);
g.beginFill(0x000000,0.2)
g.drawCircle(stage.mouseX,stage.mouseY,10)
g.endFill();
stage.addEventListener(Event.ENTER_FRAME,test)
stop();
function test(Evt:Event):void{
orb1.rotation +=5;
orb1.x = (stage.mouseX);
orb1.y = (stage.mouseY);
}
If it help's, here is the .swf, .fla AND an image with an explanation:
http://www.taylormadeclubbing.co.uk/flash/test.swf
http://www.taylormadeclubbing.co.uk/flash/test.png
http://www.taylormadeclubbing.co.uk/flash/test.fla
Hope this helps!
-
There are lots of ways to do this, one easy way would be to put your orb inside another container sprite, then rotate the container and offset the location of the orb:
PHP Code:
var orb:Sprite = new Sprite();
orb.graphics.lineStyle( 1.5,0x000000, 10 );
orb.graphics.beginFill( 0x000000,0.2 );
orb.graphics.drawCircle( 0, 0, 10 );
orb.graphics.endFill();
var orbContainer:Sprite = new Sprite();
orbContainer.addChild( orb );
orbContainer.x = stage.stageWidth / 2;
orbContainer.y = stage.stageHeight / 2;
addChild( orbContainer );
function updateOrb( e:Event ):void {
orbContainer.rotation += 5;
//a squared plus b squared equals c squared
orb.y = Math.sqrt( Math.pow( stage.mouseX - orbContainer.x, 2 ) + Math.pow( stage.mouseY - orbContainer.y, 2 ) );
}
addEventListener( Event.ENTER_FRAME, updateOrb );
Also, when posting code it really should be indented and wrapped it in a code tag.
Tags for this Thread
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
|