zoukankan      html  css  js  c++  java
  • 四 AndEngine 画线

    package com.example.AndEngineExample02;

    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.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;
    import org.anddev.andengine.ui.activity.BaseGameActivity;

    import java.util.Random;

    public class MyActivity extends BaseGameActivity {
    private int CAMERA_WIDTH = 720; //摄像机宽度
    private int CAMERA_HEIGHT = 480;//摄像机高度
    private Camera mCamera; //摄像机对象
    private long RANDOM_SEED=1234567890; //随机数种子

    @Override
    public Engine onLoadEngine() {
    //创建摄像机
    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    //创建引擎选项
    EngineOptions engineOptions=new EngineOptions(true, EngineOptions.ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera);
    //创建引擎并返回它
    return new Engine(engineOptions);
    }

    @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));
    //创建随机数对象
    Random random=new Random(RANDOM_SEED);
    for(int i=0;i<100;i++){
    float x1=random.nextFloat()*CAMERA_WIDTH;
    float y1=random.nextFloat()*CAMERA_HEIGHT;
    float x2=random.nextFloat()*CAMERA_WIDTH;
    float y2=random.nextFloat()*CAMERA_HEIGHT;
    Line line=new Line(x1,y1,x2,y2);
    line.setColor(random.nextFloat(),random.nextFloat(),random.nextFloat());
    scene.getTopLayer().addEntity(line);
    }
    //返回场景对象
    return scene;
    }

    @Override
    public void onLoadComplete() {

    }
    }

  • 相关阅读:
    UI5-技术篇-Hybrid App-1-Barcode扫描
    UI5-技术篇-How to Extend Fiori Applications
    UI5-技术篇-事务Tcode
    UI5-技术篇-SAPUI5创建自定义控件
    ABAP-信息结构S901/S902程序问题
    ABAP-会计凭证替代字段GB01设置
    UI5-技术篇-Navigation And Routing
    前后端分离djangorestframework—— 接入微信模板消息推送
    前后端分离djangorestframework—— 接入支付宝支付平台
    前后端分离djangorestframework—— 接入第三方的验证码平台
  • 原文地址:https://www.cnblogs.com/zhusd/p/3157052.html
Copyright © 2011-2022 走看看