1

i am trying to attach a movie clip to multiple nape bodies but am getting the following error.

Line 118    1067: 
Implicit coercion of a value of type flash.display:MovieClip 
to an unrelated type nape.shape:Shape.

and here is the block of code:

for (var i:int = 0; i < 10; i++)
{
     var brick:Body= new Body(BodyType.DYNAMIC);
     var brickShape:Polygon = new Polygon(Polygon.box(10,30));
     brick.position.setxy(500, ((h ) - 32 * (i + 0.5)));
     var brickMovieClip:MovieClip = new Brick();
     brickMovieClip.width = 10;
     brickMovieClip.height = 30;
     addChild(brickMovieClip);
     brick.shapes.add(brickMovieClip);              
     brick.space = space;
    brick.shapes.at(0).material.elasticity = .1;            
}

if you have any idea how to fix this your help would be greatly appreciated.

Lonergan6275
  • 1,938
  • 6
  • 32
  • 63
  • 1
    What line is line 118 ? I am thinking that the brick.shapes.add(brickMovieClip) line might be the culprit. The add method is likely expecting a Shape. – prototypical Mar 21 '13 at 17:39
  • The add method does not accept a MovieClip, it needs to be a type that subclasses nape.Shape -- circle or polygon. – prototypical Mar 24 '13 at 02:58
  • my understanding of the above is i am adding the brickMovieClip MC to the nape body brick which is a polygon – Lonergan6275 Mar 24 '13 at 20:03

1 Answers1

3

the shapes property of Body is a list of nape.shape.Shape's, not MovieClip's, you should be adding the brickShape to the body's shapes list, not a Movieclip.

Nape itself has nothing to do with graphics, and its up to you each frame, to move the grapihc associated with a body to the correct position/rotation based on the physics object state.

What you can do, is store the movieclip in the userData field of the body so that you can access it easily later if necessary like:

body.userData.graphic = brickMovieClip;

then each frame you can update the graphic like:

var mc:MovieClip = body.userData.graphic;
mc.x = body.position.x;
mc.y = body.position.y;
mc.rotation = body.rotation * 180 / Math.PI;
deltaluca
  • 1,652
  • 2
  • 10
  • 9