A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Flash MX (6) - Exploring 3D in Flash - Pre-rendered Help

  1. #1
    Member Manic_Man's Avatar
    Join Date
    Dec 2007
    Location
    Hastings, England
    Posts
    91

    Flash MX (6) - Exploring 3D in Flash - Pre-rendered Help

    Hi.. Back in.. oh, some time ago, senocular (and i think it's THE senocular who should be still around here) did a Tut on Kirupa about using Flash MX and it's limited 3D skills. You can view it here:
    http://www.kirupa.com/developer/acti...pt/3dindex.htm

    It's very good and helps alot with teaching the basics of how to do OLD 3D with MX, before AS2 and AS3 introduced much more advance 3Ding Skills.

    Anyway.. On the Top of using Pre-rendered Graphics, it's not as perfect (as stated) but pretty good. But it doesn't deal with one issue. What if the Objects that are pre-rendered, change direction..

    The Direct link to the section on Pre-rendered is this:
    http://www.kirupa.com/developer/acti...e_rendered.htm

    Now. I have a Varible, which stores the Rotation in Radians So that should be part of the work done.. I worked out that just adding this to the varible. Though it might be a problem if trying to force it more between the correct Radian values.. I've tried this line:

    frameFromAngle(((angle+perspectiveShift)+(facing))-1, this._totalframes);

    Where Facing is the Rotation and the rest is as the code pretty much what's on the page (though i changed the +1 into -1 because it Seemed to work better.. But it still doesn't seam to give the right angle it should. I did wonder if perhaps the fact the frameFromAngle code seams to force it between 2Pi and with the Facing varible it might be a fair bit higher, but i'm not sure and this doesn't seam to explain why it doesn't seam to work much at all..

    Any help or advice on displaying pre-rendered sprites would be helpful, thanks

  2. #2
    Member Manic_Man's Avatar
    Join Date
    Dec 2007
    Location
    Hastings, England
    Posts
    91
    I've found out what i wanted and i would like to thank senocular. When i contact him he was too busy to help but the fact of replying and how nice he was is something that should never be underesitmated.

    To help others who wish to do this, I'll explain and show the code change required.

    In Order to allow Objects to change direction and display the right directional frame, i knew there had to be an offset someplace but wasn't sure where.. After alot of testing i found out it's in the 'frameFromAngle' function. The oringal code is as follows:

    Actionscript Code:
    frameFromAngle = function(r, frames){
        r %= 2*Math.PI;
        if (r < 0) r += 2*Math.PI;
        return Math.floor(1 + frames * r/(2*Math.PI));
    };

    now. In order to apply the offset you need to know the rotation of the object. This should be stored as a radian to make things alot easier, or just converted to one. You can either pass this rotation value into the function find it out via some other means.. for the sake of things, i'll pass it.

    Now.. you need to REMOVE the rotation value from the passed angle (Varible 'r'). Once you have done this, the only other thing you need to do is plus 1 to the resulting sum before you return it. The new Function is as follows:

    Actionscript Code:
    frameFromAngle = function (r, frames,Rotation) {
        r -=Rotation;
        r %= _root.TwoPi;
        if (r<0) {
            r += _root.TwoPi;
        }
        var realFrame = Math.floor(1+frames*r/(_root.TwoPi));
        realFrame += 1;
        return realFrame;
    };

    as you can see, instead of just returning the sum, i've decided to do it via two lines and store the sum and then do the add 1.. I've not really got an idea why that bit was needed but it came out as 1 frame out for some reason..

    This has been tested via 4 directional frames BUT i want 8 in the end, so it should be fine, but i can't comfirm it right now. I hope this is of some use to people in the future.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center