@Override protected Scene onCreateScene() { this.mScene = new Scene(); this.xCoords = new float[COLUMNS]; this.yCoords = new float[ROWS]; float space = Math.min((float) CAMERA_HEIGHT / (float) ROWS, (float) CAMERA_WIDTH / (float) COLUMNS); float xCord = (CAMERA_WIDTH - space * (COLUMNS - 1)) / 2f; float yCord = (CAMERA_HEIGHT - space * (ROWS - 1)) / 2f; this.maps = new GomokuTiledSprite[COLUMNS - 1][ROWS - 1]; VertexBufferObjectManager VBOManager = this.getVertexBufferObjectManager(); Log.w("SPACE", "" + space); for (int i = 0; i < COLUMNS; i++) { xCoords[i] = xCord + i * space; } for (int i = 0; i < ROWS; i++) { yCoords[i] = yCord + i * space; } for (int i = 0; i < COLUMNS; i++) { Line line = new Line(xCoords[i], yCoords[0], xCoords[i], yCoords[ROWS - 1], STROKE_WIDTH, VBOManager); line.setColor(0f, 1f, 1f); mScene.attachChild(line); } for (int i = 0; i < ROWS; i++) { Line line = new Line( xCoords[0], yCoords[i], xCoords[COLUMNS - 1], yCoords[i], STROKE_WIDTH, VBOManager); line.setColor(0f, 1f, 1f); mScene.attachChild(line); } mScene.setTouchAreaBindingOnActionDownEnabled(true); mScene.setTouchAreaBindingOnActionMoveEnabled(false); for (int i = 0; i < COLUMNS - 1; i++) { for (int j = 0; j < ROWS - 1; j++) { this.maps[i][j] = new GomokuTiledSprite( xCoords[i] + space / 2f, yCoords[j] + space / 2f, blankRegion, xRegion, oRegion, winRegion, VBOManager, this); mScene.registerTouchArea(maps[i][j]); mScene.attachChild(maps[i][j]); maps[i][j].setCoordinates(i, j); } } return mScene; }
@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 public Scene onCreateScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); this.mScene = new Scene(); this.mScene.setOnAreaTouchTraversalFrontToBack(); Rectangle easyRect = new Rectangle( FIRST_SPACE, FIRST_SPACE + TOP_BORDER, CAMERA_WIDTH * (1 - (2 * BORDER_SIZE)), (CAMERA_WIDTH * (1 - (2 * BORDER_SIZE))), this.getVertexBufferObjectManager()); easyRect.setColor(1, 1, 1); this.mScene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f)); mScene.attachChild(easyRect); ; float pos_at = FIRST_SPACE; for (int i = 0; i <= NUM_ROWSCOLS; i++) { Line boardLineVert = new Line( pos_at, FIRST_SPACE + TOP_BORDER, pos_at, (CAMERA_WIDTH * (1 - BORDER_SIZE)) + TOP_BORDER, this.getVertexBufferObjectManager()); Line boardLineHorz = new Line( FIRST_SPACE, pos_at + TOP_BORDER, CAMERA_WIDTH * (1 - BORDER_SIZE), pos_at + TOP_BORDER, this.getVertexBufferObjectManager()); boardLineVert.setColor(0, 0, 0); boardLineHorz.setColor(0, 0, 0); mScene.attachChild(boardLineHorz); mScene.attachChild(boardLineVert); pos_at = pos_at + SPACING; } hudLoader.addTouchToScene(mScene, mZoomCamera); this.mScene.setTouchAreaBindingOnActionDownEnabled(true); return this.mScene; }
public Scene onCreateScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); final Scene scene = new Scene(); scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f)); boton = new ButtonSprite( 100, 100, this.mBotonTextureRegion, this.getVertexBufferObjectManager(), new OnClickListener() { public void onClick( ButtonSprite pButtonSprite, float pTouchAreaLocalX, float pTouchAreaLocalY) { boton.setPosition(boton.getX() + 20, boton.getY() + 20); } }); scene.attachChild(boton); scene.registerTouchArea(boton); return scene; }
@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; }
private void drawUsingSpriteBatch(final Scene pScene) { final IEntityModifier faceEntityModifier = new SequenceEntityModifier( new RotationByModifier(2, 90), new AlphaModifier(1.5f, 1, 0), new AlphaModifier(1.5f, 0, 1), new ScaleModifier(2.5f, 1, 0.5f), new DelayModifier(0.5f), new ParallelEntityModifier( new ScaleModifier(2f, 0.5f, 5), new RotationByModifier(2, 90)), new ParallelEntityModifier( new ScaleModifier(2f, 5, 1), new RotationModifier(2f, 180, 0))); final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager(); final SpriteGroup spriteGroup = new SpriteGroup( this.mFaceTexture, EntityModifierBenchmark.SPRITE_COUNT, vertexBufferObjectManager); spriteGroup.setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); for (int i = 0; i < EntityModifierBenchmark.SPRITE_COUNT; i++) { final Sprite face = new Sprite( (EntityModifierBenchmark.CAMERA_WIDTH - 32) * this.mRandom.nextFloat(), (EntityModifierBenchmark.CAMERA_HEIGHT - 32) * this.mRandom.nextFloat(), this.mFaceTextureRegion, vertexBufferObjectManager); face.registerEntityModifier(faceEntityModifier.deepCopy()); spriteGroup.attachChild(face); } pScene.attachChild(spriteGroup); }
private void drawUsingSpritesWithSharedVertexBuffer(final Scene pScene) { final IEntityModifier faceEntityModifier = new SequenceEntityModifier( new RotationByModifier(2, 90), new AlphaModifier(1.5f, 1, 0), new AlphaModifier(1.5f, 0, 1), new ScaleModifier(2.5f, 1, 0.5f), new DelayModifier(0.5f), new ParallelEntityModifier( new ScaleModifier(2f, 0.5f, 5), new RotationByModifier(2, 90)), new ParallelEntityModifier( new ScaleModifier(2f, 5, 1), new RotationModifier(2f, 180, 0))); /* As we are creating quite a lot of the same Sprites, we can let them share a VertexBuffer to significantly increase performance. */ final ISpriteVertexBufferObject sharedVertexBuffer = new LowMemorySpriteVertexBufferObject( this.getVertexBufferObjectManager(), Sprite.SPRITE_SIZE, DrawType.STATIC, true, Sprite.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT); for (int i = 0; i < SPRITE_COUNT; i++) { final Sprite face = new Sprite( (CAMERA_WIDTH - 32) * this.mRandom.nextFloat(), (CAMERA_HEIGHT - 32) * this.mRandom.nextFloat(), this.mFaceTextureRegion, sharedVertexBuffer); face.setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); face.registerEntityModifier(faceEntityModifier.deepCopy()); pScene.attachChild(face); } }
/** * Attach all bird sprites to scene * * @param scene {scene} */ public void AttachToScene(Scene scene) { if (scene == null) return; int size = birdSprites.size(); for (int i = 0; i < size; i++) { scene.attachChild(birdSprites.get(i).getAnimatedSprite()); } }
@Override public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback) throws Exception { this.mEngine.registerUpdateHandler(new FPSLogger()); 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()); final PhysicsHandler physicsHandler = new PhysicsHandler(face); face.registerUpdateHandler(physicsHandler); scene.attachChild(face); final AnalogOnScreenControl analogOnScreenControl = new AnalogOnScreenControl( 0, CAMERA_HEIGHT - this.mOnScreenControlBaseTextureRegion.getHeight(), this.mCamera, this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, 200, this.getVertexBufferObjectManager(), new IAnalogOnScreenControlListener() { @Override public void onControlChange( final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) { physicsHandler.setVelocity(pValueX * 100, pValueY * 100); } @Override public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl) { face.registerEntityModifier( new SequenceEntityModifier( new ScaleModifier(0.25f, 1, 1.5f), new ScaleModifier(0.25f, 1.5f, 1))); } }); analogOnScreenControl .getControlBase() .setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); analogOnScreenControl.getControlBase().setAlpha(0.5f); analogOnScreenControl.getControlBase().setScaleCenter(0, 128); analogOnScreenControl.getControlBase().setScale(1.25f); analogOnScreenControl.getControlKnob().setScale(1.25f); analogOnScreenControl.refreshControlKnobPosition(); scene.setChildScene(analogOnScreenControl); pOnCreateSceneCallback.onCreateSceneFinished(scene); }
public LevelViewButtonSelector attachButtonsToScene(Scene pScene, boolean pTouchEn) { for (LevelViewButton btn : getButtons()) { pScene.attachChild(btn); if (pTouchEn == true) { pScene.registerTouchArea(btn); } } return this; }
public LevelViewButtonSelector attachButtonsToScene( Scene pScene, boolean pTouchEn, IEntityModifier pEntityModifier) { for (LevelViewButton btn : getButtons()) { pScene.attachChild(btn); if (pTouchEn == true) { pScene.registerTouchArea(btn); } btn.registerEntityModifier(pEntityModifier); } return this; }
// Creer la scene affiche e l'ecran. private void initSplashScene() { mCurrentScene = new Scene(); // Sprite qui va contenir le logo Sprite splash = new Sprite(0, 0, manager.mSplashLogo, mEngine.getVertexBufferObjectManager()) { @Override protected void preDraw(GLState pGLState, Camera pCamera) { super.preDraw(pGLState, pCamera); pGLState.enableDither(); } }; splash.setScale(0.8f); // Ajoute le sprite splash e la scene. splash.setPosition( (mCamera.getWidth() - splash.getWidth()) * 0.5f, (mCamera.getHeight() - splash.getHeight() - 150f) * 0.5f); mCurrentScene.attachChild(splash); // Attache le titre mCurrentScene.attachChild(mTitle1); mCurrentScene.attachChild(mTitle2); }
@Override protected Scene initSceneImpl() { mTossScene = new Scene(); final Sprite backgroundSprite = new Sprite(0, 0, mBgTextureRegion, getVertexBufferObjectManager()); mTossScene.attachChild(backgroundSprite); Item item = mGame.getPlayer().getItemFromStorage(); if (item == null) { return mTossScene; // should never enter here. } final Sprite message = new Sprite(5, 20, mMessageBox, getVertexBufferObjectManager()); mTossScene.attachChild(message); int amount = mGame.itemLost(item.getType(), item.getCount()); mAmountText = new Text(270, 43, mFont, String.valueOf(amount), getVertexBufferObjectManager()); mTossScene.attachChild(mAmountText); TiledSprite itemKind = new TiledSprite(95, 43, mLocTextureRegion, getVertexBufferObjectManager()); itemKind.setCurrentTileIndex(item.getType() - 1); mTossScene.attachChild(itemKind); return mTossScene; }
@Override protected Scene onCreateScene() { Scene scene = new Scene(); this.tmxLayer = this.tiledMap .getTMXLayers() .get( 0); // the 0 is just an index of the layer. It depends on how many layers you // created within Tiled scene.attachChild(this.tmxLayer); return scene; }
/** Display the LevelSelector on the Scene. */ public void show() { /* Register as non-hidden, allowing touch events */ mHidden = false; /* Attach the LevelSelector the the Scene if it currently has no parent */ if (!this.hasParent()) { mScene.attachChild(this); } /* Set the LevelSelector to visible */ this.setVisible(true); }
private void addRectangleWithTension(final Scene pScene, final float pTension, float pDelay) { final Rectangle rectangle = new Rectangle(-SIZE, -SIZE, SIZE, SIZE, this.getVertexBufferObjectManager()); rectangle.setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE); if (pTension < 0) { rectangle.setColor(1 - pTension, 0, 0, 0.5f); } else { rectangle.setColor(pTension, 0, 0, 0.5f); } final CardinalSplineMoveModifierConfig catmullRomMoveModifierConfig1 = new CardinalSplineMoveModifierConfig( CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS.length, pTension); final CardinalSplineMoveModifierConfig catmullRomMoveModifierConfig2 = new CardinalSplineMoveModifierConfig( CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS.length, pTension); for (int i = 0; i < CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS.length; i++) { catmullRomMoveModifierConfig1.setControlPoint( i, CardinalSplineMoveModifierExample.CONTROLPOINT_1_XS[i] - SIZE / 2, CardinalSplineMoveModifierExample.CONTROLPOINT_YS[i] - SIZE / 2); catmullRomMoveModifierConfig2.setControlPoint( i, CardinalSplineMoveModifierExample.CONTROLPOINT_2_XS[i] - SIZE / 2, CardinalSplineMoveModifierExample.CONTROLPOINT_YS[i] - SIZE / 2); } rectangle.registerEntityModifier( new SequenceEntityModifier( new DelayModifier(pDelay), new LoopEntityModifier( new SequenceEntityModifier( new ParallelEntityModifier( new CardinalSplineMoveModifier( CardinalSplineMoveModifierExample.DURATION, catmullRomMoveModifierConfig1, EaseLinear.getInstance()), new RotationModifier( CardinalSplineMoveModifierExample.DURATION, -45, -315)), new ParallelEntityModifier( new CardinalSplineMoveModifier( CardinalSplineMoveModifierExample.DURATION, catmullRomMoveModifierConfig2, EaseLinear.getInstance()), new RotationModifier( CardinalSplineMoveModifierExample.DURATION, 45, 315)))))); pScene.attachChild(rectangle); }
@Override public void onPopulateSceneAsync(final Scene pScene, final IProgressListener pProgressListener) throws Exception { /* Calculate the coordinates for the face, so its centered on the camera */ final float centerX = (AsyncGameActivityExample.CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2; final float centerY = (AsyncGameActivityExample.CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2; /* Create the face and add it to the scene */ final Sprite face = new Sprite(centerX, centerY, this.mFaceTextureRegion, this.getVertexBufferObjectManager()); pScene.attachChild(face); }
public void addGimmicsButton( Scene mScene, String[] sound, int[] image, TexturePackTextureRegionLibrary pTexturePackTextureRegionLibrary) { ITextureRegion[] ttrGimmic = new ITextureRegion[3]; sprGimmic = new Sprite[3]; final Sound[] sndGimmic = new Sound[3]; int[] start = {244, 436, 612}; for (int i = 0; i < sprGimmic.length; i++) { // load sound sndGimmic[i] = loadSoundResourceFromSD(sound[i]); ttrGimmic[i] = pTexturePackTextureRegionLibrary.get(image[i]); final int tmp = i; sprGimmic[i] = new Sprite(start[i], 496, ttrGimmic[i], this.getVertexBufferObjectManager()) { @Override public boolean onAreaTouched( final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) { if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_DOWN) { if (isTouchGimmic[tmp]) { if (tmp == 2) { combineGimmic3WithAction(); } else { sndGimmic[tmp].play(); } sprGimmic[tmp].registerEntityModifier( new SequenceEntityModifier( new ScaleModifier(0.35f, 1, 1.3f), new ScaleModifier(0.35f, 1.3f, 1f))); } return true; } return super.onAreaTouched(pSceneTouchEvent, pTouchAreaLocalX, pTouchAreaLocalY); } }; mScene.registerTouchArea(sprGimmic[i]); mScene.attachChild(sprGimmic[i]); } mScene.setTouchAreaBindingOnActionDownEnabled(true); mScene.setTouchAreaBindingOnActionMoveEnabled(true); }
@Override public Scene onCreateScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); final Scene scene = new Scene(); scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f)); final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager(); this.mText = new Text( 50, 40, this.mFont, "", 1000, new TextOptions(true, AUTOWRAP_WIDTH, Text.LEADING_DEFAULT, HorizontalAlign.CENTER), vertexBufferObjectManager); scene.attachChild(this.mText); this.mLeft = new Line(0, 0, 0, TextBreakExample.CAMERA_HEIGHT, this.getVertexBufferObjectManager()); this.mRight = new Line(0, 0, 0, TextBreakExample.CAMERA_HEIGHT, this.getVertexBufferObjectManager()); this.mText.attachChild(this.mLeft); this.mText.attachChild(this.mRight); final Line leftBreakLine = new Line(0, 0, 0, TextBreakExample.CAMERA_HEIGHT, this.getVertexBufferObjectManager()); leftBreakLine.setLineWidth(2); leftBreakLine.setColor(Color.RED); this.mText.attachChild(leftBreakLine); final Line rightBreakLine = new Line( AUTOWRAP_WIDTH, 0, AUTOWRAP_WIDTH, TextBreakExample.CAMERA_HEIGHT, this.getVertexBufferObjectManager()); rightBreakLine.setLineWidth(2); rightBreakLine.setColor(Color.RED); this.mText.attachChild(rightBreakLine); this.updateText(); 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(); }
@Override protected Scene onCreateScene() { // 1 - Create new scene final Scene scene = new Scene(); Sprite backgroundSprite = new Sprite(0, 0, this.mBackgroundTextureRegion, getVertexBufferObjectManager()); scene.attachChild(backgroundSprite); // 2 - Add the towers mTower1 = new Sprite(192, 63, this.mTowerTextureRegion, getVertexBufferObjectManager()); mTower2 = new Sprite(400, 63, this.mTowerTextureRegion, getVertexBufferObjectManager()); mTower3 = new Sprite(604, 63, this.mTowerTextureRegion, getVertexBufferObjectManager()); scene.attachChild(mTower1); scene.attachChild(mTower2); scene.attachChild(mTower3); // 3 - Create the rings Ring ring1 = new Ring(1, 139, 174, this.mRing1, getVertexBufferObjectManager()) { @Override public boolean onAreaTouched( TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) { if (((Ring) this.getmStack().peek()).getmWeight() != this.getmWeight()) return false; this.setPosition( pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2); if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) { checkForCollisionsWithTowers(this); } return true; } }; Ring ring2 = new Ring(2, 118, 212, this.mRing2, getVertexBufferObjectManager()) { @Override public boolean onAreaTouched( TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) { if (((Ring) this.getmStack().peek()).getmWeight() != this.getmWeight()) return false; this.setPosition( pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2); if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) { checkForCollisionsWithTowers(this); } return true; } }; Ring ring3 = new Ring(3, 97, 255, this.mRing3, getVertexBufferObjectManager()) { @Override public boolean onAreaTouched( TouchEvent pSceneTouchEvent, float pTouchAreaLocalX, float pTouchAreaLocalY) { if (((Ring) this.getmStack().peek()).getmWeight() != this.getmWeight()) return false; this.setPosition( pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2); if (pSceneTouchEvent.getAction() == TouchEvent.ACTION_UP) { checkForCollisionsWithTowers(this); } return true; } }; scene.attachChild(ring1); scene.attachChild(ring2); scene.attachChild(ring3); // 4 - Add all rings to stack one this.mStack1.add(ring3); this.mStack1.add(ring2); this.mStack1.add(ring1); // 5 - Initialize starting position for each ring ring1.setmStack(mStack1); ring2.setmStack(mStack1); ring3.setmStack(mStack1); ring1.setmTower(mTower1); ring2.setmTower(mTower1); ring3.setmTower(mTower1); // 6 - Add touch handlers scene.registerTouchArea(ring1); scene.registerTouchArea(ring2); scene.registerTouchArea(ring3); scene.setTouchAreaBindingOnActionDownEnabled(true); return scene; }
public void initplayerSprite(Scene mScene, TiledTextureRegion mTiledTextureRegion) { playerSprite = new Player(100, 100, mTiledTextureRegion, this.getVertexBufferObjectManager()); // mBoundChaseCamera.setChaseEntity(playerSprite); mScene.attachChild(playerSprite); }
@Override public Scene onCreateScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); final Scene scene = new Scene(); scene.getBackground().setColor(0.09804f, 0.6274f, 0.8784f); final int centerX = CAMERA_WIDTH / 2; final int centerY = CAMERA_HEIGHT / 2; final Sprite sprite = new Sprite(centerX, centerY, this.mFaceTextureRegion, this.getVertexBufferObjectManager()); final PhysicsHandler physicsHandler = new PhysicsHandler(sprite); sprite.registerUpdateHandler(physicsHandler); scene.attachChild(sprite); /* Velocity control (left). */ final AnalogOnScreenControl velocityOnScreenControl = new AnalogOnScreenControl( 0, 0, this.mCamera, this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, this.getVertexBufferObjectManager(), new IAnalogOnScreenControlListener() { @Override public void onControlChange( final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) { physicsHandler.setVelocity(pValueX * 100, pValueY * 100); } @Override public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl) { /* Nothing. */ } }); { final Sprite controlBase = velocityOnScreenControl.getControlBase(); controlBase.setAlpha(0.5f); controlBase.setOffsetCenter(0, 0); scene.setChildScene(velocityOnScreenControl); } /* Rotation control (right). */ final float y = (this.mPlaceOnScreenControlsAtDifferentVerticalLocations) ? CAMERA_HEIGHT : 0; final AnalogOnScreenControl rotationOnScreenControl = new AnalogOnScreenControl( CAMERA_WIDTH, y, this.mCamera, this.mOnScreenControlBaseTextureRegion, this.mOnScreenControlKnobTextureRegion, 0.1f, this.getVertexBufferObjectManager(), new IAnalogOnScreenControlListener() { @Override public void onControlChange( final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) { if (pValueX == 0 && pValueY == 0) { sprite.setRotation(0); } else { sprite.setRotation(MathUtils.radToDeg((float) Math.atan2(pValueX, pValueY))); } } @Override public void onControlClick(final AnalogOnScreenControl pAnalogOnScreenControl) { /* Nothing. */ } }); { final Sprite controlBase = rotationOnScreenControl.getControlBase(); if (this.mPlaceOnScreenControlsAtDifferentVerticalLocations) { controlBase.setOffsetCenter(1, 1); } else { controlBase.setOffsetCenter(1, 0); } controlBase.setAlpha(0.5f); velocityOnScreenControl.setChildScene(rotationOnScreenControl); } return scene; }