4

当用户在屏幕上交换手指时,我想显示一个三角形条。我不确定如何使用 AndEngine、使用粒子系统或使用 sprite 或使用 Triangle Strip 算法来做到这一点......

我没有写任何代码,因为我很震惊该做什么。我正在上传图片,请分享您的想法。

三角带

更新

有人在 Iphone 中完成了此操作,但不幸的是我不熟悉语言语法请帮助我理解此代码的算法https://github.com/hiepnd/CCBlade

**我想要的效果** 水果忍者效果

完整的 Android 项目下载

http://www.andengine.org/forums/resources/complete-runnable-project/1301

我已经完成了这段代码,但无法获得预期的效果......

    package org.az.algo.examples;

import javax.microedition.khronos.opengles.GL10;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.particle.ParticleSystem;
import org.anddev.andengine.entity.particle.emitter.RectangleParticleEmitter;
import org.anddev.andengine.entity.particle.initializer.AlphaInitializer;
import org.anddev.andengine.entity.particle.initializer.ColorInitializer;
import org.anddev.andengine.entity.particle.initializer.GravityInitializer;
import org.anddev.andengine.entity.particle.initializer.RotationInitializer;
import org.anddev.andengine.entity.particle.modifier.AlphaModifier;
import org.anddev.andengine.entity.particle.modifier.ColorModifier;
import org.anddev.andengine.entity.particle.modifier.ExpireModifier;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.Scene.IOnSceneTouchListener;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.util.FPSLogger;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;

import android.view.ViewGroup.MarginLayoutParams;
import android.widget.Toast;


public class ParticleSystemSimpleExample extends BaseExample {
    // ===========================================================
    // Constants
    // ===========================================================

    private static final int CAMERA_WIDTH = 720;
    private static final int CAMERA_HEIGHT = 480;

    // ===========================================================
    // Fields
    // ===========================================================

    private Camera mCamera;
    private BitmapTextureAtlas mBitmapTextureAtlas;
    private TextureRegion mParticleTextureRegion;
    private BitmapTextureAtlas mBitmapTextureAtlasStreak;
    private TextureRegion mStreadTextureRegion;

    private Sprite[] mSprite = new Sprite[20];
    private int mIndex = 0;

    // ===========================================================
    // Constructors
    // ===========================================================

    // ===========================================================
    // Getter & Setter
    // ===========================================================

    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    @Override
    public Engine onLoadEngine() {
        Toast.makeText(this, "Touch the screen to move the particlesystem.", Toast.LENGTH_LONG).show();
        this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
    }

    @Override
    public void onLoadResources() {
        this.mBitmapTextureAtlas = new BitmapTextureAtlas(32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
        this.mParticleTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "gfx/particle_point.png", 0, 0);

        this.mBitmapTextureAtlasStreak = new BitmapTextureAtlas(128, 16, TextureOptions.BILINEAR_PREMULTIPLYALPHA);     
        this.mStreadTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlasStreak, this, "gfx/streak1.png", 0, 0);

        this.mEngine.getTextureManager().loadTextures(this.mBitmapTextureAtlas, this.mBitmapTextureAtlasStreak);
    }

    @Override
    public Scene onLoadScene() {
        this.mEngine.registerUpdateHandler(new FPSLogger());

        final Scene scene = new Scene();

//      final CircleOutlineParticleEmitter particleEmitter = new CircleOutlineParticleEmitter(CAMERA_WIDTH * 0.5f, CAMERA_HEIGHT * 0.5f + 20, 80);
        final RectangleParticleEmitter particleEmitter = new RectangleParticleEmitter(CAMERA_WIDTH * 0.5f, CAMERA_HEIGHT * 0.5f, 5f,5f);

//      final PointParticleEmitter particleEmitter = new PointParticleEmitter(10, 10);      
        final ParticleSystem particleSystem = new ParticleSystem(particleEmitter, 100, 100, 1000, this.mParticleTextureRegion);
        particleSystem.setParticlesSpawnEnabled(false);     

        scene.setOnSceneTouchListener(new IOnSceneTouchListener() {
            @Override
            public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {               

                if(pSceneTouchEvent.getAction() == TouchEvent.ACTION_MOVE){                 

                    particleSystem.setParticlesSpawnEnabled(true);                  
                    particleEmitter.setCenter(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());

                    mSprite[getIndex()].setPosition(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
                    mSprite[getIndex()].setVisible(true);

                }else if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP){

                    particleSystem.setParticlesSpawnEnabled(false);
                    hideAll();

                }else if(pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN){

                    particleSystem.reset();

                }

                return true;
            }
        });     

        particleSystem.addParticleInitializer(new ColorInitializer(1, 0, 0));
        particleSystem.addParticleInitializer(new AlphaInitializer(0));
        particleSystem.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
//      particleSystem.addParticleInitializer(new VelocityInitializer(-2, 2, -20, -10));
        particleSystem.addParticleInitializer(new GravityInitializer());

//      particleSystem.addParticleModifier(new ScaleModifier(0.5f, 1.0f, 0, 1.5f));
        particleSystem.addParticleModifier(new ColorModifier(1, 1, 0, 0.5f, 0, 0, 0, 3));
        particleSystem.addParticleModifier(new ColorModifier(1, 1, 0.5f, 1, 0, 1, 4, 6));
        particleSystem.addParticleModifier(new AlphaModifier(0, 1, 0, 0.5f));
        particleSystem.addParticleModifier(new AlphaModifier(1, 0, 2.5f, 3.5f));
        particleSystem.addParticleModifier(new ExpireModifier(6, 6f));

        scene.attachChild(particleSystem);


        for(int i = 0; i < mSprite.length; i++){
            mSprite[i] = new Sprite(-20, 0, mStreadTextureRegion);
            mSprite[i].setVisible(false);
            scene.attachChild(mSprite[i]);
        }





        return scene;
    }

    @Override
    public void onLoadComplete() {

    }


    private int getIndex(){
        if(mIndex >= mSprite.length -1){
            mIndex = 0;
        }
        System.out.println("Index ........ "+mIndex);
        return mIndex++;
    }

    private void hideAll(){
        for(int i = 0; i<mSprite.length; i++){
            mSprite[i].setVisible(false);
            mSprite[i].setPosition(-CAMERA_WIDTH, 0);
        }
    }
    // ===========================================================
    // Methods
    // ===========================================================

    // ===========================================================
    // Inner and Anonymous Classes
    // ===========================================================
}

我在这段代码中使用的图像

我与此代码一起使用的图像也附上了

更新

实现了部分效果..但是快速刷卡的问题..所有完整的项目都在这里上传http://www.andengine.org/forums/post31772.html#p31772

部分效应

4

1 回答 1

1

这是 LibGDX 中的一个解决方案。它使用 GL_TRIANGLE_STRIP。

https://github.com/mattdesl/lwjgl-basics/wiki/LibGDX-Finger-Swipe

最终解决方案使用两个三角形条带和一个自定义 texCoord 属性,允许我们使用查找纹理来实现虚假(但有效)的抗锯齿。更有效/更灵活的抗锯齿将使用着色器和单个三角形条。使用顶点属性 -1.0 作为顶部,1.0 作为底部边缘,1.0 作为提示。然后在片段着色器中,使用 abs() - 所以 0.0 表示“中心”,1.0 表示“边缘”。

像这样的东西:

    color.a *= smoothstep(0.0, 2./thickness, 1.0-abs(vTexCoord.t));
于 2013-04-18T22:41:25.703 回答