AIDE

  • Replies:1
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Jun 19, 2014 10:53:06 PM via Website

error in line this.scene.registerUpdateHandler(physicsWorld);

method org.andengine.entity.Entity.registerUpdateHandler(org.andengine.engine.handler.IUpdateHandler) in org.andengine.entity.scene.Scene cannot be applied to '( org.anddev.andengine.extension.physics.box2d.PhysicsWorld)'

package com.Red.ball;

import android.hardware.;
import org.andengine.engine.camera.
;
import org.andengine.engine.options.;
import org.andengine.engine.options.resolutionpolicy.
;
import org.andengine.entity.scene.;
import org.andengine.entity.scene.background.
;
import org.andengine.entity.sprite.;
import org.andengine.opengl.texture.atlas.bitmap.
;
import org.andengine.opengl.texture.region.;
import org.andengine.ui.activity.
;

import org.andengine.engine.camera.Camera;
import com.badlogic.gdx.physics.box2d.;
import org.andengine.entity.primitive.
;
import org.andengine.util.color.;
import org.jbox2d.dynamics.World;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;
import org.anddev.andengine.extension.physics.box2d.
;
import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.engine.handler.runnable.RunnableHandler;
import com.badlogic.gdx.math.;
import org.anddev.andengine.extension.physics.box2d.util.Vector2Pool;
import org.anddev.andengine.entity.shape.
;
import org.jbox2d.p5.;
import org.andengine.engine.handler.
;

public class MainActivity extends BaseGameActivity
{

    Scene scene;
    protected final static int CAMERA_WIDTH = 800;
    protected final static int CAMERA_HEIGHT = 480;
    BitmapTextureAtlas playerTexture;
    ITextureRegion playerTextureRegion;
    PhysicsWorld physicsWorld;
    Body body;

    @Override
    public EngineOptions onCreateEngineOptions()
        {
            // TODO: Implement this method
            Camera mCamera = new Camera (0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
            EngineOptions options = new EngineOptions (true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy (CAMERA_WIDTH, CAMERA_HEIGHT), mCamera);
            return options;
        }

    @Override
    public void onCreateResources(OnCreateResourcesCallback p1) throws Exception
        {
            // TODO: Implement this method
            loadGfx ();
            p1.onCreateResourcesFinished ();
        }

    public void loadGfx()
        {
            // TODO: Implement this method
            BitmapTextureAtlasTextureRegionFactory.setAssetBasePath ("gfx/");
            playerTexture = new BitmapTextureAtlas (getTextureManager (), 64, 64);
            playerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset (playerTexture, this, "red_ball.png", 0, 0);
            playerTexture.load ();
        }

    @Override
    public void onCreateScene(OnCreateSceneCallback p1) throws Exception
        {
            // TODO: Implement this method
            this.scene = new Scene();
            this.scene.setBackground(new Background(255,0,0));
            physicsWorld = new PhysicsWorld(new Vector2(0,SensorManager.GRAVITY_EARTH),false);
            this.scene.registerUpdateHandler(physicsWorld);
            createWalls ();
            p1.onCreateSceneFinished (this.scene);
        }

    @Override
    public void onPopulateScene(Scene p1, OnPopulateSceneCallback p2) throws Exception
        {
            // TODO: Implement this method
            Sprite sPlayer = new Sprite (CAMERA_WIDTH / 2, CAMERA_HEIGHT / 2, playerTextureRegion, this.mEngine.getVertexBufferObjectManager ());
            sPlayer.setRotation(45.0f);
            FixtureDef PLAYER_FIX = PhysicsFactory.createFixtureDef (10.0F, 1.0F, 0.0F);
            body = PhysicsFactory.createCircleBody (physicsWorld, sPlayer, BodyDef.BodyType.DynamicBody, PLAYER_FIX);
            this.scene.attachChild (sPlayer);
            physicsWorld.registerPhysicsConnector (new PhysicsConnector (sPlayer,body,true,false));
            p2.onPopulateSceneFinished ();
        }

    private void createWalls()
        {
            FixtureDef WALL_FIX = PhysicsFactory.createFixtureDef (0.0f, 0.0f, 0.0f);
            PhysicsFactory.createFixtureDef (0.0f, 0.0f, 0.0f);
            Rectangle ground = new Rectangle (0, CAMERA_HEIGHT - 15, CAMERA_WIDTH, 15, this.mEngine.getVertexBufferObjectManager ());
            ground.setColor (new Color (15, 50, 0));
            PhysicsFactory.createBoxBody (physicsWorld, ground, BodyDef.BodyType.StaticBody, WALL_FIX);
            this.scene.attachChild (ground);

        }
}
  • Forum posts: 708

Jun 20, 2014 4:36:41 AM via Website

Britton Brown

    @Override
public void onCreateScene(OnCreateSceneCallback p1) throws Exception
    {
        // TODO: Implement this method
        this.scene = new Scene();
        this.scene.setBackground(new Background(255,0,0));
        physicsWorld = new PhysicsWorld(new Vector2(0,SensorManager.GRAVITY_EARTH),false);
        this.scene.registerUpdateHandler(physicsWorld);
        createWalls ();
        p1.onCreateSceneFinished (this.scene);

i thing this is the problem

**physicsWorld = new PhysicsWorld(new Vector2(0,SensorManager.GRAVITY_EARTH),false);
to
physicsWorld = new PhysicsWorld(new Vector2( 0,SensorManager.GRAVITY_EARTH), false); <----- need some space **

need space after vector2( 0 and ), false

also try vector2(0 and ), false

— modified on Jun 20, 2014 4:40:10 AM

Ready To Help You.