سؤال

وأنا أعمل حاليا على صغيرة لطيفة محرك اللعبة 2D في AS3. يمكنك تحميل حتى في مختلف مقاطع فيلم فلاش من خلال XML لمختلف الرسوم المتحركة. واحدة من السمات كما يسمح لك الوجه الرسوم المتحركة عند أداء عمل معين. وبهذه الطريقة يمكن أن يكون 1 حيوية لكلا اليمين واليسار (كالعادة). لدي مصفوفة التحويل يعمل بشكل صحيح. ومع ذلك، أعتقد أن منطق الأشياء التقليب ذهابا وإيابا غير صحيح. والنتيجة هي أن الرسوم المتحركة الخطأ سوف تلعب في الوقت الخطأ. أنا قررت أن تجعل من الرسوم المتحركة لعبت على أساس سرعة الجسم المتحرك وليس عند الضغط على المفاتيح منذ لدي عناصر الفيزياء المعنية.

وهنا هو ارتباط إلى لعبة في وضعها الحالي: http://parrisstudios.com/Game_Design/ gameEngineDemo /

والمسألة هي أساسا أن الرسوم المتحركة تلعب في بعض الأحيان غير صحيحة، أو لا تلعب عندما ينبغي.

وهنا هو رمز بلادي لالتقليب (اسمحوا لي أن أعرف ما يفكر يا رفاق): ملاحظة: متغير الاتجاه هو الاتجاه الأخير يواجه حرف (اليمين أو اليسار في هذه الحالة، يتم وصفها لاحقا في التعليمات البرمجية)

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();

والمشكلة هي أن تقومون به الوجه المزدوج هنا. هذا يعمل العثور على إذا كنت في الواقع تغيير لقطات من التغيير. على سبيل المثال إذا كنت تذهب من الترشح الحق في الوقوف الحق. وغني عن الخطأ عندما تذهب من حق تشغيل لتشغيلها نقاط. لأنها هي نفس مقطع انقلبت فقط لأنك في نهاية المطاف القيام اثنين تقلب في هذه الحالة. يؤدي هذا السلوك التمشي على سطح القمر: -)

وأود أن أقترح تنظيف هذا المنطق، وتوفير وسيلة لإعادة التقليب. بدلا من التقليب إلى التوجه الأصلي، إعادة تعيين إلى ذلك حتى تتمكن من ضمان الدولة للمقطع.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top