Search Results

Search found 93 results on 4 pages for 'andengine'.

Page 3/4 | < Previous Page | 1 2 3 4  | Next Page >

  • How do I scroll in the physical world?

    - by Esteban Quintero
    I am using andengine to make a game where a sprite (player) is going up across the stage, this is my world. 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); /* Create two sprits and add it to the scene. */ this.mScene.setBackground(autoParallaxBackground); this.mScene.attachChild(ground); this.mScene.attachChild(roof); this.mScene.attachChild(left); this.mScene.attachChild(right); this.mScene.registerUpdateHandler(this.mPhysicsWorld); The problem is that if the sprite reaches up and hits the wall, as I scroll here?

    Read the article

  • Thread too slow. Better way to execute code (Android AndEngine)?

    - by rphello101
    I'm developing a game where the user creates sprites with every touch. I then have a thread run to check to see if those sprites collide with any others. The problem is, if I tap too quickly, I cause a null pointer exception error. I believe it's because I'm tapping faster than my thread is running. This is the thread I have: public class grow implements Runnable{ public grow(Sprite sprite){ } @Override public void run() { float radf, rads; //fill radius/stationary radius float fx=0, fy=0, sx, sy; while(down){ if(spriteC[spriteNum].active){ spriteC[spriteNum].sprite.setScale(spriteC[spriteNum].scale += 0.001); if(spriteC[spriteNum].sprite.collidesWith(ground)||spriteC[spriteNum].sprite.collidesWith(roof)|| spriteC[spriteNum].sprite.collidesWith(left)||spriteC[spriteNum].sprite.collidesWith(right)){ down = false; spriteC[spriteNum].active=false; yourScene.unregisterTouchArea(spriteC[spriteNum].sprite); } fx = spriteC[spriteNum].sprite.getX(); fy = spriteC[spriteNum].sprite.getY(); radf=spriteC[spriteNum].sprite.getHeightScaled()/2; Log.e("F"+Float.toString(fx),Float.toString(fy)); if(spriteNum>0) for(int x=0;x<spriteNum;x++){ rads=spriteC[x].sprite.getHeightScaled()/2; sx = spriteC[x].body.getWorldCenter().x * 32; sy = spriteC[x].body.getWorldCenter().y * 32; Log.e("S"+Float.toString(sx),Float.toString(sy)); Log.e(Float.toString((float) Math.sqrt(Math.pow((fx-sx),2)+Math.pow((fy-sy),2))),Float.toString((radf+rads))); if(Math.sqrt(Math.pow((fx-sx),2)+Math.pow((fy-sy),2))<(radf+rads)){ down = false; spriteC[spriteNum].active=false; yourScene.unregisterTouchArea(spriteC[spriteNum].sprite); Log.e("Collided",Boolean.toString(down)); } } } } spriteC[spriteNum].body = PhysicsFactory.createCircleBody(mPhysicsWorld, spriteC[spriteNum].sprite, BodyType.DynamicBody, FIXTURE_DEF); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(spriteC[spriteNum].sprite, spriteC[spriteNum].body, true, true)); } } Better solution anyone? I know there is something to do with a handler, but I don't exactly know what that is or how to use one.

    Read the article

  • rotate sprite and shooting bullets from the end of a cannon

    - by Alberto
    Hi all i have a problem in my Andengine code, I need , when I touch the screen, shoot a bullet from the cannon (in the same direction of the cannon) The cannon rotates perfectly but when I touch the screen the bullet is not created at the end of the turret This is my code: private void shootProjectile(final float pX, final float pY){ int offX = (int) (pX-canon.getSceneCenterCoordinates()[0]); int offY = (int) (pY-canon.getSceneCenterCoordinates()[1]); if (offX <= 0) return ; if(offY>=0) return; double X=canon.getX()+canon.getWidth()*0,5; double Y=canon.getY()+canon.getHeight()*0,5 ; final Sprite projectile; projectile = new Sprite( (float) X, (float) Y, mProjectileTextureRegion,this.getVertexBufferObjectManager() ); mMainScene.attachChild(projectile); int realX = (int) (mCamera.getWidth()+ projectile.getWidth()/2.0f); float ratio = (float) offY / (float) offX; int realY = (int) ((realX*ratio) + projectile.getY()); int offRealX = (int) (realX- projectile.getX()); int offRealY = (int) (realY- projectile.getY()); float length = (float) Math.sqrt((offRealX*offRealX)+(offRealY*offRealY)); float velocity = (float) 480.0f/1.0f; float realMoveDuration = length/velocity; MoveModifier modifier = new MoveModifier(realMoveDuration,projectile.getX(), realX, projectile.getY(), realY); projectile.registerEntityModifier(modifier); } @Override public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) { if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_MOVE){ double dx = pSceneTouchEvent.getX() - canon.getSceneCenterCoordinates()[0]; double dy = pSceneTouchEvent.getY() - canon.getSceneCenterCoordinates()[1]; double Radius = Math.atan2(dy,dx); double Angle = Radius * 180 / Math.PI; canon.setRotation((float)Angle); return true; } else if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN){ final float touchX = pSceneTouchEvent.getX(); final float touchY = pSceneTouchEvent.getY(); double dx = pSceneTouchEvent.getX() - canon.getSceneCenterCoordinates()[0]; double dy = pSceneTouchEvent.getY() - canon.getSceneCenterCoordinates()[1]; double Radius = Math.atan2(dy,dx); double Angle = Radius * 180 / Math.PI; canon.setRotation((float)Angle); shootProjectile(touchX, touchY); } return false; } Anyone know how to calculate the coordinates (X,Y) of the end of the barrel to draw the bullet?

    Read the article

  • Detect multitouch (two fingers touch) on a sprite to apply pinch zoom behaviour

    - by Tahreem
    I am using andengine, want to move, zoom and rotate multiple sprites individually on a scene. I have achieved "move" but for pinch zoom i am unable to get the event to two fingers' touch. Below is the code: public class Main extends SimpleBaseGameActivity { private Camera camera; private BitmapTextureAtlas mBitmapTextureAtlas; private ITextureRegion mFaceTextureRegion; private ITextureRegion mFaceTextureRegion2; Sprite face2; private static final int CAMERA_WIDTH = 800; private static final int CAMERA_HEIGHT = 480; @Override public EngineOptions onCreateEngineOptions() { camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy( CAMERA_WIDTH, CAMERA_HEIGHT), camera); return engineOptions; } @Override protected void onCreateResources() { BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); this.mBitmapTextureAtlas = new BitmapTextureAtlas( this.getTextureManager(), 1024, 1600, TextureOptions.NEAREST); BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlas, // this, "ui_ball_1.png", 0, 0, 1, 1), // this.getVertexBufferObjectManager()); this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory .createFromAsset(this.mBitmapTextureAtlas, this, "ui_ball_1.png", 0, 0); this.mFaceTextureRegion2 = BitmapTextureAtlasTextureRegionFactory .createFromAsset(this.mBitmapTextureAtlas, this, "ui_ball_1.png", 0, 0); this.mBitmapTextureAtlas.load(); this.mEngine.getTextureManager().loadTexture(this.mBitmapTextureAtlas); } @Override protected Scene onCreateScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); final Scene scene = new Scene(); scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f)); final float centerX = (CAMERA_WIDTH - this.mFaceTextureRegion .getWidth()) / 2; final float centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion .getHeight()) / 2; final Sprite face = new Sprite(centerX, centerY, this.mFaceTextureRegion, this.getVertexBufferObjectManager()) { @Override public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) { this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2); return true; } }; face.setScale(2); scene.attachChild(face); scene.registerTouchArea(face); face2 = new Sprite(200, 200, this.mFaceTextureRegion2, this.getVertexBufferObjectManager()) { @Override public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) { switch(pSceneTouchEvent.getAction()){ case TouchEvent.ACTION_DOWN: int count = pSceneTouchEvent.getMotionEvent().getPointerCount() ; for(int i= 0; i <count; i++) { int id = pSceneTouchEvent.getMotionEvent().getPointerId(i); } break; case TouchEvent.ACTION_MOVE: this.setPosition(pSceneTouchEvent.getX() -this.getWidth() / 2, pSceneTouchEvent.getY()-this.getHeight() / 2); break; case TouchEvent.ACTION_UP: break; } return true; } }; face2.setScale(2); scene.attachChild(face2); scene.registerTouchArea(face2); scene.setTouchAreaBindingOnActionDownEnabled(true); return scene; } } This line int count = pSceneTouchEvent.getMotionEvent().getPointerCount() ; should set 2 to the count variable if i touch the sprite with to fingers, then i can apply zooming functionality (setScale method) on the sprite by getting the distance between the coordinates of two fingers. Can anyone help me? why it does not detect two fingers? and without this how can i zoom the sprite on pinch of two fingers? I am very new to game development, any help would be appreciated. Thanks in advance.

    Read the article

  • Setting Higher Z-Index for Sprite

    - by Siddharth
    For my game, I have to set highest z index for my sprite. At present, I wrote following code but didn't work for me. Sprite houseSprite = new Sprite(pX, pY, textureManager.houseBgRegion.deepCopy(), mVertexBufferObjectManager); attachChild(houseSprite); houseSprite.setZIndex(500); sortChildren(); My requirement did not satisfied with setting sprite in the HUD. So any how I have to apply highest z index. Also in my game sprites are dynamically generated as per game play. So members please share your thoughts.

    Read the article

  • Rotate Body From Corner

    - by Siddharth
    I want to ask that how to rotate body from corner? movableBeam.getBeamBody().setTransform(movableBeam.getBeamBody().getPosition(), angle); The above line of code rotate the beam from center that I want rotate from one of the conner. Any member please help me. EDIT : float beamCenterX = movableBeam.getX() + movableBeam.getWidth() / 2f; float beamCenterY = movableBeam.getY() + movableBeam.getHeight() / 2f; float cornerOffsetX = movableBeam.getX() - beamCenterX; float cornerOffsetY = movableBeam.getY() - beamCenterY; float bodyAngle = (float) Math.atan2(cornerOffsetY, cornerOffsetX); float newAngle = imageAngle + bodyAngle; float newCornerOffsetX = (float) Math.cos(Math .toDegrees(newAngle)); float newCornerOffsetY = (float) Math.sin(Math .toDegrees(newAngle)); cornerOffsetX = movableBeam.getX() - movableBeam.getWidth() / 2f; cornerOffsetY = movableBeam.getY() - movableBeam.getHeight() / 2f; Vector2 postion = new Vector2( (newCornerOffsetX - cornerOffsetX + movableBeam.getX()) / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT, (newCornerOffsetY - cornerOffsetY + movableBeam.getY()) / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT); movableBeam.getBeamBody().setTransform(postion, newAngle);

    Read the article

  • Combine Two Shader Program

    - by Siddharth
    For my android application, I want to apply brightness and contrast shader on same image. At present I am using gpuimage plugin. In that I found two separate program for brightness and contrast as per the following. Contrast shader: varying highp vec2 textureCoordinate; uniform sampler2D inputImageTexture; uniform lowp float contrast; void main() { lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w); } Brightness shader: varying highp vec2 textureCoordinate; uniform sampler2D inputImageTexture; uniform lowp float brightness; void main() { lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w); } Now applying both of the effects I write following code varying highp vec2 textureCoordinate; uniform sampler2D inputImageTexture; varying highp vec2 textureCoordinate2; uniform sampler2D inputImageTexture2; uniform lowp float contrast; uniform lowp float brightness; void main() { lowp vec4 textureColorForContrast = texture2D(inputImageTexture, textureCoordinate); lowp vec4 contastVec4 = vec4(((textureColorForContrast.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColorForContrast.w); lowp vec4 textureColorForBrightness = texture2D(inputImageTexture2, textureCoordinate2); lowp vec4 brightnessVec4 = vec4((textureColorForBrightness.rgb + vec3(brightness)), textureColorForBrightness.w); gl_FragColor = contastVec4 + brightnessVec4; } Doesn't able to get desire result. I can't able to figure out what I have to do next? So please friends help me in this. What program I have to write?

    Read the article

  • Single and Double Jump with single button.

    - by Asad
    I want to make Single Jump on Single Tap and Double Jump on Double Tap. My problem is that if I make double Tap on ground then it’s fine but if I make first Tap on ground and second Tap in Air then Player gain more height then usual As in image 1. I want to Make my jump like in Image 2, No matter from which point user gives second Tap, player Always get a specific height. I Used both Impulse and Linear velocity to make Jump but my problem did not solved.

    Read the article

  • Implement 2x speed in tower of defense type game

    - by Siddharth
    I was currently developing tower of defense game and I want to implement 2x feature for my game. Game usually run with 1x speed that was normal speed of the game. Here what 1x and 2x mean : 1x - mention normal speed of the game, 2x - mention the game object moves with double speed means user experience the fast game play. I want to implement such functionality for my game. The functionality that I want contains in the game Medieval Castle game that was available in the market. https://play.google.com/store/apps/details?id=com.nova.root&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5ub3ZhLnJvb3QiXQ.. The screen shot also shows the 1x and 2x button in that game. I think for 2x speed of the game I have to increase the speed of each object that were in the game. So any member please help what to do for that implementation. Only idea become enough for me.

    Read the article

  • Rain effect looks like snowfall effect?

    - by Nikhil Lamba
    i am making a game in that game i want rain effect i am little bit far from this right now i am doing like below particleSystem.addParticleInitializer(new ColorInitializer(1, 1, 1)); particleSystem.addParticleInitializer(new AlphaInitializer(0)); particleSystem.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE); particleSystem.addParticleInitializer(new VelocityInitializer(2, 2, 20, 10)); particleSystem.addParticleInitializer(new RotationInitializer(0.0f, 30.0f)); particleSystem.addParticleModifier(new ScaleModifier(1.0f, 2.0f, 0, 150)); particleSystem.addParticleModifier(new ColorModifier(1, 1, 1, 1f, 1, 1, 1, 3)); particleSystem.addParticleModifier(new ColorModifier(1, 1, 1f, 1, 1, 1, 1, 6)); particleSystem.addParticleModifier(new AlphaModifier(0, 1, 0, 3)); particleSystem.addParticleModifier(new AlphaModifier(1, 0, 1, 125)); particleSystem.addParticleModifier(new ExpireModifier(50, 50)); scene.attachChild(particleSystem); But its looks like snowfall effect what changes i can do for make it rain effect please correct me EDIT : here is link for snapshot http://i.imgur.com/bRIMP.png

    Read the article

  • Sprite not rotating around its centre after Scaling at its centre

    - by asma.farhat
    If I scale a sprite at its centre, then try to rotate it around its centre as well, the rotation does not occur around its centre. If you need to rotate, for example a scaled ball,the way its working it is set the scale center at the top left (0,0) set the scale that you want, and then set the rotation center to the middle of the scaled sprite, and then apply the rotation modifier. blaBloBliSprite.setScaleCenter(0, 0); blaBloBliSprite.setScale(0.667f); blaBloBliSprite.setPosition(557, CAMERA_HEIGHT / 2 - blaBloBliSprite.getHeightScaled() / 2); blaBloBliSprite.setRotationCenter(blaBloBliSprite.getWidthScaled() / 2, blaBloBliSprite.getHeightScaled() / 2); But I want to scale a sprite at its centre as well. Is there any way of doing it?

    Read the article

  • Ragdoll continuous movement

    - by Siddharth
    I have created a ragdoll for my game but the problem I found was that the ragdoll joints are not perfectly implemented so they are continuously moving. Ragdoll does not stand at fix place. I here paste my work for that and suggest some guidance about that so that it can stand on fix place. chest = new Chest(pX, pY, gameObject.getmChestTextureRegion(), gameObject); head = new Head(pX, pY - 16, gameObject.getmHeadTextureRegion(), gameObject); leftHand = new Hand(pX - 6, pY + 6, gameObject.getmHandTextureRegion() .clone(), gameObject); rightHand = new Hand(pX + 12, pY + 6, gameObject .getmHandTextureRegion().clone(), gameObject); rightHand.setFlippedHorizontal(true); leftLeg = new Leg(pX, pY + 18, gameObject.getmLegTextureRegion() .clone(), gameObject); rightLeg = new Leg(pX + 7, pY + 18, gameObject.getmLegTextureRegion() .clone(), gameObject); rightLeg.setFlippedHorizontal(true); gameObject.getmScene().registerTouchArea(chest); gameObject.getmScene().attachChild(chest); gameObject.getmScene().registerTouchArea(head); gameObject.getmScene().attachChild(head); gameObject.getmScene().registerTouchArea(leftHand); gameObject.getmScene().attachChild(leftHand); gameObject.getmScene().registerTouchArea(rightHand); gameObject.getmScene().attachChild(rightHand); gameObject.getmScene().registerTouchArea(leftLeg); gameObject.getmScene().attachChild(leftLeg); gameObject.getmScene().registerTouchArea(rightLeg); gameObject.getmScene().attachChild(rightLeg); // head revolute joint revoluteJointDef = new RevoluteJointDef(); revoluteJointDef.enableLimit = true; revoluteJointDef.initialize(head.getHeadBody(), chest.getChestBody(), chest.getChestBody().getWorldCenter()); revoluteJointDef.localAnchorA.set(0f, 0f); revoluteJointDef.localAnchorB.set(0f, -0.5f); revoluteJointDef.lowerAngle = (float) (0f / (180 / Math.PI)); revoluteJointDef.upperAngle = (float) (0f / (180 / Math.PI)); headRevoluteJoint = (RevoluteJoint) gameObject.getmPhysicsWorld() .createJoint(revoluteJointDef); // // left leg revolute joint revoluteJointDef.initialize(leftLeg.getLegBody(), chest.getChestBody(), chest.getChestBody().getWorldCenter()); revoluteJointDef.localAnchorA.set(0f, 0f); revoluteJointDef.localAnchorB.set(-0.15f, 0.75f); revoluteJointDef.lowerAngle = (float) (0f / (180 / Math.PI)); revoluteJointDef.upperAngle = (float) (0f / (180 / Math.PI)); leftLegRevoluteJoint = (RevoluteJoint) gameObject.getmPhysicsWorld() .createJoint(revoluteJointDef); // right leg revolute joint revoluteJointDef.initialize(rightLeg.getLegBody(), chest.getChestBody(), chest.getChestBody().getWorldCenter()); revoluteJointDef.localAnchorA.set(0f, 0f); revoluteJointDef.localAnchorB.set(0.15f, 0.75f); revoluteJointDef.lowerAngle = (float) (0f / (180 / Math.PI)); revoluteJointDef.upperAngle = (float) (0f / (180 / Math.PI)); rightLegRevoluteJoint = (RevoluteJoint) gameObject.getmPhysicsWorld() .createJoint(revoluteJointDef); // left hand revolute joint revoluteJointDef.initialize(leftHand.getHandBody(), chest.getChestBody(), chest.getChestBody().getWorldCenter()); revoluteJointDef.localAnchorA.set(0f, 0f); revoluteJointDef.localAnchorB.set(-0.25f, 0.1f); revoluteJointDef.lowerAngle = (float) (0f / (180 / Math.PI)); revoluteJointDef.upperAngle = (float) (0f / (180 / Math.PI)); leftHandRevoluteJoint = (RevoluteJoint) gameObject.getmPhysicsWorld() .createJoint(revoluteJointDef); // right hand revolute joint revoluteJointDef.initialize(rightHand.getHandBody(), chest.getChestBody(), chest.getChestBody().getWorldCenter()); revoluteJointDef.localAnchorA.set(0f, 0f); revoluteJointDef.localAnchorB.set(0.25f, 0.1f); revoluteJointDef.lowerAngle = (float) (0f / (180 / Math.PI)); revoluteJointDef.upperAngle = (float) (0f / (180 / Math.PI)); rightHandRevoluteJoint = (RevoluteJoint) gameObject.getmPhysicsWorld() .createJoint(revoluteJointDef);

    Read the article

  • How do I make my rain effect look more like rain and less like snowfall?

    - by Nikhil Lamba
    I am making a game in that game I want a rain effect. I am little bit far from this right now. I am creating the rain effect like below: particleSystem.addParticleInitializer(new ColorInitializer(1, 1, 1)); particleSystem.addParticleInitializer(new AlphaInitializer(0)); particleSystem.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE); particleSystem.addParticleInitializer(new VelocityInitializer(2, 2, 20, 10)); particleSystem.addParticleInitializer(new RotationInitializer(0.0f, 30.0f)); particleSystem.addParticleModifier(new ScaleModifier(1.0f, 2.0f, 0, 150)); particleSystem.addParticleModifier(new ColorModifier(1, 1, 1, 1f, 1, 1, 1, 3)); particleSystem.addParticleModifier(new ColorModifier(1, 1, 1f, 1, 1, 1, 1, 6)); particleSystem.addParticleModifier(new AlphaModifier(0, 1, 0, 3)); particleSystem.addParticleModifier(new AlphaModifier(1, 0, 1, 125)); particleSystem.addParticleModifier(new ExpireModifier(50, 50)); scene.attachChild(particleSystem); But it looks like snowfall! What changes can I do for it to look more like rain? EDIT Here is a screenshot:

    Read the article

  • Continuous Movement of gun bullet

    - by Siddharth
    I was using box2d for the movement of the body. When I apply gravity (0,0) the bullet continuously move but when I change gravity to the earth the behavior was changed. I also try to apply continuous force to the bullet body but the behavior was not so good. So please provide any suggestion to continuously move bullet body in earth gravity. currentVelocity = bulletBody.getLinearVelocity(); if (currentVelocity.len() < speed|| currentVelocity.len() > speed + 0.25f) { velocityChange = Math.abs(speed - currentVelocity.len()); currentVelocity.set(currentVelocity.x* velocityChange, currentVelocity.y*velocityChange); bulletBody.applyLinearImpulse(currentVelocity,bulletBody.getWorldCenter()); } I apply above code for the continuous velocity of the body. And also I did not able to find any setGravityScale method in the library.

    Read the article

  • Council for the Development of a jumping game!

    - by Esteban Quintero
    I want to create platforms on the stage, where a sprite is jumping on them. something like this http://itunes.apple.com/es/app/doodle-jump-cuidado-extremadamente/id307727765?mt=8 I would like some guidance to do so. 1) what is the best way to simulate the jump? (Velocity or EnityModifier) 2) as platforms rabdom I can generate, with no overlap? 3) should move the camera or the sprites of the stage?

    Read the article

  • Isometric projection bad coordonate

    - by Christophe Debove
    I have a 2D map, for each element I apply this isometric projection to place my Sprite //Element e; float[] f= projection(e.getX(), e.getY() ,z); // x and y represent Sprite Coordonate (tile_width and height depend of my // camera size and the number of elements in x and in y float x = f[0]*tile_width; float y = f[1]*tile_height; public float[] projection(float x, float y, float z) { return new float[]{ (( x )-(y) ) , ((x/2) + (y/2) - z )}; } the sprite for one element : The result of my projection : The problem is I need to add an offset of tile_height/2 to the y and tile_width/2 to the x to have something like this (in the red rectangle I drawed with paint what I want) : Where did I make wrong? (I found the projection method in How should I sort images in an isometric game so that they appear in the correct order? )

    Read the article

  • Reloading Resources on Resume

    - by Siddharth
    I'm having a problem with my game. If I press the "Home button" the game is paused... everythings fine, but if I then go back to the game all the resources are reloaded before I can continue the game. And it takes quite a bit. Is this normal, or is there a way to avoid the reloading? I have write following code in onResume and onPause method. It loads same texture again and again on resume of game. @Override protected void onPause() { super.onPause(); if (Utility.flagSound && mScene != null) { if (mScene.getUserData().equals(Constants.GAME_SCENE)) Utility.isPlayLevelMusic = false; else Utility.isPlayLevelMusic = true; audioManager.gameBgMusic.pause(); audioManager.levelBgMusic.pause(); } if (this.mEngine != null && this.mEngine.isRunning()) { this.mEngine.stop(); } } @Override protected void onResume() { super.onResume(); if (audioManager != null && Utility.flagSound && dataManager != null) { if (Utility.flagSound) { if (Utility.isPlayLevelMusic) audioManager.levelBgMusic.play(); else audioManager.gameBgMusic.play(); } } if (this.mEngine != null && !this.mEngine.isRunning()) { this.mEngine.start(); } } I would be glad if anybody could help...

    Read the article

  • Particle effect after the bullet

    - by Siddharth
    In my game, I fire a bullet from the gun along with that I generate a particle behind the bullet so that I look like fire effect after the bullet. But my problem is that the position I got from the bullet was distance in place. So basically I want to say that the bullet speed was high for that reason I got coordinate for the particle generation was far from each other like dot dot effect. But I want continuous flow of particle behind the bullet. So please provide any guidance for my problem

    Read the article

  • Use PathModifier of MoveModifier for Tower of Defense Game

    - by Siddharth
    In my game I want to move enemy on the fixed path so that I have establish manual grid structure for that purpose not used tile map. Game contain multiple level and the path will be different for each level and also multiple fixed path exist for each level. So my question is, What I have to use MoveModifier or PathModifier for my game ? Also mention I have to use WayPoint or not. Further detail you all are free to ask. Please help me to decide what to do.

    Read the article

  • draw bullet at the end of the barrel

    - by Alberto
    excuse my awkwardness, i have this code: [syntax="java"] int x2 = (int) (canon.getSceneCenterCoordinates()[0] + LENGTH_SPRITE/2* Math.cos(canon.getRotation())); int y2 = (int) (canon.getSceneCenterCoordinates()[1] + LENGTH_SPRITE/2* Math.sin(canon.getRotation())); projectile = new Sprite( (float) x2, (float) y2, mProjectileTextureRegion,this.getVertexBufferObjectManager() ); mMainScene.attachChild(projectile); [/syntax] and the bullet are drawn around the cannon in circle.. but not from the end of cannon :( help!

    Read the article

  • EaseFunction in LoopEntityModifier

    - by Siddharth
    For my game, I need EaseFunction in LoopEntityModifier. In my game, I am rotating ball over certain object. For giving effect I want to use EaseFunction. I want to rotate ball around an object take around 4 to 5 round that was already rotating but I want add some effect so that it looks good. For this I have to use EaseFunction which suits my needs. But if I put EaseFunction in rotation modifier then each round rotation modifier apply an effect of EaseFunction that I want only one time occur either starting or ending time. So if I can able to provide EaseFunction in LoopEntityModifier then it will good for me or something similar also work for me. At present my code is something similar like this. new LoopEntityModifier(new RotationModifier(...)); I hope someone has some idea on this.

    Read the article

  • Smooth Camera Zoom Factor Change

    - by Siddharth
    I have game play scene in which user can zoom in and out. For which I used smooth camera in the following manner. public static final int CAMERA_WIDTH = 1024; public static final int CAMERA_HEIGHT = 600; public static final float MAXIMUM_VELOCITY_X = 400f; public static final float MAXIMUM_VELOCITY_Y = 400f; public static final float ZOOM_FACTOR_CHANGE = 1f; mSmoothCamera = new SmoothCamera(0, 0, Constants.CAMERA_WIDTH, Constants.CAMERA_HEIGHT, Constants.MAXIMUM_VELOCITY_X, Constants.MAXIMUM_VELOCITY_Y, Constants.ZOOM_FACTOR_CHANGE); mSmoothCamera.setBounds(0f, 0f, Constants.CAMERA_WIDTH, Constants.CAMERA_HEIGHT); But above thing create problem for me. When user perform zoom in and leave game play scene then other scene behaviour not look good. I already set zoom factor to 1 for this purpose. But now it show camera translation in other scene. Because scene switching time it so much small that player can easily saw translation of camera that I don't want to show. After camera reposition, everything works perfect but how to set camera its proper position. For example my loading text move from bottom to top or vice versa based on camera movement. Any more detail you want then I can able to give you.

    Read the article

  • How to fire a bullet in a specific direction?

    - by Mike
    I am developing an Android game. I have problem with bullet firing. It's a space ship that has to fire bullets but right now it's firing in a random direction. I have to fire a bullet to the enemy from the only one point on the nose of the ship. Right now the bullets fire sometimes from the tailpart or other. So that's a problem. How do I give a bullet direction and how to fire it from only the head of my space ship?

    Read the article

  • How to remove a box2d body when collision happens?

    - by Ayham
    I’m still new to java and android programming and I am having so much trouble Removing an object when collision happens. I looked around the web and found that I should never handle removing BOX2D bodies during collision detection (a contact listener) and I should add my objects to an arraylist and set a variable in the User Data section of the body to delete or not and handle the removing action in an update handler. So I did this: First I define two ArrayLists one for the faces and one for the bodies: ArrayList<Sprite> myFaces = new ArrayList<Sprite>(); ArrayList<Body> myBodies = new ArrayList<Body>(); Then when I create a face and connect that face to its body I add them to their ArrayLists like this: face = new AnimatedSprite(pX, pY, pWidth, pHeight, this.mBoxFaceTextureRegion); Body BoxBody = PhysicsFactory.createBoxBody(mPhysicsWorld, face, BodyType.DynamicBody, objectFixtureDef); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(face, BoxBody, true, true)); myFaces.add(face); myBodies.add(BoxBody); now I add a contact listener and an update handler in the onloadscene like this: this.mPhysicsWorld.setContactListener(new ContactListener() { private AnimatedSprite face2; @Override public void beginContact(final Contact pContact) { } @Override public void endContact(final Contact pContact) { } @Override public void preSolve(Contact contact,Manifold oldManifold) { } @Override public void postSolve(Contact contact,ContactImpulse impulse) { } }); scene.registerUpdateHandler(new IUpdateHandler() { @Override public void reset() { } @Override public void onUpdate(final float pSecondsElapsed) { } }); My plan is to detect which two bodies collided in the contact listener by checking a variable from the user data section of the body, get their numbers in the array list and finally use the update handler to remove these bodies. The questions are: Am I using the arraylist correctly? How to add a variable to the User Data (the code please). I tried removing a body in this update handler but it still throws me NullPointerException , so what is the right way to add an update handler and where should I add it. Any other advices to do this would be great. Thanks in advance.

    Read the article

  • Why Swipe left doesn't work? [on hold]

    - by Hitesh
    I wrote the below code to detect and perform a sprite action on the single tap and swipe right event. @Override public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) { float x = 0F; int tapCount = 0; boolean playermoving = false; // TODO Auto-generated method stub if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_MOVE) { if (pSceneTouchEvent.getX() > x) { playermoving = true; players.runRight(); } if (pSceneTouchEvent.getX() < x) { Log.i("Run Left", "SPRITE Left"); } /* * if (pSceneTouchEvent.getX() < x) { System.exit(0); * Log.i("SWIPE left", "SPRITE LEFT"); } */ } if (pSceneTouchEvent.getAction() == MotionEvent.ACTION_DOWN) { playermoving = false; x = pSceneTouchEvent.getX(); tapCount++; Log.i("X CORD", String.valueOf(x)); } if (pSceneTouchEvent.isActionDown()) { if (tapCount == 1 && playermoving != true) { tapCount = 0; players.jumpRight(); } } return true; } The code works fine. The only problem is that the swipe left event is not being detected due to some reasons. What can i do to make the swipe left action work? Please help

    Read the article

< Previous Page | 1 2 3 4  | Next Page >