Android使用AndEngine创建第一个程序
2024-07-02 01:15:34 224人阅读
首先要把andengine.jar复制到libs文件夹里
03 | import org.anddev.andengine.engine.Engine; |
04 | import org.anddev.andengine.engine.camera.Camera; |
05 | import org.anddev.andengine.engine.options.EngineOptions; |
06 | import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation; |
07 | import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy; |
08 | import org.anddev.andengine.entity.scene.Scene; |
09 | import org.anddev.andengine.entity.sprite.Sprite; |
10 | import org.anddev.andengine.opengl.texture.TextureOptions; |
11 | import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas; |
12 | import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory; |
13 | import org.anddev.andengine.opengl.texture.region.TextureRegion; |
14 | import org.anddev.andengine.ui.activity.BaseGameActivity; |
16 | public class MainActivity extends BaseGameActivity { |
18 | public static int CAMERA_WIDTH = 320; |
19 | public static int CAMERA_HEIGHT = 480; |
21 | public Camera mCamera; |
23 | private BitmapTextureAtlas bgTexture; |
24 | private TextureRegion background; |
26 | public Engine onl oadEngine() { |
27 | this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);//创建相机 |
28 | return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT, |
29 | new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), |
33 | public void onl oadResources() { |
34 | bgTexture = new BitmapTextureAtlas(1024, 1024, |
35 | TextureOptions.BILINEAR_PREMULTIPLYALPHA); |
36 | background = BitmapTextureAtlasTextureRegionFactory.createFromAsset(//从资产读取图片 |
37 | bgTexture, this, "colorful.png", 0, 0); |
38 | this.getEngine().getTextureManager().loadTextures(bgTexture); |
41 | public Scene onl oadScene() { |
43 | mScene.setTouchAreaBindingEnabled(true); |
47 | public void onl oadComplete() { |
48 | Sprite bgd = new Sprite(0, 0, background); |
49 | mScene.attachChild(bgd); |
<iframe id="google_ads_frame2" vspace="0" height="250" marginHeight="0" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-3447371224873639&output=html&h=250&slotname=8660799060&adk=1970350646&w=300&lmt=1398829959&flash=11.9.900.117&url=http%3A%2F%2Fwww.cnblogs.com%2Fxiaochao1234%2Fp%2F3699021.html&dt=1398829937327&shv=r20140424&cbv=r20140417&saldr=sb&prev_slotnames=4356862740&correlator=1398829937188&frm=20&ga_vid=429972749.1397695120&ga_sid=1398816550&ga_hid=377506283&ga_fc=1&u_tz=480&u_his=409&u_java=1&u_h=768&u_w=1364&u_ah=740&u_aw=1364&u_cd=16&u_nplug=0&u_nmime=0&dff=verdana&dfs=16&adx=0&ady=2281&biw=314&bih=74&eid=317150304%2C317150312&oid=3&rx=0&eae=0&docm=9&vis=0&fu=0&ifi=2&xpc=2BzjXhhTMR&p=http%3A//www.cnblogs.com&dtd=43" frameBorder="0" width="300" allowTransparency="true" name="google_ads_frame2" marginWidth="0" scrolling="no" hspace="0"></iframe><iframe id="google_ads_frame3" vspace="0" height="250" marginHeight="0" src="http://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-3447371224873639&output=html&h=250&slotname=8660799060&adk=1970350646&w=300&lmt=1398829959&flash=11.9.900.117&url=http%3A%2F%2Fwww.cnblogs.com%2Fxiaochao1234%2Fp%2F3699021.html&dt=1398829937377&shv=r20140424&cbv=r20140417&saldr=sb&prev_slotnames=4356862740%2C8660799060&correlator=1398829937188&frm=20&ga_vid=429972749.1397695120&ga_sid=1398816550&ga_hid=377506283&ga_fc=1&u_tz=480&u_his=409&u_java=1&u_h=768&u_w=1364&u_ah=740&u_aw=1364&u_cd=16&u_nplug=0&u_nmime=0&dff=verdana&dfs=16&adx=306&ady=2531&biw=314&bih=74&eid=317150304%2C317150312&oid=3&rx=0&eae=0&docm=9&vis=0&fu=0&ifi=3&xpc=wfXUX3Z6hd&p=http%3A//www.cnblogs.com&dtd=47" frameBorder="0" width="300" allowTransparency="true" name="google_ads_frame3" marginWidth="0" scrolling="no" hspace="0"></iframe>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉:
投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。