andengine:onCreateResoures函数未调用

时间:2015-02-28 16:14:29

标签: andengine

我正在使用以下代码。但是,当我运行应用程序时,不会调用onCreateResources函数。我在该函数中创建的toast永远不会被提升。我只得到一个黑屏。

package com.example.tankcontrol;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.texture.Texture;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.atlas.bitmap.BuildableBitmapTextureAtlas;
import org.andengine.opengl.texture.bitmap.BitmapTexture;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.ui.activity.BaseGameActivity;
import org.andengine.ui.activity.SimpleBaseGameActivity;

import android.widget.Toast;


public class GameActivity extends SimpleBaseGameActivity{

    private final int CAMERA_WIDTH = 800;
    private final int CAMERA_HEIGHT = 480;

    BitmapTextureAtlas playerTA;
    ITextureRegion playerTR;
    Scene scene;

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

    public void loadGfx(){
        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx");

        playerTA = new BitmapTextureAtlas(getTextureManager() , 64 , 64);
        playerTA.load();
        playerTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(playerTA, this , "chutiya.png" , 0 , 0);

    }

    @Override
    protected void onCreateResources() {
        Toast.makeText(this, "I am here!", Toast.LENGTH_SHORT).show();
        loadGfx();      
    }

    @Override
    protected Scene onCreateScene() {
        scene = new Scene();        
        Sprite rocketS = new Sprite(CAMERA_WIDTH/2, CAMERA_HEIGHT/2, playerTR, this.mEngine.getVertexBufferObjectManager());
        scene.attachChild(rocketS);

        return scene;
    }

}

提前感谢任何帮助。感谢:)

1 个答案:

答案 0 :(得分:0)

资产基础路径应该以“/”结尾,所以试试这个:

BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");

你的logcat上可能有关于此的消息。