4

私は使用するのが初めてで、タッチAndEngineにスプライトのサイズを大きくしようとしています。ある程度は機能しますが、突然このエラーが発生することがあります。何か案は?この時点で、十分なテキストが必要なので、質問を投稿させてください。誰かがさらに情報を必要とする場合は、お知らせください。投稿します。私はアイデアに対して非常にオープンです。より良い方法がある場合、または私のコードに問題がある場合は、お知らせください。この時点で、物理学の世界は機能しません。

06-17 22:44:25.809: E/AndroidRuntime(20526): FATAL EXCEPTION: UpdateThread
06-17 22:44:25.809: E/AndroidRuntime(20526): java.lang.NullPointerException
06-17 22:44:25.809: E/AndroidRuntime(20526):    at org.andengine.util.modifier.ModifierList.onUpdate(ModifierList.java:66)
06-17 22:44:25.809: E/AndroidRuntime(20526):    at org.andengine.entity.Entity.onManagedUpdate(Entity.java:1392)
06-17 22:44:25.809: E/AndroidRuntime(20526):    at org.andengine.entity.Entity.onUpdate(Entity.java:1167)
06-17 22:44:25.809: E/AndroidRuntime(20526):    at org.andengine.entity.Entity.onManagedUpdate(Entity.java:1402)
06-17 22:44:25.809: E/AndroidRuntime(20526):    at org.andengine.entity.scene.Scene.onManagedUpdate(Scene.java:284)
06-17 22:44:25.809: E/AndroidRuntime(20526):    at org.andengine.entity.Entity.onUpdate(Entity.java:1167)
06-17 22:44:25.809: E/AndroidRuntime(20526):    at org.andengine.engine.Engine.onUpdateScene(Engine.java:591)
06-17 22:44:25.809: E/AndroidRuntime(20526):    at org.andengine.engine.Engine.onUpdate(Engine.java:586)
06-17 22:44:25.809: E/AndroidRuntime(20526):    at org.andengine.engine.Engine.onTickUpdate(Engine.java:548)
06-17 22:44:25.809: E/AndroidRuntime(20526):    at org.andengine.engine.Engine$UpdateThread.run(Engine.java:820)

これは私のコードです:

public class TestGFX2Activity extends SimpleBaseGameActivity implements IAccelerationListener, IOnSceneTouchListener {
/** Called when the activity is first created. */

    private static final int CAMERA_WIDTH = 720;
    private static final int CAMERA_HEIGHT = 480;
    private final FixtureDef FIXTURE_DEF = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);
    private BitmapTextureAtlas mBitmapTextureAtlas;
    private TextureRegion circleTR;
    private Scene scene;
    boolean down=false;
    float scale;
    final float growRate = (float) .0001;

    private PhysicsWorld mPhysicsWorld;

    @Override
    public EngineOptions onCreateEngineOptions() {
        final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
    }

    @Override
    public void onCreateResources() {

    /*Line 66*/ this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(), 64, 128, TextureOptions.BILINEAR); //Line 66
        this.circleTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "circle.png", 0, 0); // 64x32

        this.mBitmapTextureAtlas.load();
    }

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

        this.scene = new Scene();
        this.scene.setBackground(new Background(0, 1, 0));
        Log.e("Tag","Got to background");
        this.scene.setOnSceneTouchListener(this);

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

        final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager();
        final Rectangle ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2, vertexBufferObjectManager);
        final Rectangle roof = new Rectangle(0, 0, CAMERA_WIDTH, 2, vertexBufferObjectManager);
        final Rectangle left = new Rectangle(0, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);
        final Rectangle right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);

        final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof, BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef);
        PhysicsFactory.createBoxBody(this.mPhysicsWorld, right, BodyType.StaticBody, wallFixtureDef);

        this.scene.attachChild(ground);
        this.scene.attachChild(roof);
        this.scene.attachChild(left);
        this.scene.attachChild(right);

        this.scene.registerUpdateHandler(this.mPhysicsWorld);

        return this.scene;
    }

    @Override
    public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
        Sprite face;
        Body body;
        scale = 1;

        if(this.mPhysicsWorld != null) {
            if(pSceneTouchEvent.isActionDown()) {
                //this.addFace(pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
                down = true;
                face = new Sprite(pSceneTouchEvent.getX(), pSceneTouchEvent.getY(), circleTR, this.getVertexBufferObjectManager());
                body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, FIXTURE_DEF);

                new Thread(new Grow(face)).start();

                return true;
            } else if(pSceneTouchEvent.isActionUp()){
                down = false;
            }
        }
        return false;
    }

    @Override
    public void onAccelerationAccuracyChanged(final AccelerationData pAccelerationData) {

    }

    @Override
    public void onAccelerationChanged(final AccelerationData pAccelerationData) {
        final Vector2 gravity = Vector2Pool.obtain(pAccelerationData.getX(), pAccelerationData.getY());
        this.mPhysicsWorld.setGravity(gravity);
        Vector2Pool.recycle(gravity);
    }

    @Override
    public void onResumeGame() {
        super.onResumeGame();

        this.enableAccelerationSensor(this);
    }

    @Override
    public void onPauseGame() {
        super.onPauseGame();

        this.disableAccelerationSensor();
    }

    private class Grow implements Runnable{
        Sprite s;
        ScaleModifier mod;

        public Grow(Sprite sprite){
            s = sprite;
            scene.attachChild(s);
        }
        public void run(){
            while(down){
                //Log.e("Tag",Float.toString(scale));
                s.clearEntityModifiers();
                mod = new ScaleModifier((float) .1,scale,scale+growRate);
                scale+=growRate;
                s.registerEntityModifier(mod);
                /*s.detachSelf();
                s.setScale(scale);
                scale += growRate;
                try{
                    Thread.sleep(100);
                }catch(InterruptedException e){}
                scene.attachChild(s);*/
            }
        }
    }
}
4

2 に答える 2

2

これを別のスレッドで呼び出す代わりに、おそらくこれを呼び出す必要があります

new Grow(face)).start();

runOnUpdate()ブロック内

myActivity.runonUpdateThread(new Grow(face)));
于 2012-06-19T16:44:01.787 に答える
0

交換するだけ

new Thread(new Grow(face)).start();

TestGFX2Activity.runonUpdateThread(new Grow(face)));
于 2012-11-03T20:13:37.810 に答える