A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Set bitmap origin to movieclip origin

  1. #1
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254

    Set bitmap origin to movieclip origin

    Hey guys,

    I'm currently making a bitmap copy of a movieclip and adding it to the screen. The problem I am having is positioning the image the same as the movieclip.

    What I mean is currently I have a character which is a movie clip. The origin of the movieclip is set to the bottom middle of the character. Now when ever you copy a movieclip to a bitmap the origin is now the top right corner of the image.

    I could simply use bitmap.x -= width / 2; bitmap.y += height;. But here is the next problem.

    I have attached bitmaps inside the movieclip and the new bitmap takes this into account even transparent pixels (i know how to ignore these). The character movie is positioned at the middle of its feet manually so this doesn't take into account the attached bitmaps on the character. So the character could be 60px wide but 40px to the left of the origin and 20px to the right and the feet would still be on the origin. So because of this bitmap.x -= width / 2; bitmap.y += height; wont put the feet in the middle but rather place the origin at the middle of the bitmap.

    Now I could simply attach the movie clip instead but for performance reasons I need it to be a bitmap.

    Is there anyway to translate the origin exactly/

    Sorry if this doesn't make sense. I can try re explain if need be.
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

  2. #2
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    You could have just set the origin to top-left from the start, and avoided all these problems, or better yet, switch to spritesheet.

    But well, you can try translating the bitmap using a matrix by the amount of difference of the width/height to the coordinates of the origin of the mc.
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  3. #3
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254
    Yeah I know. It's just that having the orgin there seems to make more sense calcs wise in the game for collisions. As for the sprite sheet, that was always an option but animating the different items seems to be over kill for one person

    I figured I would have to use the matrix. I still barely know how it works. I had to use it to copy the image in the first place but that was a fluke

    I'll have a play around and see if I can get it working.

    Thanks
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

  4. #4
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254
    OK I'm still stuck.

    Here is the code I am using to copy the movie clip as a bitmap and add it to the stage.

    PHP Code:
    var bounds:Rectangle mc.getBounds(mc); //Never did understand why you had to pass itself as a parameter

    var bitmapData:BitmapData = new BitmapData(bounds.widthbounds.heighttrue0x00000000);

    bitmapData.draw(mc, new Matrix(1,0,0,1, -bounds.x, -bounds.y), nullnullnullture);

    var 
    bitmap:Bitmap = new Bitmap(bitmapData);

    addChild(bitmap); 
    As far as I can tell the matrix is only used to copy the mc and not its end position when placed inside the movieclip.

    So are you saying to use another matrix on the copied bitmap? I'm not really sure how to do and work out the right points.
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

  5. #5
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    Doush, I am sorry but I can't help much here, but for one thing, if you use the matrix that way, it might compress your code, but it will in the end only confuse you. use the normal way:
    var mat:Matrix = new Matrix();
    mat.translate(0,-1);
    mat.scale(.............. e.t.c


    In my own game engine I am using a spritesheet and am using an external XML to parse it and deal with different sizes of the tiles(and coordinates), I haven't really thought of doing it how you are trying to do, so I have no idea about the actual solution in your case. I will play around with this later and try to figure something out......
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  6. #6
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254
    Its all good bluemagica, thanks for trying. I would have done it the spritesheet way but animation each attached item would have taken me ages. So I decided on a simpler way for me.

    I'll try work out a way to do it Thanks again for your help
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

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