A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25

Thread: [AS3][Help] Adding A Sprite To A Stage

  1. #21
    Professional Flash Developer
    Join Date
    Aug 2007
    Location
    California
    Posts
    105
    Quote Originally Posted by as3newb

    That looks like a winner there, but I'm not following how the bitmapdata ends up inside the sprite. Are you by any chance implying that the bitmapinstance for mybitmapdata could be changed on the fly by moving over new bitmapdata to it and it would be reflected inside the sprite without the need for a new beginbitmapfill? (phew...what a mouthfull..)
    Pretty much that's how it works because everything in the AS3 swf platform is passed by reference (many not primitives though). If a BitmapData object is a property of a Bitmap object that is inside a sprite (on its display list), by simply changing the reference of the bitmapData inside the Bitmap will change the look of the bitmap ans thus the sprite.

    I have to work up some examples of both of these (the above also) that are real world and working, but this is how I have been doing it for years.

  2. #22
    Member
    Join Date
    Jan 2009
    Location
    Texas
    Posts
    75
    Awesome Jeff, I got it all working! Thanks so much! Now I can animate my Sprite() objects. woo hoo! It's a fairly difficult concept to grasp because in order to get auto centered scaling and rotation, I have to first set up an empty parent, then attach a child which attaches the bitmap.

    Now it's time to code some high level wrapper routines to all this stuff so it's much nicer to play with.

  3. #23
    Professional Flash Developer
    Join Date
    Aug 2007
    Location
    California
    Posts
    105
    Yes, the Bitmap inside the Sprite must be placed at 1/2 width, 1/2 height for x and y respectively. That is the only way to rotate the Sprite and have it be radial motion around the center point rather than radial around the top left corner. It bugs me too.

    -Jeff

  4. #24
    Member
    Join Date
    Jan 2009
    Location
    Texas
    Posts
    75
    whoah....come to think of it, I don't need that initial empty sprite anymore since the bmp is a child of the sprite. Excellent.

  5. #25
    Registered User
    Join Date
    Nov 2010
    Posts
    1

    Lightbulb single sprite rotation

    instead of drawRect to draw your square or rectangle use the moveTo and lineTo property, doing this adds the registration(roation point) to the center so no parent will be needed. heres some sample code:

    var moon:Shape = new Shape();
    moon.graphics.lineStyle(0,0xFFFFCC);
    moon.graphics.beginFill(0xFFFF00);
    moon.graphics.moveTo(-5,-5);
    moon.graphics.lineTo(5,-5);
    moon.graphics.lineTo(5,5);
    moon.graphics.lineTo(-5,5);
    moon.graphics.lineTo(-5,-5);
    moon.graphics.endFill();
    Note: this makes a standard 5 by 5 square and when you go to addChild(moon); also add the X and Y you want it t be located at.

    addChild(moon); // adding moon to stage
    moon.x = 200; //X coordinate
    moon.y = 200; //Y coordinate
    I know this isn't a sprite, but it gets the job done

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