뒤집기를위한 결함 매트릭스 (미러 반사) movieclip
-
05-07-2019 - |
문제
나는 현재 AS3에서 멋진 작은 2D 게임 엔진을 연구하고 있습니다. 다른 애니메이션에 대해 XML을 통해 다른 플래시 영화 클립을로드 할 수도 있습니다. 기능 중 하나를 사용하면 특정 액션을 수행 할 때 애니메이션을 뒤집을 수 있습니다. 그렇게하면 왼쪽과 오른쪽 모두에 대한 1 개의 애니메이션이있을 수 있습니다 (평소와 같이). 매트릭스 변환이 올바르게 작동합니다. 그러나, 나는 물건을 앞뒤로 뒤집는 것에 대한 나의 논리가 잘못되었다고 생각합니다. 결과적으로 잘못된 애니메이션은 잘못된 시간에 재생됩니다. 나는 물리 요소가 관련되어 있기 때문에 키 프레스보다는 움직이는 물체의 속도를 기반으로 애니메이션을 재생하기로 결정했습니다.
다음은 현재 상태의 게임 링크입니다. http://parrisstudios.com/game_design/gameenginedemo/
문제는 주로 애니메이션이 잘못된 시간에 재생되거나해야 할 때 재생되지 않는다는 것입니다.
다음은 뒤집기를위한 내 코드입니다 (여러분의 생각을 알려주세요) : PS : 방향 변수는 문자가 직면하는 마지막 방향입니다 (이 경우 왼쪽 또는 오른쪽으로 코드의 뒷부분에 설명되어 있습니다).
private function drawJumpMode():void {
var change:Boolean = false;
//decide whether to swap graphics or continue playing
if (Math.abs(particleGroup.particles[0].velocity.y) < epsilon && Math.abs(particleGroup.particles[0].velocity.x) < epsilon && direction == "right") {
if (lastClipAction != "stillRight"){
lastClipAction = "stillRight";
change = true;
}
}
else if (Math.abs(particleGroup.particles[0].velocity.y) < epsilon && Math.abs(particleGroup.particles[0].velocity.x) < epsilon && direction == "left") {
if (lastClipAction != "stillLeft"){
lastClipAction = "stillLeft";
change = true;
}
}
else if (particleGroup.particles[0].velocity.y > 0 && Math.abs(particleGroup.particles[0].velocity.x) < epsilon) {
if (lastClipAction != "down"){
lastClipAction = "down";
change = true;
}
}
else if (particleGroup.particles[0].velocity.y < 0 && Math.abs(particleGroup.particles[0].velocity.x) < epsilon) {
if (lastClipAction != "up"){
lastClipAction = "up";
change = true;
}
}
else if (particleGroup.particles[0].velocity.x > 0) {
if (lastClipAction != "right") {
lastClipAction = "right";
direction = "right";
change = true;
}
}
else if (particleGroup.particles[0].velocity.x < 0) {
if (lastClipAction != "left"){
lastClipAction = "left";
direction = "left";
change = true;
}
}
//If the movie clip has changed, swap the old one back into the all clips library and get the new one.
if (change) {
//set flip to false whenever there is a change in movie clip
flipped = false;
//if the movie clip was flipped before, this should flip it
//back to normal
flip();
//remove movie clip from the scene
game.removeChild(playingMovieClip);
//check it back into the movie clip library
allClips.addChild(playingMovieClip);
//add the movie clip into the scene
playingMovieClip = MovieClip(allClips.getChildByName(actionToClip[lastClipAction + "Name"]));
game.addChild(playingMovieClip);
}
//Flip if needed
flip();
//set it to true so that it won't be constantly flipped.
flipped = true;
//set movie clip to be center over the main particle
playingMovieClip.x = particleGroup.particles[0].center.x;
playingMovieClip.y = particleGroup.particles[0].center.y;
}
private function flip():void {
//If a transformation is required, then do so
if (actionToClip[lastClipAction + "H"]=="1" && !flipped){
flipHorizontal(playingMovieClip);
}
if (actionToClip[lastClipAction + "V"]=="1" && !flipped){
flipVertical(playingMovieClip);
}
}
해결책
문제의 코드가 여기에 있다고 생각합니다.
//If the movie clip has changed, swap the old one back into the all clips library and get the new one.
if (change) {
//set flip to false whenever there is a change in movie clip
flipped = false;
//if the movie clip was flipped before, this should flip it
//back to normal
flip();
//remove movie clip from the scene
game.removeChild(playingMovieClip);
//check it back into the movie clip library
allClips.addChild(playingMovieClip);
//add the movie clip into the scene
playingMovieClip = MovieClip(allClips.getChildByName(actionToClip[lastClipAction + "Name"]));
game.addChild(playingMovieClip);
}
//Flip if needed
flip();
문제는 여기서 더블 플립을하고 있다는 것입니다. 이것은 실제로 변화에서 클립을 바꾸고 있는지 확인합니다. 예를 들어 올바른 달리기에서 오른쪽으로 가면. 오른쪽 달리기에서 왼쪽 달리기로 가면 잘못됩니다. 그들은 같은 클립이기 때문에이 상황에서 두 번의 뒤집기를 끝내게됩니다. 이것은 문 워크 행동을 일으킨다 :-).
이 논리를 정리하고 뒤집기를 재설정하는 방법을 제공하는 것이 좋습니다. 원래 방향으로 돌아가는 대신 클립 상태를 보장 할 수 있도록 다시 재설정하십시오.