当前位置:  编程技术>移动开发
本页文章导读:
    ▪AndEngine学习札记(二) LineExample        AndEngine学习笔记(二) LineExample 项目地址:http://code.google.com/p/andengine/     LineExample源码:       package org.anddev.andengine.examples; import java.util.Random; import org.anddev.andengine.engine.Engine; import org.andd.........
    ▪ 汉语 Api        中文 Api http://android.toolib.net/index.htmlhttp://androidbox.sinaapp.com/ ......
    ▪ 多点抚摸的简单示例       多点触摸的简单示例 - (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ touchLabel.text = @"Touches Began"; } - (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{ touchLabel.text = @"Touches Cancelled"; } -.........

[1]AndEngine学习札记(二) LineExample
    来源: 互联网  发布时间: 2014-02-18
AndEngine学习笔记(二) LineExample

项目地址:http://code.google.com/p/andengine/

 

 

LineExample源码:

 

 

 

package org.anddev.andengine.examples;

import java.util.Random;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.primitive.Line;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.background.ColorBackground;
import org.anddev.andengine.entity.util.FPSLogger;

/**
 * @author Nicolas Gramlich
 * @since 11:54:51 - 03.04.2010
 */
public class LineExample extends BaseExample {
	// ===========================================================
	// Constants
	// ===========================================================

	/* Initializing the Random generator produces a comparable result over different versions. */
	private static final long RANDOM_SEED = 1234567890;

	private static final int CAMERA_WIDTH = 720;
	private static final int CAMERA_HEIGHT = 480;

	private static final int LINE_COUNT = 100;

	// ===========================================================
	// Fields
	// ===========================================================

	private Camera mCamera;

	// ===========================================================
	// Constructors
	// ===========================================================

	// ===========================================================
	// Getter & Setter
	// ===========================================================

	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================

	@Override
	public Engine onLoadEngine() {
		this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
		return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
	}

	@Override
	public void onLoadResources() {

	}

	@Override
	public Scene onLoadScene() {
		this.mEngine.registerUpdateHandler(new FPSLogger());

		final Scene scene = new Scene(1);
		scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));

		final Random random = new Random(RANDOM_SEED);

		for(int i = 0; i < LINE_COUNT; i++) {
			final float x1 = random.nextFloat() * CAMERA_WIDTH;
			final float x2 = random.nextFloat() * CAMERA_WIDTH;
			final float y1 = random.nextFloat() * CAMERA_HEIGHT;
			final float y2 = random.nextFloat() * CAMERA_HEIGHT;
			final float lineWidth = random.nextFloat() * 5;

			final Line line = new Line(x1, y1, x2, y2, lineWidth);

			line.setColor(random.nextFloat(), random.nextFloat(), random.nextFloat());

			scene.getTopLayer().addEntity(line);
		}

		return scene;
	}

	@Override
	public void onLoadComplete() {

	}

	// ===========================================================
	// Methods
	// ===========================================================

	// ===========================================================
	// Inner and Anonymous Classes
	// ===========================================================
}
 

 

 

在onLoadEngine里,Camera是一个重点,EngineOption也是一个。

 

Camera:A Camera defines the rectangle of the scene that is drawn on the screen, as not the whole scene is visible all the time. Usually there is one Camera per Scene, except for the SplitScreenEngines. There are subclasses that allow zooming and smooth position changes of the Camera.

Camera定义了在屏幕上的矩形Scene,因为不是整个Scene都是一直可见的。通常一个Camera对应一个Scene,除非是SplitScreenEngines.它通过Camera允许放大,平移和变换位置。


EngineOption:EngineOption需要四个参数,分别是 FullScreen(是否全屏) ScreenOrientaiton(横屏或竖屏) RatioResolutionPolicy(放大缩小比例) Camera(前文的Camera)

RatioResolutionPolicy 需要new RatioResolutionPolicy(int width, int height)按比例修正画面大小,以适应屏幕大小

 

 

在onLoadScene()经常会看到registerUpdateHandler()和Scene的用法

 

registerUpdateHandler()暂略


Scence:The Scene class is the root container for all objects to be drawn on the screen. A Scene has a specific amount of Layers, which themselves can contain a (fixed or dynamic) amount of Entities. There are subclasses, like the CameraScene/HUD/MenuScene that are drawing themselves to the same position of the Scene no matter where the camera is positioned to.


Scene类是屏幕里面的所有对象的根容器。Scene拥有指定的Layer,这些 Layer能拥有多个(固定或动态的)实例。它的子类如CameraScene/HUD/MenuScene都是画在同一个位置上不管camera的位置是哪里。

 

 


    
[2] 汉语 Api
    来源: 互联网  发布时间: 2014-02-18
中文 Api
http://android.toolib.net/index.html
http://androidbox.sinaapp.com/

    
[3] 多点抚摸的简单示例
    来源: 互联网  发布时间: 2014-02-18
多点触摸的简单示例
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
	touchLabel.text = @"Touches Began";
}

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
	touchLabel.text = @"Touches Cancelled";
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
	touchLabel.text = @"Touches Stopped";
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
	touchLabel.text = @"Drag detected";
}

 

需要注意的是:在Interface Builder中,必须将view的属性Interaction里的两项User Interaction Enabled和Multiple Touch都勾上。


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3