1:首先我们此游戏使用libgdx引擎,当然这个算是废话了。
2:我们使用libgdx引擎里面的Screen来作为我们的场景。
3:本讲首先来实现游戏中的第一个info界面,显示一个图标以及一个动画和一个返回按钮。

界面如下:

我们来看下代码实现:

package com.example.gamedemo;

import android.util.Log;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureAtlas.AtlasRegion;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Timer;
import com.badlogic.gdx.utils.Timer.Task;

public class InfoScreen extends ScreenAdapter {

Stage Ui;
SpriteBatch Batch;
private TextureAtlas atlas;
private Sprite sprite;
private Sprite Title;
FirstGame Gm;
Animation flyMove;
Array<TextureRegion> keyFramesArray = new Array<TextureRegion>();
float stateTime = 0f;
float x, y;
int regionWidth, regionHeight;
AtlasRegion Region;
float flyMovex;
ImageButton Back;

public InfoScreen(FirstGame tGm) {
// TODO Auto-generated constructor stub
this.Gm = tGm;

Batch = new SpriteBatch();
Ui = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
atlas = new TextureAtlas(Gdx.files.internal("shoot_background.pack"));
sprite = atlas.createSprite("background");
sprite.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Title = atlas.createSprite("shoot_copyright");
Region = atlas.findRegion("game_loading3");
flyMovex = (Gdx.graphics.getWidth() - Region.getRegionWidth()) / 2;
keyFramesArray.add(atlas.findRegion("game_loading1"));
keyFramesArray.add(atlas.findRegion("game_loading2"));
keyFramesArray.add(atlas.findRegion("game_loading3"));
keyFramesArray.add(atlas.findRegion("game_loading4"));
flyMove = new Animation(0.3f, keyFramesArray);
x = (Gdx.graphics.getWidth() - Title.getWidth()) / 2;
y = (Gdx.graphics.getHeight() - (Title.getHeight() + 150));
regionWidth = Title.getRegionWidth();
regionHeight = Title.getRegionHeight();
Title.setPosition(x, y);

ImageButtonStyle style = new ImageButtonStyle();
style.imageUp = new TextureRegionDrawable(
atlas.findRegion("btn_finish"));
style.imageDown = new TextureRegionDrawable(
atlas.findRegion("btn_finish"));
Back = new ImageButton(style);

Back.addListener(new ClickListener() {
public void clicked(InputEvent event, float x, float y) {
Gm.EndGame();

}
});
Back.setX(Gdx.graphics.getWidth() - Back.getWidth() - 2);
Back.setY(10);
Ui.addActor(Back);
Gdx.input.setInputProcessor(Ui);

new Timer().scheduleTask(new Task() {

@Override
public void run() {
// TODO Auto-generated method stub
Log.i("lxmlxm", "timer ok!");
Gm.setScreen(new GameScreen(Gm));
}
}, 3);

}

@Override
public void render(float delta) {
// TODO Auto-generated method stub
super.render(delta);
Batch.begin();
sprite.draw(Batch);
Title.draw(Batch);
stateTime += delta;
TextureRegion frame = flyMove.getKeyFrame(stateTime, true);
Batch.draw(frame, flyMovex, y - 80 - Region.getRegionHeight());
Batch.end();
Ui.draw();

}

@Override
public void resume() {
// TODO Auto-generated method stub
super.resume();
Gdx.input.setInputProcessor(Ui);
}

@Override
public void pause() {
// TODO Auto-generated method stub
super.pause();
Gdx.input.setInputProcessor(null);
}

@Override
public void hide() {
// TODO Auto-generated method stub
super.hide();
}

@Override
public void dispose() {
// TODO Auto-generated method stub
super.dispose();
Batch.dispose();
Ui.dispose();
atlas.dispose();

}

}

这个界面相对来说比较简单,只是一个image 一个动画 以及一个button组合在一起,button增加退出实现。
添加一个timer实现3s跳到游戏主界面中,开始真正的打飞机游戏了。

