日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

andengine游戏引擎总结基础篇

發布時間:2024/10/12 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 andengine游戏引擎总结基础篇 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


????? 其他的游戲引擎知道的不是很對,不過相對于學java的童鞋們來說,那是個不錯的選擇啦,這個發動機咋樣,google去吧。基礎篇包括圖片,字體,音效,數據讀取,會了這點,就會做簡單的小游戲啦

?????? 對于游戲開發,也就是把靜待的圖片動態化,同時加點音效什么的。

?????? 1.圖片

??????? 1)?聲名

BitmapTextureAtlas mTexturePlayer this.mBitmapTextureAtlas = new BitmapTextureAtlas(32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA); 對于這個類,作用就相當于開辟一個內從空間,以后用來盛具體的圖片,所以,開辟大小一定要大于圖片像素大小

????????2)加載資源

????????? 分兩種,一種是TextureRegion這個加載單個圖片,另一種是TiledTextureRegion,加載可以分割的圖片

???????? TextureRegion:

private TextureRegion mFaceTextureRegion; this.mFaceTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas, this, "Menu.jpg", 0, 0)


???????????? TiledTextureRegion

private TiledTextureRegion mPlayerTextureRegion; this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mTexturePlayer, this, "player.png",0, 0, 4, 4); ?

???????????? player.png是圖片名,4,4是分割方式4*4分割方式

?????????? 3)注冊資源

this.mEngine.getTextureManager().loadTexture(this.mTextureArm0);

如果不注冊,顯示的是空白區域

只要申請了資源,就一定要注冊,就是使用了BitmapTextureAtlas,就一定要把它注冊到engine中

????????4)使用

?????? 也分兩種,一種是Sprite ,使用的是TextureRegion加載的圖片。

this.backSprite=new Sprite(0, 0, mBackgroundTextureRegion);

?????? 另一種是AnimateSprinte,這個具備動畫效果。

final AnimatedSprite player = new AnimatedSprite(centerX-200, centerY-100,this.mPlayerTextureRegion);//

???????? 具體的動畫,調用animate()函數,圖片可以使用回調函數,產生復雜的效果

final Sprite sprite = new Sprite(pX, pY, this.armsMap.get(pCard)) {boolean mGrabbed = false;@Overridepublic boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {switch(pSceneTouchEvent.getAction()) {case TouchEvent.ACTION_DOWN:this.setScale(1.25f);this.mGrabbed = true;break;case TouchEvent.ACTION_UP:if(this.mGrabbed) {if(choice>=1){armsEditor.putInt("arm", 1);armsEditor.commit();Intent myintent=new Intent(ChoiceArms.this, MenuGame.class);ChoiceArms.this.startActivity(myintent);System.gc();System.exit(0);}else if(usermoney>10){usermoney-=10;this.mGrabbed = false;this.setScale(1.0f);moneyEditor.putInt("money", usermoney);moneyEditor.commit();armsEditor.putInt("arm", 1);armsEditor.commit();choice=1;armsEditor.putInt("choice", choice);armsEditor.commit();Toast.makeText(ChoiceArms.this, "您購買了光彈", Toast.LENGTH_SHORT).show();Intent myintent=new Intent(ChoiceArms.this, MenuGame.class);ChoiceArms.this.startActivity(myintent);System.gc();System.exit(0);}else{Toast.makeText(ChoiceArms.this, "對不起,金錢不足吆", Toast.LENGTH_SHORT).show();}this.setScale(1.0f);}break;}return true;}};

上邊代碼實現觸摸選擇購買子彈,其中涉及如何用xml方式讀寫數據,會在后續進行講解

??????? 4)加載到場景中

this.mScene.attachChild(sprite);

??????? 2字體

???? 同樣分三種,聲明,加載資源,使用。

????1)聲明,申請內存資源

BitmapTextureAtlas mStrokeFontTexture;

??? 2)加載字體資源

this.mStrokeFont = new StrokeFont(this.mStrokeFontTexture, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32, true, Color.BLUE, 2, Color.YELLOW);

字體類型也很多,可以使用系統默認的,也可以使用加載的,可以是帶邊框的,也可以是不帶的

?? 3)注冊到engine中

this.mEngine.getFontManager().loadFont( this.mStrokeFont);


?

?? 4)字體使用

?? 使用好了會幫你解決不少麻煩

final Text textNormal = new Text(100, 100, this.mFont, "Just some normal Text.");比如下邊的可變字體,還有金幣字體等 mCurrBossLive=new ChangeableText(0,0, this.mStrokeFont, "?????", "?????".length());

5)加載到場景中

scene.attachChild(textStroke);

3音效使用

????????? 分為長的背景音樂(格式一般為mp3)跟短的音效(如.ogg格式,大小不超過1M)。

????????? 1)引擎聲明使用 Engine中setNeedsMusic(true).setNeedsSound(true));

Engine engine=new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE,new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),this.mBoundChaseCamera).setNeedsMusic(true).setNeedsSound(true));

???????? 2)加載資源

?????

music=MusicFactory.createMusicFromAsset(getMusicManager(), getApplicationContext(), "BlueWorld.mp3");

?

??????? 3)使用

music.play();

??????? 也有重復?music.setLooping(true);,暫停等很多功能,只需要一行代碼;


??????? 4用xml方式讀寫數據

????????????????? 1)聲明

?????????????????

public static SharedPreferences scores;private SharedPreferences.Editor scoresEditor; scores=getSharedPreferences("scores", MODE_PRIVATE);scoresEditor=scores.edit();

??????????????? 2)使用

??????????????

scores.getInt("user0",-1)//讀數據,讀的是user0中的整形數據,如果找不到,用0代替 ?????scoresEditor.putInt("suer0", count);//將整型變量count中的數據存到user0中scoresEditor.commit();//一定要提交 //SharedPreferences是用來讀的,int float string等等 //SharedPreferences.Editor用來寫的,寫完后一定要提交



?

?

?

轉載于:https://www.cnblogs.com/pangblog/p/3331264.html

總結

以上是生活随笔為你收集整理的andengine游戏引擎总结基础篇的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。