The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 3 of 3

Thread: SUPER HARD Trig Problem

  1. #1

    SUPER HARD Trig Problem

    This is a follow up thread to this: http://www.kirupa.com/forum/showthre...=1#post2529594

    I figured they are different enough problems that I should start a new thread...

    At any rate, I have learned how to position graphics in a circular pattern and they space out evenly depending on how many graphics are in a given array.

    So now, I want to be able to rotate the graphics in a clockwise or counter-clockwise pattern (not a sprite container that holds all of the graphics, but the graphics themselves.)

    I am pretty close... here's what I have so far:

    Code:
    private function weaponChange(e:KeyboardEvent):void {
                if(e.keyCode == LEFT_KEY1 || e.keyCode == LEFT_KEY2 || e.keyCode == DOWN_KEY1 || e.keyCode == DOWN_KEY2) {
                    for(var i:uint = 0; i < _weaponSymbols.length; i++) {
                        var j:int;
                        if(i+1==_weaponSymbols.length) j=-1;
                        else j = i;
                        
                        TweenLite.to(_weaponSymbols[i], 1, {bezier:[{x:600,y:600},{x:_weaponSymbols[j+1].x,y:_weaponSymbols[j+1].y}]});
                    }
                }
                
                if(e.keyCode == RIGHT_KEY1 || e.keyCode == RIGHT_KEY2 || e.keyCode == UP_KEY1 || e.keyCode == UP_KEY2) {
                    trace("Counter - Clockwise")
                }
            }
    So this gets each graphic to the next location just fine. Now notice what I have in red... I want the graphics to animate along the parameter of the circle. All I need to do that is to identify the x,y coordinates between the two graphics.

    I figure the y will be easy because I can just subtract the y of one graphic from another... the x is something I have no idea how to do...

    See the image I have attached... this illustrates the x Points that I'll need depending on number of graphics.

    Any help is appreciated!
    AR
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	SymbolShift.jpg 
Views:	36 
Size:	26.3 KB 
ID:	51422  

  2. #2
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?
    So your looking for the coordinates of the x in your diagrams? I assume from the last thread that you know the angle that each graphic is at. In that case, the x will be at an angle equal to the angle of the graphic plus 2pi divided by the number of graphics.
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  3. #3
    Hm... This will tween all mcs to their new position, depending on which item is in the "currentWeapon" slot (the top one) and which one you want to be in the top slot "targetWeapon".

    Note, this code is VERY similar to the one I wrote above...
    Code:
    //This corresponds to the weapon number in the array
    var currentWeapon:uint = 0;
    var targetWeapon:uint = 3;
    
    //Angle in radians
    var angleEach:Number = (2 * Math.PI) / weaponSymbols.length;
    var targetAngle:Number = -angleEach * targetWeapon;
    
    //Note that this is a temporary item that contains all the properties for tweening,
    //And is never placed on the stage in any way or used other than storing values
    var tp:Object = {angle:(-angleEach * currentWeapon)};
    
    TweenLite.to(tp, 1, {angle:targetAngle, onUpdate:moveSymbols});
    
    function moveSymbols()
    {
       for(var i:uint = 0; i < weaponSymbols.length; i++) {
           var symbolAngle:Number = (angleEach * (i - currentWeapon)) + tp.angle;
           weaponSymbols[i].x = RING_MENU_RADIUS * Math.sin(symbolAngle);
           weaponSymbols[i].y = RING_MENU_RADIUS * Math.cos(symbolAngle) * -1; //Multiplied by negative one becuase in Flash, up on y is "backwards"
           
           //You can also tween the items into place, but I believe this direct method 
           //is a lot faster and more "cpu friendly"
       }
    }
    If it doesn't work, post back and I'll try again.

    I'm not 100% sure if using -angleEach in the places I did instead of regular angle each will solve a problem or cause it, so you can test both methods. If you get runtime errors, you might need to use the "onUpdateParams" and pass in the variables directly instead.

    Right now it will always spin counter clockwise to get the next item, but with a tad of logic, you can make it spin whichever way is closer, but I'll leave that up to you.

    I have a short article on how you can easily tween functions (like I did here) on my blog:
    http://iqandreas.blogspot.com/2009/0...functions.html



    Sorry, I can't help it... You know what else is SUPER HARD? http://www.youtube.com/watch?v=KtxfJGmj-aE
    Blog article of the month: Why My One Line 'if' Statements Are Unusual
    Twitter: @IQAndreas
    GitHub: IQAndreas

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012