开发者

AS3 How to create double sided MovieClip which when rotation shows the other side as well?

开发者 https://www.devze.com 2023-02-10 09:37 出处:网络
I have a movie clip which has two frames. On the first frame I have the front side and on the second I have the back. I am rotating the MovieClip by rotationX,rotationY,rotationZ properties.

I have a movie clip which has two frames. On the first frame I have the front side and on the second I have the back. I am rotating the MovieClip by rotationX, rotationY, rotationZ properties.

I want to di开发者_开发百科splay the frame 2 when the MovieClip rotates. Please help. I dont want to use PaperVision class. Also, please consider the Perspective View of the scene.

Sometimes, the MovieClip might not only be dependent on rotation. It is also equally dependent on the position (only in Perspective View).

Thanks for considering my question.

Regards, Sanket

PS: Please check the problem here http://sanket.info/as3/problem.gif


Just to add to the existing solutions, here are some ready made utilities:

  • Thibault Imbert's SideDetector
  • Senocular's IsFrontFacing
  • Soulwire's Double Sided 3D Plane

AS3 How to create double sided MovieClip which when rotation shows the other side as well?

HTH


sounds like you want to determine which side you see based on the rotation and the perspective angle combined.

rotation you already know how to read.

and it looks like the perspective angle is based on only a change in x (based on your image)

in game terms, this would be like seeing through the eyes of a hero that can only step left and right, but not forwards backwards or turning. Please confirm.

if thats the case, i recommend finding the perspective angle with something like this.

this is 2d math as if viewing your camera(as hero) and your pic from overhead. and finding the angle between them.

//find difference between hero and pic positions  (delta means difference or change)
var deltaPt:Point = new Point(pic.x - hero.x, pic.y - hero.y);
//find angle between hero and pic, then convert to degrees from radians
var angle:Number = Math.atan2(deltaPt.y, deltaPt.x) * 180 / Math.PI

var testAngle:Number = pic.rotation + angle;
trace("angle: "+angle);
trace("testAngle: "+testAngle);

check if those traces are anywhere near what your expecting to see.

perhaps angle needs to be negative instead of positive, or offset by 90º or something (i tend to guess and check this a bit, sorry for the slop)

if your hero is also able to rotate... it may get more complicated, or it might just involve adding the hero's rotation to the mix, I haven't thought that part through just yet.

once you get it adjusted right it should end in something like this, which I'm sure you already know.

if(testAngle > 90){gotoAndStop(2)}
else{gotoAndStop(1)};

hope that helps some.


Check out this link.

http://codingfiend.com/examples/greeting_card/

Rather than using two frames, make your front and back as two movieclips on one frame. Place them on top of each other, front side on top, and flip the backside horizontally. I used this ENTER_FRAME event to track rotation and show and hide the front of the card. I start the event when clicking the front of the card, track the tween and kill the event when its open. Perhaps you could also track position as well as rotation to accomplish what you are looking for.

protected function oef(evt:Event):void
{
    var rot:Number = Math.round(_front.rotationY);

    if(rot >= 0 && rot <= 89)
    {
        _front.outside.visible = true;
    }
    else
    {
    _front.outside.visible = false;
    }           
}
0

精彩评论

暂无评论...
验证码 换一张
取 消