Java 安发动机黑匣子精灵加载不正确
嗨,我是android开发新手,我有一些问题,我的精灵加载不正确。在我开始添加AnalogOnScreenControl之前,我的代码非常好,现在我所有的精灵包括AnalogOnScreenControl都显示了一个黑框。控件上的nub也是黑色的。唯一不黑的东西是黑土地和土地本身。这是我的密码:Java 安发动机黑匣子精灵加载不正确,java,android,andengine,sprite,Java,Android,Andengine,Sprite,嗨,我是android开发新手,我有一些问题,我的精灵加载不正确。在我开始添加AnalogOnScreenControl之前,我的代码非常好,现在我所有的精灵包括AnalogOnScreenControl都显示了一个黑框。控件上的nub也是黑色的。唯一不黑的东西是黑土地和土地本身。这是我的密码: public class MainActivity extends BaseGameActivity { Scene scene; protected static final int CAMERA_
public class MainActivity extends BaseGameActivity {
Scene scene;
protected static final int CAMERA_WIDTH = 256;
protected static final int CAMERA_HEIGHT = 144;
BitmapTextureAtlas playerTexture;
ITextureRegion playerTextureRegion;
PhysicsWorld physicsWorld;
private Camera mCamera;
private TextureRegion controlTextureRegion;
private TextureRegion controlNubTextureRegion;
@Override
public EngineOptions onCreateEngineOptions() {
// TODO Auto-generated method stub
mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); // Camera
// Defines
// How
// we
// see
// the
// screen
EngineOptions options = new EngineOptions(true,
ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(
CAMERA_WIDTH, CAMERA_HEIGHT), mCamera); // set screen
// orientation
// and camera to
// engine
// options
return options; // return those options
}
@Override
public void onCreateResources(
OnCreateResourcesCallback pOnCreateResourcesCallback)
throws Exception {
// TODO Auto-generated method stub
loadGfx(); // load graphics
pOnCreateResourcesCallback.onCreateResourcesFinished(); // add callback
}
private void loadGfx() {
// TODO Auto-generated method stub
BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
playerTexture = new BitmapTextureAtlas(getTextureManager(), 88, 23);
playerTextureRegion = BitmapTextureAtlasTextureRegionFactory
.createFromAsset(playerTexture, getBaseContext(),
"mrsaispritesheet.png", 0, 0);
this.controlTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(new BuildableBitmapTextureAtlas(getTextureManager(), 32, 32), this.getAssets(), "basecontrol.png", false);
this.controlNubTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(new BuildableBitmapTextureAtlas(getTextureManager(), 32, 32), this.getAssets(), "controlnub.png", false);
}
@Override
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
throws Exception {
// TODO Auto-generated method stub
final AnalogOnScreenControl control = new AnalogOnScreenControl(0,
CAMERA_HEIGHT - this.controlTextureRegion.getHeight(),
this.mCamera, this.controlTextureRegion,
this.controlNubTextureRegion, 200,
getVertexBufferObjectManager(),
new IAnalogOnScreenControlListener() {
@Override
public void onControlChange(
BaseOnScreenControl pBaseOnScreenControl,
float pValueX, float pValueY) {
// TODO Auto-generated method stub
}
@Override
public void onControlClick(
AnalogOnScreenControl pAnalogOnScreenControl) {
// TODO Auto-generated method stub
}
});
this.scene = new Scene();
this.scene.setBackground(new Background(0, 125, 58));
physicsWorld = new PhysicsWorld(new Vector2(0,
SensorManager.GRAVITY_MOON), false);
this.scene.registerUpdateHandler(physicsWorld);
createWalls();
this.scene.setChildScene(control);
pOnCreateSceneCallback.onCreateSceneFinished(this.scene);
}
private void createWalls() {
// TODO Auto-generated method stub
FixtureDef WALL_FIX = 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, BodyType.StaticBody,
WALL_FIX);
this.scene.attachChild(ground);
}
@Override
public void onPopulateScene(Scene pScene,
OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
// TODO Auto-generated method stub
Sprite sPlayer = new Sprite(CAMERA_WIDTH / 2, CAMERA_HEIGHT / 2,
playerTextureRegion,
this.mEngine.getVertexBufferObjectManager());
final FixtureDef PLAYER_FIX = PhysicsFactory.createFixtureDef(10.0f,
0.0f, 0.0f);
Body body = PhysicsFactory.createBoxBody(physicsWorld, sPlayer,
BodyType.DynamicBody, PLAYER_FIX);
this.scene.attachChild(sPlayer);
physicsWorld.registerPhysicsConnector(new PhysicsConnector(sPlayer,
body, true, false));
pOnPopulateSceneCallback.onPopulateSceneFinished();
}
}
知道我做错了什么吗?特别推荐帮助:创建纹理后,需要调用加载函数来加载纹理。像这样: playerTexture.load()
这一行必须在创建它们之后您需要在创建它们之后调用加载函数来加载纹理。像这样: playerTexture.load()
这条线必须是在创建它们之后是的,它解决了我的一个问题我的精灵现在出现了,但我的模拟控件没有,它不允许我使用load()使用类似的texturesok,我弄乱了一些代码,我破坏了Anengine o.0,我的场景不再像以前那样加载,甚至使用了我粘贴在这里的代码,这在某种程度上是可行的。。。当我在模拟器上运行它时,我看到了白板和黑屏-编辑-nvm,我想问题是我设置的textureatlas对于实际图像太小了,我仍然无法加载模拟纹理:/yeah,这解决了我的一个问题我的sprite现在出现了,但我的模拟控件没有,它不允许我使用load()使用类似的texturesok,我弄乱了一些代码,我破坏了Anengine o.0,我的场景不再像以前那样加载,甚至使用了我粘贴在这里的代码,这在某种程度上是可行的。。。当我在模拟器上运行它时,我看到白板和黑屏-编辑-nvm,我想问题是我将textureatlas设置得太小,无法加载实际图像的模拟纹理:/