本文介绍了在触摸像水果忍者或素食Samurai在和发动机绘图线效应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提请在AndEngine一行以类似水果忍者或素食武士刀片的效果。
谁能帮我?并给样品code?

I want to draw a line in AndEngine with the effect of a blade similar to Fruit Ninja or Veggie Samurai. Can anyone help me? and give a sample code?

推荐答案

也许,我迟到了,但希望这能帮助别人。

Maybe, I am late but hope this will help others.

    @Override
    public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {

        final float touchX = pSceneTouchEvent.getX();
        final float touchY = pSceneTouchEvent.getY();

        if (pSceneTouchEvent.isActionDown()) {
            initTrail(touchX, touchY);
            swipeGestureSprite = addSwipeSprite(touchX, touchY);
        } else if (pSceneTouchEvent.isActionMove()) {

            moveTrail(pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), 0);

            if (swipeGestureSprite != null) {
                swipeGestureSprite.setX(touchX);
                swipeGestureSprite.setY(touchY);
            }
        } else if (pSceneTouchEvent.isActionUp()) {

            mScene.detachChild(this.particleSystem);

            if (swipeGestureSprite != null) {
                this.mScene.detachChild(swipeGestureSprite);
                swipeGestureSprite = null;
            }

            return true;
        }

        return false;
    }




    private void initTrail(float mX, float mY) {
        this.particleEmitter = new PointParticleEmitter(mX, mY);
        this.particleSystem = new SpriteParticleSystem(particleEmitter, 1000, 1000, 5000, this.mRibbon, this.getVertexBufferObjectManager());
        particleSystem.addParticleInitializer(new BlendFunctionParticleInitializer<Sprite>(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE));
        particleSystem.addParticleInitializer(new ExpireParticleInitializer<Sprite>(1));
        particleSystem.addParticleModifier(new ScaleParticleModifier<Sprite>(0, 1, 1, 0f));
        particleSystem.addParticleModifier(new AlphaParticleModifier<Sprite>(0, 1, 1, 0));
        this.mScene.attachChild(particleSystem);
    }


private void moveTrail(float trailX, float trailY, int count) {
        if (particleEmitter == null) {
            initTrail(trailX, trailY);
        }

        particleEmitter.setCenter(trailX, trailY);
    }

这篇关于在触摸像水果忍者或素食Samurai在和发动机绘图线效应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 05:11