2
대포와 캐논이 있습니다. 포탄을 대포에서 마우스 클릭 위치로 옮기려면 어떻게해야합니까? 정지 애니메이션/폭발/정지 애니메이션을 활성화 하시겠습니까?발사체를 마우스 클릭 위치로 이동 AS3
나는 다른 솔루션을 시도했지만 그 중 아무 것도 나를 위해 작동하지 않는 것처럼 보였습니다. 그래서 조금 정리했습니다.
그리고 네, 나는 추한 것을 알고 있습니다.
대포와 캐논이 있습니다. 포탄을 대포에서 마우스 클릭 위치로 옮기려면 어떻게해야합니까? 정지 애니메이션/폭발/정지 애니메이션을 활성화 하시겠습니까?발사체를 마우스 클릭 위치로 이동 AS3
나는 다른 솔루션을 시도했지만 그 중 아무 것도 나를 위해 작동하지 않는 것처럼 보였습니다. 그래서 조금 정리했습니다.
그리고 네, 나는 추한 것을 알고 있습니다.
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.display.MovieClip;
import flash.events.Event;
import flash.ui.Mouse;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.utils.Timer;
import flash.display.Sprite;
addEventListener(Event.ENTER_FRAME, enterFr);
function enterFr(e:Event)
{
\t aims.x = mouseX;
\t aims.y = mouseY;
}
Mouse.hide();
zamok.addEventListener(MouseEvent.CLICK, fire);
function fire(m:MouseEvent)
{
\t var s:Sound = new cannonFire();
\t s.play();
\t var explo:boom = new boom();
\t explo.x = mouseX;
\t explo.y = mouseY;
\t addChild(explo);
}
private function fireCannonBall(target: Point):void
{
const cannonBall:CannonBall = new CannonBall(); // you need to implement this class, or just use some MovieClip from library;
cannonBall.x = initialPosition.x; // initial position is a point where your cannon is located.
cannonBall.y = initialPosition.y;
addChild(cannonBall);
// I suggest using TweenNano, but it has some limitations, read the License Agreement carefully
TweenNano.to(cannonBall, 15 /* animation duration */, {x: target.x, y: target.y, onComplete: makeExplosion, onCompleteParams: [cannonBall]});
}
private function makeExplosion(cannonBall: CannonBall):void
{
/* I leave this part to you, here you might want to launch some explosion animation */
}
이제 우리는 클릭을 처리 할 필요가 : 대략, 그것 뿐이다
private function onMouseClick(e: MouseEvent):void
{
const target: Point = new Point(stage.mouseX, stage.mouseY);
//and launch the cannonBall:
fireCannonBall(target);
}
우리에게 이미 시도한 것과 같은 일부 코드를보기 :
는 TweenNano이 링크를 클릭하십시오에 대한 자세한 내용을 알고. 마지막으로 확인한 바로는 SO는 도움을 요청하고 조언을 구하는 것이지, 바로 사용할 수있는 코드를 생성하는 것이 아닙니다. –@GurtejSingh @ GurtejSingh 내가 당신에게 그것을 보여 주면 당신은 나를 싫어 할 것입니다, 진지하게, 나는 그것을하지 않는 것이 좋습니다, 너무 추한 것입니다. 오 잘 ... – solspire
코드가 잘 보입니다. Tween을 사용하여 대포를 mouseX 및 mouseY 위치로 움직일 수 있으며 트윈이 완료되면 폭발시킬 수 있습니다. 나는 보통 내 모든 애니메이션에 Tweenlite를 사용하지만 제 3 자이므로 Tweenlite로 멋지다면 한번 해보십시오. 꽤 쉽습니다. 건배. –