1

i am new to andengine trying to draw line onscenetouch event

i found a peace of code

private Line[] mLineArray = new Line[10];
private ArrayList<Points> mTouchPoints = new ArrayList<Points>(); 

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

        final Scene scene = new Scene();

    final RectangleParticleEmitter particleEmitter = new          
       RectangleParticleEmitter(CAMERA_WIDTH * 0.5f, CAMERA_HEIGHT * 0.5f, 5f, 5f);
        //scene.setOnSceneTouchListenerBindingEnabled(true);
        scene.setOnSceneTouchListener(new IOnSceneTouchListener() {
            public boolean onSceneTouchEvent(final Scene pScene,
                    final TouchEvent pSceneTouchEvent) {

                if (pSceneTouchEvent.getAction() != TouchEvent.ACTION_DOWN
                        && pSceneTouchEvent.getAction() == TouchEvent.ACTION_MOVE) {

                    mTouchPoints.add(new Points(pSceneTouchEvent.getX(),
                            pSceneTouchEvent.getY()));

                    printSamples(pSceneTouchEvent.getMotionEvent(),
                            particleEmitter);

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

                    hideAllLine();
                    resetTouchList();

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

                }

                return true;
            }
        });

        for (int i = 0; i < mLineArray.length; i++) {
            mLineArray[i] = new Line(0, 0, 0, 0, 10);
            scene.attachChild(mLineArray[i]);
        }
        return scene;
    }

here i am able to draw lines by touching screen in this project but when i import this code to my project

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


        mPhysicsWorld = new PhysicsWorld(new Vector2(0,
                SensorManager.GRAVITY_EARTH), false);


        scene = new Scene();
        scene.setBackground(this.mGrassBackground);
        scene.setOnSceneTouchListener(new IOnSceneTouchListener() {
            public boolean onSceneTouchEvent(final Scene pScene,
                    final TouchEvent pSceneTouchEvent) {

                if (pSceneTouchEvent.getAction() != TouchEvent.ACTION_DOWN
                        && pSceneTouchEvent.getAction() ==    TouchEvent.ACTION_MOVE) {

                    mTouchPoints.add(new Points(pSceneTouchEvent.getX(),
                            pSceneTouchEvent.getY()));

                    printSamples(pSceneTouchEvent.getMotionEvent(),
                            particleEmitter);

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

                //  hideAllLine();
                    //resetTouchList();

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

                }

                return true;
            }
        });


        for (int i = 0; i < mLineArray.length; i++) {
            mLineArray[i] = new Line(0, 0, 0, 0, 10);
            scene.attachChild(mLineArray[i]);
        }

now the problem is the previous piece of code contains Scene onLoadScene() where as my project contains Scene onCreateScene() and now i am unable to attach mLineArray[i] to my project i say Cast argument mLineArray[i] to IEntity. but the same code is working in previous project i am getting error on Cast argument mLineArray[i] to IEntity on scene.attachChild(mLineArray[i]);

4

0 回答 0