• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

change Registrationpoint of drawn Bitmap

Community Beginner ,
Apr 13, 2017 Apr 13, 2017

Copy link to clipboard

Copied

Hello Community,

I want to tween Movieclips from off-Stage to a random coordinate on-Stage. They should not touch!

I need a way to "reserve" a space on my stage for a movieclip, that isn't on that position yet. I roll random coordinates for positions of my mc with a timer and I cant use a "normal" colission tests, because the Movieclips are slowly tweened to that position and during the tween the later position can get grabbed away by a new movieclip.

I tried to write a function where a Bitmap (later set to invisible) with the exact shape and size of a movieclip spawns at the random point as a placeholder for collisiontest. I want to check if the Bitmap has any collisions with other objects and if not, tween my movieclip on the bitmaps position. (otherways reroll for a new coordinate)

when drawing the bitmapData in a Bitmap, my registrationpoint changes form center to top-left to draw the bitmap completely. I need it in center to make the bitmap the same position like the movieclip.

how can i change the registrationpoint?

function drawBitmap(fly:Fly):void{

  var bounds:Rectangle = fly.getBounds(this); // gets Bounds of Fly in a Rectangle

  var flyBmpData = new BitmapData(bounds.width,bounds.height)

  var flyOffset:Matrix = fly.transform.matrix;

  flyOffset.tx = fly.x - bounds.x;

  flyOffset.ty = fly.y - bounds.y;

  flyBmpData.draw(fly,flyOffset);

  var flyBmp = new Bitmap(flyBmpData);

  flyBmp.x = stage.stageWidth/2;

  flyBmp.y = stage.stageHeight/2;

  addChild(flyBmp);

  }

is there a simpler way to make the Movieclips not overlappig on stage than using a bitmap as placeholder? Maybe only using the bitmapData...?

Thanks!

Megaloadon

TOPICS
ActionScript

Views

350

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Apr 13, 2017 Apr 13, 2017

To make a sprite and put your Bitmap in it, yes you do just like you thought:

var mySprite:Sprite = new Sprite();

mySprite.addChild(flyBMP);

Sprites are just like MovieClips, just a bit lighter as they have no frames. Good for general containers. I routinely use Sprites as layers in my projects - I will have a main layer, a "top" layer, etc... you can then easily remove all objects in a layer etc.

Anyway, to delete them together you would just remove the Sprite and then remove any child with it.

Votes

Translate

Translate
Enthusiast ,
Apr 13, 2017 Apr 13, 2017

Copy link to clipboard

Copied

You might try something like using different sections of the stage - like divide it into 8 sections and then grab a random point within that area.

As for changing the reg point of a bitmap - just place it into a sprite. If your bitmap is 100x100 stick it in a sprite and set it to -50,-50 and then move the sprite.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 13, 2017 Apr 13, 2017

Copy link to clipboard

Copied

dmennenoh​

Ah.. that sounds helpful! So I put it in another ObjectContainer and instead of change the registrationpoint i change the position in the container..

I have not much experience with creating ObjectContainer in AS3, because I usualy do all the MovieClips etc. in Flash. Can you give me a snippet with your sprite solution pls? is it something like: mySprite.addChild(flyBmp) ?

Anyways there might be a way to actually change the registrationPoint back with the Matrix i used in my function. I just dont know how.

I save all the fly Objects in an Array with an ID, so I can identify and delete them by clicking. It would be perfect if i can link the Bitmap to the flyObject to delete them together. maybe thats also possible by putting it into a sprite and maybe than into the object fly? Any Ideas? Thanks for the quick response

Megaloadon

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 13, 2017 Apr 13, 2017

Copy link to clipboard

Copied

To make a sprite and put your Bitmap in it, yes you do just like you thought:

var mySprite:Sprite = new Sprite();

mySprite.addChild(flyBMP);

Sprites are just like MovieClips, just a bit lighter as they have no frames. Good for general containers. I routinely use Sprites as layers in my projects - I will have a main layer, a "top" layer, etc... you can then easily remove all objects in a layer etc.

Anyway, to delete them together you would just remove the Sprite and then remove any child with it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 13, 2017 Apr 13, 2017

Copy link to clipboard

Copied

LATEST

dmennenoh​

That will solve it... Thank You!

So to delete them at once i would have to put the fly and my bitmap in one MC or Sprite. Can I then still move them indpendend and with old registrationpoints etc? Otherways i would need a way to put them together in an Object and push that into my array.

What would be better?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines