AndEngine can not shows sprite - java

In Android Studio, I'm trying to create a sprite with AndEngine, but it failed to display the sprite, it only shows a black screen. I'v searched and tried different methods for hours.
Here is the structure:
-myApplication
-andEngine
-app
-res
-drawable
-stand.png
Here is the codes:
#Override
public void onCreateResources() {
this.mBitmapTextureAtlas = new BitmapTextureAtlas(getTextureManager(), 30, 30, TextureOptions.DEFAULT);
mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromResource(mBitmapTextureAtlas, this, R.drawable.stand, 0, 0);
mBitmapTextureAtlas.load();
}
#Override
public Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
this.mMainScene = new Scene();
this.mMainScene.setBackground(new Background(1, 1, 1));
final Sprite oPlayer = new Sprite(100, 100, mPlayerTextureRegion, getVertexBufferObjectManager());
this.mMainScene.attachChild(oPlayer);
return this.mMainScene;
}
Any help will be appreciated
Thanks.

Check your logcat it's may be an exception.
As I check your code, this line may be reason of exception.
mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromResource(mBitmapTextureAtlas, this, R.drawable.stand, 0, 0);
Check dimension of your stand.png it should not greater than 30*30 otherwise pass greater value, when you're creating object of BitmapTextureAtlas.

Related

addAction always rotates the actor origin 0,0, why?

