private void testSceneTouchWorker( final Scene pScene, final int pSurfaceTouchX, final int pSurfaceTouchY, final float pExpectedX, final float pExpectedY) { pScene.setOnSceneTouchListener( new IOnSceneTouchListener() { @Override public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) { final float actualX = pSceneTouchEvent.getX(); final float actualY = pSceneTouchEvent.getY(); Assert.assertEquals(pExpectedX, actualX, DELTA); Assert.assertEquals(pExpectedY, actualY, DELTA); return true; } }); final long uptimeMillis = SystemClock.uptimeMillis(); final boolean result = this.mEngine.onTouch( null, MotionEvent.obtain( uptimeMillis, uptimeMillis, MotionEvent.ACTION_DOWN, pSurfaceTouchX, pSurfaceTouchY, 0)); Assert.assertTrue(result); }
@Override public Scene onCreateScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); /* Create a nice scene with some rectangles. */ final Scene scene = new Scene(); final Entity rectangleGroup = new Entity(MotionStreakExample.CAMERA_WIDTH / 2, MotionStreakExample.CAMERA_HEIGHT / 2); rectangleGroup.attachChild(this.makeColoredRectangle(-180, -180, 1, 0, 0)); rectangleGroup.attachChild(this.makeColoredRectangle(0, -180, 0, 1, 0)); rectangleGroup.attachChild(this.makeColoredRectangle(0, 0, 0, 0, 1)); rectangleGroup.attachChild(this.makeColoredRectangle(-180, 0, 1, 1, 0)); /* Spin the rectangles. */ rectangleGroup.registerEntityModifier( new LoopEntityModifier( new SequenceEntityModifier( new RotationModifier(10, 0, 7200, EaseQuadInOut.getInstance()), new DelayModifier(2)))); scene.attachChild(rectangleGroup); /* TouchListener */ scene.setOnSceneTouchListener(this); return scene; }
@Override protected Scene onCreateScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); // TODO Auto-generated method stub scene = new Scene(); try { final TMXLoader tmxLoader = new TMXLoader( this.getAssets(), this.mEngine.getTextureManager(), TextureOptions.BILINEAR_PREMULTIPLYALPHA, this.getVertexBufferObjectManager(), new ITMXTilePropertiesListener() { @Override public void onTMXTileWithPropertiesCreated( final TMXTiledMap pTMXTiledMap, final TMXLayer pTMXLayer, final TMXTile pTMXTile, final TMXProperties<TMXTileProperty> pTMXTileProperties) {} }); this.mTMXTiledMap = tmxLoader.loadFromAsset("tmx/map_pro.tmx"); } catch (final TMXLoadException e) { Debug.e(e); } final TMXLayer tmxLayer = this.mTMXTiledMap.getTMXLayers().get(0); scene.attachChild(tmxLayer); /* Make the camera not exceed the bounds of the TMXEntity. */ this.mBoundChaseCamera.setBounds(0, 0, tmxLayer.getHeight(), tmxLayer.getWidth()); this.mBoundChaseCamera.setBoundsEnabled(true); final float centerX = (MyCamera.CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2; final float centerY = (MyCamera.CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2; face = new Sprite(centerX, centerY, this.mFaceTextureRegion, this.getVertexBufferObjectManager()); scene.attachChild(face); // Add playerSprite to screen initplayerSprite(scene, this.mPlayerTextureRegion); // Scene UpdateHandler scene.setTouchAreaBindingOnActionDownEnabled(true); scene.setOnAreaTouchListener(pOnAreaTouchListener); scene.registerUpdateHandler(pUpdateHandler); scene.registerTouchArea(tmxLayer); scene.setOnSceneTouchListener(pOnSceneTouchListener); return scene; }
@Override protected Scene onCreateScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); final Scene scene = new Scene(); final CircleOutlineParticleEmitter particleEmitter = new CircleOutlineParticleEmitter( XMLLayoutExample.CAMERA_WIDTH * 0.5f, (XMLLayoutExample.CAMERA_HEIGHT * 0.5f) + 20, 80); final SpriteParticleSystem particleSystem = new SpriteParticleSystem( particleEmitter, 60, 60, 360, this.mParticleTextureRegion, this.getVertexBufferObjectManager()); scene.setOnSceneTouchListener( new IOnSceneTouchListener() { @Override public boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) { particleEmitter.setCenter(pSceneTouchEvent.getX(), pSceneTouchEvent.getY()); return true; } }); particleSystem.addParticleInitializer(new ColorParticleInitializer<Sprite>(1, 0, 0)); particleSystem.addParticleInitializer(new AlphaParticleInitializer<Sprite>(0)); particleSystem.addParticleInitializer( new BlendFunctionParticleInitializer<Sprite>(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE)); particleSystem.addParticleInitializer(new VelocityParticleInitializer<Sprite>(-2, 2, -20, -10)); particleSystem.addParticleInitializer(new RotationParticleInitializer<Sprite>(0.0f, 360.0f)); particleSystem.addParticleInitializer(new ExpireParticleInitializer<Sprite>(6)); particleSystem.addParticleModifier(new ScaleParticleModifier<Sprite>(0, 5, 1.0f, 2.0f)); particleSystem.addParticleModifier( new ColorParticleModifier<Sprite>(0, 3, 1, 1, 0, 0.5f, 0, 0)); particleSystem.addParticleModifier( new ColorParticleModifier<Sprite>(4, 6, 1, 1, 0.5f, 1, 0, 1)); particleSystem.addParticleModifier(new AlphaParticleModifier<Sprite>(0, 1, 0, 1)); particleSystem.addParticleModifier(new AlphaParticleModifier<Sprite>(5, 6, 1, 0)); scene.attachChild(particleSystem); return scene; }
@Override public void onPopulateScene(Scene pScene, OnPopulateSceneCallback pOnPopulateSceneCallback) { mPhysicsWorld = new FixedStepPhysicsWorld( 60, new Vector2(0f, -SensorManager.GRAVITY_EARTH * 2), false, 8, 3); mScene.registerUpdateHandler(mPhysicsWorld); final FixtureDef WALL_FIXTURE_DEF = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f); final Rectangle ground = new Rectangle( cameraWidth / 2f, 6f, cameraWidth - 4f, 8f, this.getVertexBufferObjectManager()); final Rectangle roof = new Rectangle( cameraWidth / 2f, cameraHeight - 6f, cameraWidth - 4f, 8f, this.getVertexBufferObjectManager()); final Rectangle left = new Rectangle( 6f, cameraHeight / 2f, 8f, cameraHeight - 4f, this.getVertexBufferObjectManager()); final Rectangle right = new Rectangle( cameraWidth - 6f, cameraHeight / 2f, 8f, cameraHeight - 4f, this.getVertexBufferObjectManager()); ground.setColor(0f, 0f, 0f); roof.setColor(0f, 0f, 0f); left.setColor(0f, 0f, 0f); right.setColor(0f, 0f, 0f); groundWallBody = PhysicsFactory.createBoxBody( this.mPhysicsWorld, ground, BodyType.StaticBody, WALL_FIXTURE_DEF); roofWallBody = PhysicsFactory.createBoxBody( this.mPhysicsWorld, roof, BodyType.StaticBody, WALL_FIXTURE_DEF); leftWallBody = PhysicsFactory.createBoxBody( this.mPhysicsWorld, left, BodyType.StaticBody, WALL_FIXTURE_DEF); rightWallBody = PhysicsFactory.createBoxBody( this.mPhysicsWorld, right, BodyType.StaticBody, WALL_FIXTURE_DEF); this.mScene.attachChild(ground); this.mScene.attachChild(roof); this.mScene.attachChild(left); this.mScene.attachChild(right); Rectangle GravityRect = new Rectangle(300f, 240f, 100f, 100f, this.getEngine().getVertexBufferObjectManager()); GravityRect.setColor(0f, 0.7f, 0f); mScene.attachChild(GravityRect); mScene.registerTouchArea(GravityRect); gravityBody = PhysicsFactory.createBoxBody( mPhysicsWorld, GravityRect, BodyType.DynamicBody, boxFixtureDef); gravityBody.setLinearDamping(0.4f); gravityBody.setAngularDamping(0.6f); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(GravityRect, gravityBody)); Rectangle AntiGravityRect = new Rectangle(500f, 240f, 100f, 100f, this.getEngine().getVertexBufferObjectManager()) { @Override protected void onManagedUpdate(final float pSecondsElapsed) { super.onManagedUpdate(pSecondsElapsed); antigravityBody.applyForce( -mPhysicsWorld.getGravity().x * antigravityBody.getMass(), -mPhysicsWorld.getGravity().y * antigravityBody.getMass(), antigravityBody.getWorldCenter().x, antigravityBody.getWorldCenter().y); } }; AntiGravityRect.setColor(0f, 0f, 0.7f); mScene.attachChild(AntiGravityRect); mScene.registerTouchArea(AntiGravityRect); antigravityBody = PhysicsFactory.createBoxBody( mPhysicsWorld, AntiGravityRect, BodyType.DynamicBody, boxFixtureDef); antigravityBody.setLinearDamping(0.4f); antigravityBody.setAngularDamping(0.6f); mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(AntiGravityRect, antigravityBody)); mScene.setOnSceneTouchListener(this); pOnPopulateSceneCallback.onPopulateSceneFinished(); }