ActionScript 3.0 :: Change The Rotation Point Of A Sprite?
Feb 4, 2008
I'm attempting to write a racing game. I've loaded in my image, I brought it to the stage and now, all I want to do is rotate it from its' center and not upper left corner.
The code:
racer.rotation += 5;
rotates from the upper left corner. How do I rotate from the center of the car/sprite? I've tried putting it into a container but I'm unsure on the coordinates of the container because I tried to set the x,y coordinates to half the sprite image but y'know, it's not doing what I expect it to.
ActionScript Code:
if (arrowLeft) {
var container:Sprite = new Sprite();
[Code]....
I will never sneer at another racing game! I didn't think it would be this hard to do a simple rotate of an image!
I have a point which is setted at the border on a component, with changed transform point to the center of a component in order to match the component rotation.
the important part is when i try to get the point XY after rotation - they remains the same as before rotation.
how to get XY, after rotation ( changeing point.rotation property to specific degrees of rotaion )
I'm trying to convert a Sprite that I have into BitmapData so I can perform some collision detection. There are a few things about the way the Sprites are used that is making this more difficult than I expected:
The Sprite itself is a container which holds another Sprite that actually has a box drawn in it. The inner Sprite is positioned negative half its width & height so that it can be rotated from the center via the container. The container may be rotated at any angle at any given time
So my approach thus far has been attempting to draw the outer Sprite onto a new BitmapData object with a Matrix to account for the difference. Whilst I can use a Matrix to make this work for one particular rotation angle, I cannot find a way to make it work for any rotation.
Here's what I'm doing to draw onto the new BitmapData:
var p:Product = getProduct(); // Product is the container with the inner sprite var bounds:Rectangle = p.getBounds(stage); var bd:BitmapData = new BitmapData(bounds.width, bounds.height, true, 0x00FFFFFF);
[Code]....
Translating by the same amount as the previous example will no longer work here, and the box will still be cut off. I've looked around at some solutions posted before or suggestions from other people but they don't seem to work for me due to my container Sprite and rotation.
Has anyone got a bit of code I can use to change the center point DisplayObjects rotate around in a 3D space? I need it to work with rotationX, rotationY and rotationZ. I know theres a workaround of wrapping every object in aother sprite and offsetting the x & y positions but I'd much prefer a math solution. As an example of the problem, this code should make a star shape:
When you load a object through flash, you can set the rotational/scale point, but when you load it as a loader object or sprite, how do you change this point?
In this instance, I want to change the height of a sprite that is filled with a rectangle so that it shrinks down, not up.
Right now:
var colored_bar:Sprite = new Sprite(); with (colored_bar.graphics) { beginFill(0x9e1819, 1);
[Code]....
The way I am doing it currently is moving the y position everytime I take away soem of the height, so it looks like it's moving down, but I'd think moving the orientation point at the beginning would be faster
I found this actionscript online to rotate a sprite around its center point but I get two errors when I use it. 1084: Syntax error: expecting identifier before leftparen. 1084: Syntax error: expecting rightparen before leftbrace. Also, in place of angleDegrees do I put in the angle I want the sprite to rotate by?
var point:Point=new Point(spr_box.x+spr_box.width/2, spr_box.y+spr_box.height/2); rotateAroundCenter(spr_box,45); function rotateAroundCenter (ob:*, angleDegrees) { var m:Matrix=ob.transform.matrix; m.tx -= point.x;
Flash knows where the anchor point is in 3D space in order for the symbol to rotate around it, but I can't seem to figure out how to see the coordinates of the anchor point or type in new ones. Please tell me how to do this. I am already very annoyed that Lynda, a pay service, doesn't think this is vital information. Apparently they think we would never want to do anything more visually stimulating than one simple spinning logo! But I digress...
Just to be clear, I know how to move the anchor point visually on the stage, but I want accuracy. I want to be able to give two symbols the exact same coordinates to rotate around.
i'm working on a flash game at the moment, and i would like to know if i am able to set the point that the movieclip rotates around using actionscript.
i don't want to do it by simply moving all of the contents of the movieclip closer or nearer. is there any other way of doing it? i couldn't find any simple functions for it. am i just going to have to use some complicated maths?
[edit] rotation point, aka, registration point.[/edit]
I am making a 'simple' template builder in flash which allows the user to add/remove text boxes and images to the stage. I can rotate any of the movieClips fine but it rotates from the top left and i want it to rotate from midpoint. Is there a way to set the midpoint/rotation point using actionscript?
I have the following problem. I have an MovieClip in a holder MC. I would like to turn the inner MC X with 'rotation' parameter, and still keep it in the holder mc to the right and bottom of the holder MC reference point. So after turning it should look like thatanyone can tell me how to do that? Basically a function that takes any X rotated in any degrees through X.rotation = ... and puts it back in place in the holder MC.
I am rotating some objects which their rotation (pivot) point is not at the center. My aim is to rotate from the center of the shape. How can I overcome this?
greetings, first of all sorry for my english. This question will probably looks more difficult than it is.
I have movieclip which I want to rotate around internal point few angles with click on certain button, and I manage to do it, but I want to see motion, or even put ease not only to immediately pop up in the place.
I am creating a a small site with a spinning menu but I want it to spin only in onedirection ( clockwise) and around the centre of the 3 point cross I am using as a menu.I have this currently to rotate the menu but I want it to only rotate on way and around centre.
Code: content_mc.draw_btn.addEventListener(MouseEvent.CLICK,drawClick); function drawClick(e:MouseEvent):void{
I want to have arm movement such as the forearm rotating about the arm where the elbow should be the problem is the registration point is at the shoulder for arm. I want the forearms registration to be constantly equal to a simulated registration point where the elbow should be as the arms registration point would be at the shoulder. I need to do it without nesting (a movieclip within another) is it possible. I tried using a constant distant between the two clips but it doesn't work. Don't know I have to use trigonometry or not
I think in brief what I trying to accomplish is onEnterFrame=function(){ arm._x=shoulder._x arm._y=shoulder._y arm._x=simulated_x (where elbow would be) arm._y=simulated_y (where elbow would be) }
I am trying to rotate a symbol about the y-axis, 45 degrees one direction, then back to center, then 45 degrees the other direction. Seems like a relatively simple task, except here is what happens.
Here is the object with no rotation: Here is the object rotated exactly 45 degrees: And here is the object rotated exactly -45 degrees:
I need the object to rotate the same as it did the first time but in reverse, otherwise "45" and "-45" are generally worthless numbers to refer to. Is it something to do with the pivot point? I made sure the registration point was in the center when I created the symbol. It doesn't seem to be pivoting the object around the center though. How do I rotate about the y-axis using a pivot point that is actually in the center and gives the same (but opposite) effect when rotating it one way versus the other?
I have a project on the go which has a compass that I would like to have move randomly around a fixed central point (giving the idea of changing direction).Would anyone be able to help me out with the coding to get this to work?
var shape1:Shape; shape1=draw(); addChild(shape1); shape1.rotation=50;
[Code]....
Then I want to rotate the shape at it's center point(200,202) by using shape1.rotation=50,but I find the shape don't rotate at the the center of it's shape. How to realize the function which make shape rotate at its center point?
Does anyone know if AS3 or FP9/10 enforces a minimum increment or resolution for the Sprite rotation property?It seems to only allow rotations in multiples of 0.25 degrees.For example:
var lines:Array = new Array(); for (i=0; i<2000; i++){ lines[i] = new Shape(); lines[i].graphics.lineStyle(.1, 0x000000);
[code]...
This draws the lines in groups at 0.25 degree spacing with gaps between them.
As in the figure i have three lines out of which line1 and line2 are fixed. line3 is derived from line1 based on some angle say 70.I try to rotate the line3 but it deviate from the point x1 and x2. I try the code like this
How can I know if a point is contained inside of an Sprite in Flex?
For example: // My example point var A:Point = new Point(5,5); // My example sprite var s:Sprite = new Sprite(); s.graphics.lineStyle(1,0x000000,1); s.graphics.moveTo(0,0); s.graphics.lineTo(100,100);
The point A belong to sprite s because its position is inside of it. Is there any function to know it? I want to do it for all kind of sprites, so use math formulas to calculate linear or quadratic equations (line, circle, rectangle, etc) is not valid for me.
how I can count the B point's coordinates (see attached image... or not as I am a new user...pf!). I know the arrow's rotation - so the angle (let's say it is -120), A's coordinates (0, 0) - A is the middle point of the arrow, and that the distance between A and B is 50 px.
I searched online and found this script that is supposed to rotate and image but I'm not sure how to use, where to put in the degree angle that I want my sprites to rotate by. Also, I get an error. 1084: Syntax error: expecting identifier before leftparen. 1084: Syntax error: expecting rightparen before leftbrace.
var point:Point=new Point(spr_box.x+spr_box.width/2, spr_box.y+spr_box.height/2); rotateAroundCenter(spr_box,45); function rotateAroundCenter (ob:*, angleDegrees) {
I once needed to pan a sprite full of movieClips (picture 1) which were draggable with no bounds so you could drag them up and left (higher than sprites registration point).
You could also drag them down and right and expand a sprite that way (as well) but that didnt matter.What did matter was how much is 'up' and 'left' from the sprite registration point so i can include that in my formula for panning.
This was easy to find, i just sorted my array of movieClips, sorted on x and sorted on y after each drag, and thats how i got my up and left points.
Now I am trying to do that same thing, exept my movieclips inside a sprite have a custom rotation (picture 2), so i also have an up and left point, except this time up and left are caused by rotations of movieClips inside a sprite... (and these are dragable as well with no bounds)
I basically want the food sprite to spin slowly about its center, not its x and y value which is the top left corner of the sprite. How can I make the anchor the center of the sprite?