My code (libgdx):
#Override
public void create () {
stage = new Stage();
Gdx.input.setInputProcessor(stage);
texture = new Texture(Gdx.files.internal("image.png"));
TextureRegion region = new TextureRegion(texture,256,128);
Image actor = new Image(region);
actor.setPosition(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
actor.setOrigin(actor.getWidth()/2, actor.getHeight()/2);
group = new Group();
group.addActor(actor);
stage.addActor(group);
}
#Override
public void render () {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
stage.act(Gdx.graphics.getDeltaTime());
stage.draw();
if(Gdx.input.isButtonPressed(Input.Buttons.LEFT)){
if(Gdx.input.getX() < Gdx.graphics.getWidth() / 2)
{
group.addAction(parallel(rotateBy(1,1)));
}
else
{
group.addAction(parallel(rotateBy(-1,1)));
}
}
}
Hi, i use LibGdx and my problem is that I would like to rotate on the same object , but when I start the rotation , I turn around point 0.0 in the lower left.
I can not understand why ...
someone can explain how to do ?
Thank You
you're rotating the group not the actor
so try this
set the origin of the group to
group.setOrigin(group.getWidth()/2, group.getHeight()/2);
September origin of the group not the actor you add the group to this case:
group.addActor(actor);
group.setPosition(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
group.setOrigin(group.getWidth()/2, group.getHeight()/2);
stage.addActor(group);
secondly, that API're using? or is the method, parallel or rotateBy created by you, anyway you can use this haver works for you as you pretend.
group.addAction(Actions.parallel(Actions.rotateBy(1,1)));
P.S: if it works, the response of Kareem Hammad was my first answer, haha, but already had published.

Inherent damping in LibGdx DistanceJoint

I am trying to learn LibGdx and simulate a Spring Mass connection. I am able to define everything correctly and run the simulation but the spring defined seems to have an inherent damping dur to which the oscillations of the dynamic body die out.
I have set the damping ratio to zero but still get the decay.
Can some one explain if this is a bug or am i doing something wrong.
Below are my codes.
SpringMass class:
public class SpringMass implements Screen {
private void createScene() {
trackers = new ArrayList<Tracker>();
isTracking = new ArrayList<Boolean>();
world.setGravity(new Vector2(0, 0));
Vector2 boxPos = new Vector2(200, 200);
staticBox = new Box(world, boxPos, 10, 10, false);
dynBox = new Box(world, boxPos.add(150, 0), 10, 10, true);
new Spring(staticBox.body, dynBox.body, world, 100, 0.8f, 0);
}
}
Spring Class:
public class Spring {
private DistanceJointDef distanceJointDef;
public Spring(Body bodyA, Body bodyB, World world, float length, float stiffness, float dampingRatio) {
distanceJointDef = new DistanceJointDef();
distanceJointDef.bodyA = bodyA;
distanceJointDef.bodyB = bodyB;
distanceJointDef.length = length*CONSTANTS.WORLD_TO_BOX;
distanceJointDef.frequencyHz = stiffness;
distanceJointDef.dampingRatio=dampingRatio;
world.createJoint(distanceJointDef);
}
}

Rendering complete Tiled Map on Android with LibGdx

I am trying to render a Tiled Map on to an Android device. However, when I test it on my android phone, only the top layer is rendered on to the screen (out of two layers total). Is there a way to fix this? I am using Libgdx as well as Tiled Map Editor.
Below is some of the code for my project which implements the Screen interface. The omitted code is not necessary for the question but can be shown if needed.
public class Play implements Screen {
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.setView(cam);
renderer.render();
/*code ommited*/
renderer.getSpriteBatch().begin();
animateAgent(time);
sr.setProjectionMatrix(cam.combined);
try {
animateBullets(sr);
} catch(IndexOutOfBoundsException e) {}
renderer.getSpriteBatch().end();
}
public void show() {
cam = new OrthographicCamera();
cam.setToOrtho(false);
cam.position.set(0,0,0);
cam.zoom = 8.0f;
cam.update();
map = new TmxMapLoader().load("data/batMap.tmx");
blocked = (TiledMapTileLayer) map.getLayers().get(1);
renderer = new OrthogonalTiledMapRenderer(map);
atlas = new TextureAtlas("data/specOps.txt");
agent = atlas.createSprites("agent");
/* code ommitted */
player = new Player(agent,blocked,bullets);
Gdx.input.setInputProcessor(player);
}
}
Here's how it currently looks:
and here's how it should look:
You are only getting one layer at
blocked = (TiledMapTileLayer) map.getLayers().get(1);
or are you getting the other layer elsewhere?
Try:
map.getLayers().get(0).setVisible(true);
map.getLayers().get(1).setVisible(true);

Unable to display SVG in angengine

I am trying to render a SVG to the screen using andengine, but unfortunately it is not being displayed. Also, I am not getting any exceptions or errors while running the project, thus I'm finding it very hard to debug.
I've had a look at this post but I guess BlackPawnTextureBuilder is not available on GLES2.
I've included part of my code below,
public void onCreateResources(OnCreateResourcesCallback pOnCreateResourcesCallback) throws Exception
{
BuildableBitmapTextureAtlas buildableBitmapTextureAtlas = new BuildableBitmapTextureAtlas(this.getTextureManager(), 2048, 2048, TextureOptions.BILINEAR);
logoSplashITextureRegion = SVGBitmapTextureAtlasTextureRegionFactory.createFromAsset(buildableBitmapTextureAtlas, this, "gfx/BrickRed.svg", 80, 40);
buildableBitmapTextureAtlas.load();
pOnCreateResourcesCallback.onCreateResourcesFinished();
}
public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception
{
logoSplashScene = new Scene();
logoSplashSprite = new Sprite(0, 0, logoSplashITextureRegion,mEngine.getVertexBufferObjectManager())
{
#Override
protected void preDraw(GLState pGLState, Camera pCamera)
{
super.preDraw(pGLState, pCamera);
pGLState.enableDither();
}
};
logoSplashSprite.setPosition((CAMERA_WIDTH - logoSplashSprite.getWidth()) * 0.5f, (CAMERA_HEIGHT - logoSplashSprite.getHeight()) * 0.5f);
logoSplashScene.attachChild(logoSplashSprite);
pOnCreateSceneCallback.onCreateSceneFinished(BrickActivity.logoSplashScene);
}
Am I forgetting something in the code?
Thanks in advance for you help.
I finally managed to make it work.
It seems like as I'm using GLES2 I had to include the following line just before I load my textureAtlas.
buildableBitmapTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
Now my onCreateResources looks like this,
try
{
buildableBitmapTextureAtlas = new BuildableBitmapTextureAtlas(textureManager, 2048, 2048, TextureOptions.BILINEAR);
SVG redBrick = SVGParser.parseSVGFromAsset(assertManager, "gfx/BrickRed.svg");
iTextureRegion = SVGBitmapTextureAtlasTextureRegionFactory.createFromSVG(buildableBitmapTextureAtlas, redBrick, 80, 40);
buildableBitmapTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource, BitmapTextureAtlas>(0, 1, 0));
buildableBitmapTextureAtlas.load();
} catch (TextureAtlasBuilderException e)
{
e.printStackTrace();
}

Drawing Graphics3D in TeeChart

I have a problem using IGraphics3D in a tChart. I can draw any type of picture over the tChart, but when I try to export the image using getImage() to a file the drawings disappear. These pictures also disappears when I click with the mouse over the Chart. I'm using the "com.steema.teechart.tools.Annotation" also and that it works how I want. However I don't know why the Graphics3D have a different behaviour.
I copy the code that shows how I create the drawings:
IGraphics3D grafics = tChart.getGraphics3D();
grafics.getPen().setColor(liniaGrafica.getColorLinia());
Series serie = tChart.getSeries(liniaGrafica.getIndexSerie());
grafics.line(X1, Y, X2, Y);
Can anyone help me with that doubt.
Thank you in advance.
Note you have to call the custom drawing routines at the chartPainted event. Here you have an example:
private static void initializeChart() {
tChart1.getAspect().setView3D(false);
Area area1 = new Area(tChart1.getChart());
area1.fillSampleValues(100);
tChart1.addChartPaintListener(new ChartPaintAdapter() {
#Override
public void chartPainted(ChartDrawEvent e) {
IGraphics3D grafics = tChart1.getGraphics3D();
grafics.getPen().setColor(tChart1.getSeries(0).getColor());
grafics.line(0, 0, 100, 100);
}
});
}

Categories