Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.pandus;
- import java.io.IOException;
- import java.io.InputStream;
- import org.andengine.engine.camera.Camera;
- import org.andengine.engine.camera.SmoothCamera;
- import org.andengine.engine.options.EngineOptions;
- import org.andengine.engine.options.ScreenOrientation;
- import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
- import org.andengine.entity.scene.Scene;
- import org.andengine.entity.scene.background.AutoParallaxBackground;
- import org.andengine.entity.scene.background.ParallaxBackground;
- import org.andengine.entity.scene.background.ParallaxBackground.ParallaxEntity;
- import org.andengine.entity.sprite.Sprite;
- import org.andengine.entity.util.FPSLogger;
- import org.andengine.opengl.texture.ITexture;
- import org.andengine.opengl.texture.bitmap.BitmapTexture;
- import org.andengine.opengl.texture.region.ITextureRegion;
- import org.andengine.opengl.texture.region.TextureRegion;
- import org.andengine.opengl.texture.region.TextureRegionFactory;
- import org.andengine.ui.activity.SimpleBaseGameActivity;
- import org.andengine.util.adt.io.in.IInputStreamOpener;
- import org.andengine.util.debug.Debug;
- public class Game extends SimpleBaseGameActivity {
- private static int CAMERA_WIDTH = 800;
- private static int CAMERA_HEIGHT = 460;
- private SmoothCamera camera;
- private TextureRegion mrace_theme, mrace_marks;
- ParallaxLayer parallaxLayer = new ParallaxLayer(camera, true, 4000);
- @Override
- public EngineOptions onCreateEngineOptions() {
- final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
- return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED,
- new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
- }
- @Override
- protected void onCreateResources() {
- try {
- // 1 - Set up bitmap textures
- ITexture race_theme = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
- @Override
- public InputStream open() throws IOException {
- return getAssets().open("gfx/race_road.png");
- }
- });
- ITexture race_marks = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
- @Override
- public InputStream open() throws IOException {
- return getAssets().open("gfx/race_marks.png");
- }
- });
- // 2 - Load bitmap textures into VRAM
- race_theme.load();
- race_marks.load();
- //this.mrace_theme = TextureRegionFactory.extractFromTexture(race_theme);
- //this.mrace_marks = TextureRegionFactory.extractFromTexture(race_marks);
- //BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTorTexture, this, "wyscigi_tlo.png",0,0);
- /*this.mTorTexture = new BitmapTextureAtlas(this.getTextureManager(), 1024,1024, TextureOptions.BILINEAR);
- this.mTorTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mTorTexture, this, "wyscigi_tlo.png",0,0);
- this.mTorTexture.load();*/
- } catch (IOException e) {
- Debug.e(e);
- }
- }
- @Override
- protected Scene onCreateScene() {
- Scene scene = new Scene();
- ParallaxLayer parallaxLayer = new ParallaxLayer(camera, true, 4000);
- Sprite Srace_theme = new Sprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, (ITextureRegion)mrace_theme, this.getVertexBufferObjectManager());
- Sprite Srace_marks = new Sprite(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, mrace_marks, this.getVertexBufferObjectManager());
- parallaxLayer.setParallaxChangePerSecond(1);
- parallaxLayer.setParallaxScrollFactor(0);
- parallaxLayer.attachParallaxEntity(new ParallaxEntity(0, Srace_marks));
- //The method attachParallaxEntity(ParallaxLayer.ParallaxEntity) in the type ParallaxLayer is not applicable for the arguments (ParallaxBackground.ParallaxEntity)
- scene.attachChild(parallaxLayer);
- return scene;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement