RokonDemo《Rokon Donate》

懒骨头(http://blog.csdn.com/iamlazybone)

Rokon:http://rokonandroid.com/

SVN:http://rokon.googlecode.com/svn/examples/donate_app

————————————————

程序运行截图:

程序很简单,三个类,Donate是捐赠的意思。

第一个类是RokonActivity.java ,入口类,负责创建引擎加载图片资源:

import com.stickycoding.rokon.DrawPriority; import com.stickycoding.rokon.RokonActivity; public class Donate extends RokonActivity { public static final float GAME_WIDTH = 8f; public static final float GAME_HEIGHT = 4.8f; private DonateScene scene; public void onCreate() { // 调试模式 debugMode(); // 强制全屏 forceFullscreen(); // 强制横屏 forceLandscape(); // 设置游戏尺寸 setGameSize(GAME_WIDTH, GAME_HEIGHT); // 使用VBO‘S渲染方式 setDrawPriority(DrawPriority.PRIORITY_VBO); // 设置图片路径 setGraphicsPath("textures/"); // 创建引擎 createEngine(); } // 引擎创建完成时调用 public void onLoadComplete() { // 加载贴图资源 Textures.load(); // 设置场景 setScene(scene = new DonateScene()); } }

然后是Textures.java,加载资源的具体实现类。

import com.stickycoding.rokon.Texture; import com.stickycoding.rokon.TextureAtlas; public class Textures { // 静态的资源管理类 public static TextureAtlas atlas; // 资源类 public static Texture background, box; public static void load() { atlas = new TextureAtlas(); atlas.insert(background = new Texture("background.png")); atlas.insert(box = new Texture("box.png")); // 资源管理类调用complete()方法之后无法再添加其他资源类。 atlas.complete(); } }

第三个类DonateScene.java,场景类,主要是往世界里添加精灵。

package com.stickycoding.rokondonatefree; import android.util.Log; import android.view.MotionEvent; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.World; import com.stickycoding.rokon.PhysicalSprite; import com.stickycoding.rokon.Scene; import com.stickycoding.rokon.background.FixedBackground; public class DonateScene extends Scene { // 小方块的个数,数量加大,卡的明显(骨头测试手机G2) private static final int BOX_COUNT = 6; // Box2D的世界类, private World world; // 静态的背景 private FixedBackground background; // 向量类 private Vector2 gravity; // 精灵类 private PhysicalSprite[] wall, box; public DonateScene() { // 创建场景(层的个数,精灵饿个数) super(3, new int[] { 1, BOX_COUNT, 1 }); setBackground(background = new FixedBackground(Textures.background)); // gravity参数,经测试,是设置原点坐标,重力方向。 setWorld(world = new World(gravity = new Vector2(0, 0), false)); createWalls(); createBoxes(); } // 由于要Box2d效果,所以需要建四面墙。 private void createWalls() { wall = new PhysicalSprite[4]; wall[0] = new PhysicalSprite(0, -1, Donate.GAME_WIDTH, 1); wall[0].createStaticBox(); add(0, wall[0]); wall[1] = new PhysicalSprite(Donate.GAME_WIDTH, 0, 1, Donate.GAME_HEIGHT); wall[1].createStaticBox(); add(0, wall[1]); wall[2] = new PhysicalSprite(0, Donate.GAME_HEIGHT, Donate.GAME_WIDTH, 1); wall[2].createStaticBox(); add(0, wall[2]); wall[3] = new PhysicalSprite(-1, 0, 1, Donate.GAME_HEIGHT); wall[3].createStaticBox(); add(0, wall[3]); } // 建立BOX_COUNT个精灵。 private void createBoxes() { box = new PhysicalSprite[BOX_COUNT]; for (int i = 0; i < BOX_COUNT; i++) { box[i] = new PhysicalSprite((float) Math.random() * Donate.GAME_WIDTH, (float) Math.random() * Donate.GAME_HEIGHT, 0.2f + (float) Math.random() * 0.5f, 0.2f + (float) Math.random() * 0.5f); box[i].setTexture(Textures.box); box[i].setRGBA((float) Math.random(), (float) Math.random(), (float) Math.random(), 1); box[i].createDynamicBox(); // 给没有贴图的精灵加边框 box[i].setBorder(0, 0, 0, 1); // 添加到第2层 add(1, box[i]); } } int x = 0, y = 0; @Override public void onGameLoop() { } @Override public void onPause() { } @Override public void onResume() { } @Override public void onReady() { } @Override public void onTouchDown(float x, float y, MotionEvent event, int pointerCount, int pointerId) { // 测试gravity参数方法:作用为设置重力方向。 gravity.set(8 - (float) Math.random() * 16, 8 - (float) Math.random() * 16); world.setGravity(gravity); Log.i("", "xx=" + world.getGravity().x + " yy=" + world.getGravity().y); } }

更多相关文章

  1. 不吹不黑!GitHub 上帮助人们学习编码的 12 个资源,错过血亏...
  2. 一款霸榜 GitHub 的开源 Linux 资源监视器!
  3. android各种资源的详细解释
  4. android 拨号面板
  5. Android学习笔记(1)-永远不变的Hello World
  6. 一定要看的 Android(安卓)资源目录的相关知识 raw drwable value
  7. 如何进行资源的热修复
  8. Android学习资源大全
  9. Android的线程详解(几种实现方法及区别)

随机推荐

  1. Python探究之旅—Python语言的基本认识
  2. 如何在Apache POI(java)中读取.docx中的字
  3. 怎么在html,Javascript,vBscript中实现从
  4. Java多线程之Thread、Runnable、Callable
  5. BufferedImage到InputStream - 格式不同
  6. 20145122《 Java网络编程》实验五实验报
  7. java操作ftp实现文件的上传下载(适用于图
  8. ***100分,谁有用java mail做的把表单直接
  9. 急求用jersey2.x+spring3.x 开发rest web
  10. 从AWS Lambda发布到SNS时超时