أفضل الأسعار في العالم
الطبقة العامة MenuScrollerActivity تمتد BaseGameActivity تطبق IScrollDetectorListener, IOnSceneTouchListener, IClickDetectorListener { // ============================================================== =============== // الثوابت // ================================================================================================== ========= كثافة العمليات المحمية CAMERA_WIDTH = 480; كثافة العمليات الثابتة المحمية CAMERA_HEIGHT = 320؛ عدد صحيح ثابت محمي FONT_SIZE = 24؛ PADDING ثابت ثابت = 50 ؛ قوائم int الثابتة المحمية = 7؛ // ========================================================================================= =========== // الحقول // ================================================================================================== ========= مشهد خاص mScene؛ كاميرا خاصة mCamera؛ الخط الخاص mFont؛ الخاص BitmapTextureAtlas mFontTexture؛ خاص BitmapTextureAtlas mMenuTextureAtlas؛ خاص TextureRegion mMenuLeftTextureRegion؛ خاص TextureRegion mMenuRightTextureRegion؛ القائمة اليسرى الخاصة بـ Sprite ؛ قائمة العفريت الخاصة؛ // التمرير الخاص SurfaceScrollDetector mScrollDetector; ClickDetector الخاص mClickDetector؛ تعويم خاص mMinX = 0؛ تعويم خاص mMaxX = 0؛ تعويم خاص mCurrentX = 0؛ Private int iItemClicked = -1; شريط تمرير مستطيل خاص؛ قائمة خاصة <TextureRegion> columns = new ArrayList<TextureRegion>(); // ========================================================================================= =========== // المنشئون // ================================================================================================== ========= // ================================================================================================== ========= // Getter & Setter // ================================================================================================== ========= // ================================================================================================== ========= // طرق ل/من SuperClass/واجهات // ================================================================================================== ========= @Override public void onLoadResources() { // المسارات FontFactory.setAssetBasePath("font/"); BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); // الخط this.mFontTexture = new BitmapTextureAtlas(256, 256); this.mFont = FontFactory.createFromAsset(this.mFontTexture, this, "Plok.TTF", FONT_SIZE, true, Color.BLACK); this.mEngine.getTextureManager().loadTextures(this.mFontTexture); this.mEngine.getFontManager().loadFonts(this.mFont); // صور القائمة for (int i = 0; i < MENUITEMS; i++) { BitmapTextureAtlas mMenuBitmapTextureAtlas = new BitmapTextureAtlas(256,256, TextureOptions.BILINEAR_PREMULTIPLYALPHA); TextureRegion mMenuTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mMenuBitmapTextureAtlas, this, "menu"+i+".png", 0, 0); this.mEngine.getTextureManager().loadTexture(mMenuBitmapTextureAtlas); columns.add(mMenuTextureRegion); } // أنسجة أسهم القائمة this.mMenuTextureAtlas = new BitmapTextureAtlas(128,128, TextureOptions.BILINEAR_PREMULTIPLYALPHA); this.mMenuLeftTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mMenuTextureAtlas, this, "menu_left.png", 0, 0); this.mMenuRightTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mMenuTextureAtlas, this, "menu_right.png",64, 0); this.mEngine.getTextureManager().loadTexture(mMenuTextureAtlas); } @Override public Engine onLoadEngine() { this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); Final EngineOptions EngineOptions = new EngineOptions(true, ScreenOrientation.LANDSCAPE, new fillResolutionPolicy(), this.mCamera); EngineOptions.getTouchOptions().setRunOnUpdateThread(true); محرك المحرك النهائي = محرك جديد (engineOptions)؛ محرك العودة } @Override public Scene onLoadScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); this.mScene = new Scene(); this.mScene.setBackground(new ColorBackground(0, 0, 0)); this.mScrollDetector = new SurfaceScrollDetector(this); this.mClickDetector = new ClickDetector(this); this.mScene.setOnSceneTouchListener(this); this.mScene.setTouchAreaBindingEnabled(true); this.mScene.setOnSceneTouchListenerBindingEnabled(true); CreateMenuBoxes(); إرجاع this.mScene; } @Override public boolean onSceneTouchEvent(final Scene pScene, Final TouchEvent pSceneTouchEvent) { this.mClickDetector.onTouchEvent(pSceneTouchEvent); this.mScrollDetector.onTouchEvent(pSceneTouchEvent); عودة صحيحة؛ } @Override public void onScroll(final ScrollDetector pScollDetector, Final TouchEvent pTouchEvent, Final float pDistanceX, Final float pDistanceY) { // تعطيل أسهم القائمة لليسار واليمين (حشوة 15 بكسل) if(mCamera.getMinX()<=15) Menuleft. setVisible(false); else Menuleft.setVisible(true); if(mCamera.getMinX()>mMaxX-15) Menuright.setVisible(false); else Menuright.setVisible(true); // العودة إذا تم الوصول إلى الأطراف if ( ((mCurrentX - pDistanceX) < mMinX) ){ return; }else if((mCurrentX - pDistanceX) > mMaxX){ return; } // توسيط الكاميرا إلى النقطة الحالية this.mCamera.offsetCenter(-pDistanceX,0 ); mCurrentX -= pDistanceX; // قم بتعيين شريط التمرير باستخدام تعويم الكاميرا tempX =mCamera.getCenterX()-CAMERA_WIDTH/2; // أضف الجزء % إلى الموضع tempX+= (tempX/(mMaxX+CAMERA_WIDTH))*CAMERA_WIDTH; // تعيين الموضع التمرير Bar.setPosition(tempX, التمريرBar.getY()); // اضبط الأسهم لليسار واليمين Menuright.setPosition(mCamera.getCenterX()+CAMERA_WIDTH/2-menuright.getWidth(),menuright.getY()); Menuleft.setPosition(mCamera.getCenterX()-CAMERA_WIDTH/2,menuleft.getY()); // لأن الكاميرا يمكن أن تحتوي على قيم X سلبية، لذا اضبطها على 0 if(this.mCamera.getMinX()<0){ this.mCamera.offsetCenter(0,0 ); mCurrentX=0; } } @Override public void onClick(ClickDetector pClickDetector, TouchEvent pTouchEvent) {loadLevel(iItemClicked); }; // ========================================================================================= =========== // الطرق // ================================================================================================== ========= public void CreateMenuBoxes() { int spriteX = PADDING; int spriteY = PADDING; // عداد العنصر الحالي int iItem = 1; for (int x = 0; x < columns.size(); x++) { // عند اللمس، احفظ العنصر الذي تم النقر عليه في حالة كونه نقرة وليس تمريرًا. Final int itemToLoad = iItem; Sprite sprite = new Sprite(spriteX,spriteY,columns.get(x)){ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, Final float pTouchAreaLocalX, Final float pTouchAreaLocalY) { iItemClicked = itemToLoad; عودة كاذبة. } }; iItem++; this.mScene.attachChild(sprite); this.mScene.registerTouchArea(sprite); spriteX += 20 + PADDING+sprite.getWidth(); } mMaxX = spriteX - CAMERA_WIDTH; // تعيين حجم شريط التمرير العائمscrollbarsize = CAMERA_WIDTH/((mMaxX+CAMERA_WIDTH)/CAMERA_WIDTH); scrollBar = new Rectangle(0,CAMERA_HEIGHT-20,scrollbarsize, 20); التمرير Bar.setColor(1,0,0); this.mScene.attachChild(scrollBar); Menuleft = new Sprite(0,CAMERA_HEIGHT/2-mMenuLeftTextureRegion.getHeight()/2,mMenuLeftTextureRegion); Menuright = new Sprite(CAMERA_WIDTH-mMenuRightTextureRegion.getWidth(),CAMERA_HEIGHT/2-mMenuRightTextureRegion.getHeight()/2,mMenuRightTextureRegion); this.mScene.attachChild(menuright); Menuleft.setVisible(false); this.mScene.attachChild(menuleft); } @Override public void onLoadComplete() { } // هنا يتم استدعاء تحميل العنصر. public void LoadLevel(final int iLevel) { if (iLevel != -1) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(MenuScrollerActivity.this, "تحميل العنصر" + String.valueOf( iLevel)، Toast.LENGTH_SHORT).show(); } }}لا داعي للقلق بشأن هذا الأمر.