libgdx 打飞机游戏实现教程相关推荐

  1. Python开发打飞机游戏

    作者:晓晓 链接:https://zhuanlan.zhihu.com/p/21290174 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 一.项目简介 1. 介绍 ...

  2. libgdx教程_使用libgdx进行Android游戏开发–一天中的原型,第1a部分

    libgdx教程 在本文中,我将绕开游戏引擎和组件的构建模块,并演示如何使用libgdx库快速制作游戏原型. 您将学到什么: 创建一个非常简单的2D Shooter Platformer游戏. 完整的 ...

  3. html5 游戏制作教程,利用HTML5 Canvas制作一个简单的打飞机游戏

    之前在当耐特的DEMO里看到个打飞机的游戏,然后就把他的图片和音频扒了了下来....自己凭着玩的心情重新写了一个.仅供娱乐哈......我没有用框架,所有js都是自己写的......所以就可以来当个简 ...

  4. libgdx教程_使用libgdx进行Android游戏开发–一天中的原型,第1b部分

    libgdx教程 创造游戏并展现世界 要将世界渲染到屏幕上,我们需要为其创建一个屏幕,并告诉它渲染世界. 在libgdx中,有一个名为Game的便利类,我们将把StarAssault类重写为StarA ...

  5. 【软件教程 §微信打飞机游戏无敌补丁:无敌模式开启方法】

    [软件教程 §微信打飞机游戏无敌补丁:无敌模式开启方法]  微信5.0上线,游戏中心内置游戏<经典飞机大战>(俗称打飞机游戏)一天之内便遭遇破解,已越狱手机可开启无敌模式. 小编整理了微信 ...

  6. [libGDX游戏开发教程]使用LibGDX进行游戏开发(1)-游戏设计

    声明:本章是一个系列的开始,英文原文是<Learning libGDX Game Development>,大家请周知. [libgdx游戏开发教程]使用Libgdx进行游戏开发(2)-游 ...

  7. [libgdx游戏开发教程]使用Libgdx进行游戏开发(10)-音乐音效不求人,程序员也可以DIY

    本章音效文件都来自于公共许可:  http://files.cnblogs.com/mignet/sounds.zip 在游戏中,播放背景音乐和音效是基本的功能. Libgdx提供了跨平台的声音播放功 ...

  8. libgdx开发指南_使用libgdx进行Android游戏开发–一天中的原型,第1a部分

    libgdx开发指南 在本文中,我将绕开游戏引擎和组件的构建模块,并演示如何使用libgdx库快速制作游戏原型. 您将学到什么: 创建一个非常简单的2D Shooter Platformer游戏. 完 ...

  9. python 之路200行Python代码写了个打飞机游戏

    先看一下项目结构 \ """ PlayPlane/ |-- bin/ | |-- main.py 程序运行主体程序 |-- config/ | |-- settings. ...

最新文章

  1. Go 语言编程 — 内存分配
  2. python可变参数的特点_可变参数**kwargs传入函数时的存储方式为( )_学小易找答案...
  3. Swoole入门指南:PHP7安装Swoole详细教程(一)
  4. 如何在android studio中设置sdk path?
  5. 昆仑通态触摸屏数据转发上传_嵌_ModbusTcpIp数据转发 昆仑通态屏与屏之间通讯 - 下载 - 搜珍网...
  6. Wonder——Auggie | Education
  7. 字符串固定长度 易语言_易语言宽字符数据类型怎么设置
  8. Python使用HappyBase连接Hbase与基本操作
  9. 快速崛起的物联网世界安全问题
  10. 计算机科学技术考研内容,计算机科学技术考研考什么科目
  11. 云存储收银系统_重磅丨远丰云收银系统WebPos升级 开启智能收银新时代
  12. 高等数学求导公式复习
  13. java 中怎么打印一个日历_日历打印用java实现
  14. springboot+vue+elementUI 校园志愿者管理系统#毕业设计
  15. js中输出2000~2100年之间所有的闰年;
  16. c语言内联int 21h,[X64内核]SMAP,SMEP
  17. beyond compare 4 This license key has been revoked 解决办法
  18. 进程间通信(IPC (Inter-process communication))
  19. OpenLayers应用一(转自http://www.cnblogs.com/lzlynn/)
  20. 面试必问---TCP连接

热门文章

  1. 百度地图 控件——路网地图和影像地图切换
  2. Jboot 跨域请求
  3. PHP 项目 该网页无法正常运作情况,但没有报错
  4. mysql语句中limt_mysql sql语句中的limit用法
  5. SpringBoot+Vue实现简单用户管理平台第一篇(后端接口设计)
  6. python实验心得体会范文大全_万能实验报告心得体会5篇范文
  7. php实现短信找回密码,thinkphp5怎么调用云片接口实现发送短信验证码找回密码功能...
  8. R语者小case之——从KEGG原始网页批量生成通路的基因表格
  9. 南京工业大学计算机学院考研真题,南京工业大学考研真题汇总
  10. 云安全软件市场现状研究分析报告 -