cannon

thank you, thank you, thank you

the *2 should be the variable which sees how far is the mouse from the cannon and therefore gets the power. so it should be *power but i havent defined the power yet.
master wrote:
thank you, thank you, thank you

the *2 should be the variable which sees how far is the mouse from the cannon and therefore gets the power. so it should be *power but i havent defined the power yet.


Haha, not a problem.
How can i removeChild when it is outside the stage. I cannot seem to access the childs i create. I don't need to access them individually but i just want to get rid of them as they are outside the stage (talking about the "shot"-s)
Code:
   function shootShot(event:MouseEvent):void {
      xd=myWorld1x.triangle.x-myWorld1x.mouseX;
      yd=myWorld1x.triangle.y-myWorld1x.mouseY;
      radAngle=Math.atan2(yd,xd);
      var shot:vinyl=new vinyl();
      if (- Math.cos(radAngle)<0&&- Math.sin(radAngle)>-1) {
         myWorld1x.triangle.klip.gotoAndPlay(2);
         shot.x=myWorld1x.triangle.x;
         shot.y=myWorld1x.triangle.y-50;
         arvutaPower();
         shot.linearVelocityX=0;
         shot.linearVelocityY=- dance;
         myWorld1x.addChildAt(shot,1);
      } else if (-Math.sin(radAngle)>0) {
         myWorld1x.triangle.klip.gotoAndPlay(2);
         shot.x=myWorld1x.triangle.x+50;
         shot.y=myWorld1x.triangle.y;
         arvutaPower();
         shot.linearVelocityX=dance;
         shot.linearVelocityY=0;
         myWorld1x.addChildAt(shot,1);
      } else {
         myWorld1x.triangle.klip.gotoAndPlay(2);
         shot.x=myWorld1x.triangle.x+(-Math.cos(radAngle)*50);
         shot.y=myWorld1x.triangle.y+(-Math.sin(radAngle)*50);
         arvutaPower();
         shot.linearVelocityX=- Math.cos(radAngle)*dance;
         shot.linearVelocityY=- Math.sin(radAngle)*dance;
         myWorld1x.addChildAt(shot,1);
      }
   }

   myWorld1x.addEventListener(MouseEvent.MOUSE_DOWN, shootShot);
bump:)
I know this is coming in a bit late, but I posted code similar to a cannon a while back based on Emanuel Ferranto's Box2d code and a user's question about how to make it work in WCK. Might be worth it to check that code out,

viewtopic.php?f=19&t=6414
burtonposey wrote:
I know this is coming in a bit late, but I posted code similar to a cannon a while back based on Emanuel Ferranto's Box2d code and a user's question about how to make it work in WCK. Might be worth it to check that code out,

http://www.box2d.org/forum/viewtopic.php?f=19&t=6414


Hey thanks for the reply. I did find this thread when i searched the forums but unfortunately i don't use the new versions. Could you deliver it in CS4?
If you're needing to access your cannonballs that you are shooting, then I recommend you keep an object pool or some sort of collection handy.

That said, probably the simplest answer is create a special WCK object type that will sit outside of your game level. It has an event listener for ContactEvent.BEGIN_CONTACT and checks on those objects if the thing that hit it is one of your "vinyl" object types. If it is, it gets a vinyl.remove callout to take it off the stage.

Code:
var contactedItem:vinyl = e.other.m_userData as vinyl;
if( contactedItem ) {
   contactedItem.remove();
}
burtonposey wrote:
If you're needing to access your cannonballs that you are shooting, then I recommend you keep an object pool or some sort of collection handy.

That said, probably the simplest answer is create a special WCK object type that will sit outside of your game level. It has an event listener for ContactEvent.BEGIN_CONTACT and checks on those objects if the thing that hit it is one of your "vinyl" object types. If it is, it gets a vinyl.remove callout to take it off the stage.

Code:
var contactedItem:vinyl = e.other.m_userData as vinyl;
if( contactedItem ) {
   contactedItem.remove();
}


Thanks!:) I swear i tried this solution but it didn't work and i just left the idea, i guess the listener was inside the level. Glad you brought that out. Thanks again 🙂

Original thread: https://box2d.org/forum/viewtopic.php?t=6926