其他的游戏引擎知道的不是很对,不过相对于学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; @Override
public 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用来写的,写完后一定要提交

andengine游戏引擎总结基础篇的更多相关文章

  1. andengine游戏引擎总结进阶篇2

    本篇包括瓦片地图,物理系统, 1瓦片地图 超级玛丽,冒险岛,魂斗罗等游戏主场景都有瓦片地图画成,它的作用可见一斑,它可以用tiled Qt软件画成,在辅助篇中讲讲解tiled Qt软件的使用 1)加载 ...

  2. andengine游戏引擎总结进阶篇1

    本篇包括虚拟键盘,粒子系统 1虚拟键盘 分为两种,一种是单个虚拟键盘,另一种是多个方位虚拟键盘 1)加载虚拟键盘所需要的图片资源 private BitmapTextureAtlas mOnScree ...

  3. 如何制作一款HTML5 RPG游戏引擎——第五篇,人物&人物特效

    上一次,我们实现了对话类,今天就来做一个游戏中必不可少的——人物类. 当然,你完全是可以自己写一个人物类,但是为了方便起见,还是决定把人物类封装到这个引擎里. 为了使这个类更有意义,我还给人物类加了几 ...

  4. 如何制作一款HTML5 RPG游戏引擎——第四篇,情景对话

    今天我们来实现情景对话.这是一个重要的功能,没有它,游戏将变得索然无味.所以我们不得不来完成它. 但是要知道,使用对话可不是一件简单的事,因为它内部的东西很多,比如说人物头像,人物名称,对话内容... ...

  5. 如何制作一款HTML5 RPG游戏引擎——第三篇,利用幕布切换场景

    开言: 在RPG游戏中,如果有地图切换的地方,通常就会使用幕布效果.所谓的幕布其实就是将两个矩形合拢,直到把屏幕遮住,然后再展开直到两个矩形全部移出屏幕. 为了大家做游戏方便,于是我给这个引擎加了这么 ...

  6. HTML5 RPG游戏引擎 地图实现篇

    一,话说全国年夜事   前没有暂看到lufy的专客上,有一名伴侣念要一个RPG游戏引擎,出于兴趣筹办入手做一做.因为我研讨lufylegend有冶时间了,对它有必然的依赖性,因而便筹办将那个引擎基于 ...

  7. HGE游戏引擎之实战篇,渐变的游戏开场

    #include <hge.h> #include "menuitem.h" //#include <hgefont.h> #include <hge ...

  8. 【unity3d游戏开发之基础篇】unity3d射线的原理用法以及一个利用射线实现简单拾取的小例子

    原地址:http://www.cnblogs.com/xuling/archive/2013/03/04/2943154.html 最近开始研究U3D,它的强大就不多说了, 今天研究了研究射线相关东西 ...

  9. Atitit 基于dom的游戏引擎

    Atitit 基于dom的游戏引擎 1. 添加sprite控件(cocos,createjs,dom)1 1.1.1. Cocos1 1.1.2. createjs1 1.1.3. Dom模式2 1. ...

随机推荐

  1. CDH 2、Cloudera Manager的安装

    1.Cloudera Manager • Cloudera Manager是一个管理CDH的端到端的应用. • 作用: – 管理 – 监控 – 诊断 – 集成 • 架构 • Server – 管理控制 ...

  2. Nginx日志文件配置与切割

    Nginx日志的指令主要有两条: log_format,设置日志的格式 access_log,指定日志文件的存放路径.格式和缓存大小 两条指令在Nginx配置文件中的位置可以在http{……..}之间 ...

  3. svn local delete, incoming delete upon update 解决办法

    经常有人会说,树冲突是很难解决的一类冲突,其实一旦了解了其原理,要解决也不难.先回顾下对于树冲突的定义.     树冲突:当一名开发人员移动.重命名.删除一个文件或文件夹,而另一名开发人员也对它们进行 ...

  4. Win8 使用VC6.0调试

    Win8.1下无法执行vc++6.0的解决方法 注意 安装过程中最后一步会卡在那里不动,能够直接关闭安装程序,忽略报错. 1 安装完毕后在安装文件夹下找到MSDEV.EXE 而且将 MSDEV.EXE ...

  5. BestCoder Round #14 B 称号 Harry And Dig Machine 【TSP】

    称号:Harry And Dig Machine 哈哈  最终涨边粉色了,不easy呀.顺便写一道题解吧 题意:给一个m*n的矩阵,然后当中最多由10个有值,求总左上角把全部的值都拿上回到左上角的最小 ...

  6. Swift中NSData与NSDictionary之间的相互转换

    原创Blog,转载请注明出处 使用NSKeyedUnarchiver类来进行相互转换 1.NSDictionary转NSData var dictionaryExample : [String:Any ...

  7. visual studio 2015 修改类class 文件模板

    第一步:找到模板文件 路径:C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\C ...

  8. NSNumber 和 NSValue 的部分使用

    1.NSNumber 在Objective-c中有int,float,char等基本数据类型,但这些基本数据类型并不是对象,而数组,字典,字符串等容器中存放的都是对象类型,因此我们需要用到NSNumb ...

  9. E - Number Sequence(第二季水)

    Description A single positive integer i is given. Write a program to find the digit located in the p ...

  10. jeasyui制作计划-搭建php运行环境

    1.参考链接: http://jingyan.baidu.com/article/154b46315242b328ca8f4101.html http://jingyan.baidu.com/arti ...