• 四 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() {

    }
    }

  • 相关阅读:
    MMORPG大型游戏设计与开发(客户端架构 part14 of vegine)
    java线程与并发(一)
    HTTP学习笔记(五)
    http学习笔记(四)——HTTP报文
    http学习笔记(三)
    http学习笔记(二)—— 嘿!伙计,你在哪?(URL)
    http学习笔记(一)
    本地DNS安装
    SQL Server求解连续操作(登录)数量(次数)最大的记录(用户)问题
    一个有趣的SQL Server 层级汇总数据问题
  • 原文地址:https://www.cnblogs.com/zhusd/p/3157052.html
Copyright © 2020-2023  润新知