package lyu.edu.activity;

import java.io.IOException;

import 链接已屏蔽ponent.GameTouchEvent;

import lyu.edu.util.constants.JJYL;

import org.anddev.andengine.audio.sound.Sound;

import org.anddev.andengine.audio.sound.SoundFactory;

import org.anddev.andengine.entity.scene.Scene;

import org.anddev.andengine.entity.scene.Scene.IOnAreaTouchListener;

import org.anddev.andengine.entity.scene.Scene.ITouchArea;

import org.anddev.andengine.entity.scene.background.AutoParallaxBackground;

import org.anddev.andengine.entity.scene.background.RepeatingSpriteBackground;

import org.anddev.andengine.entity.scene.background.ParallaxBackground.ParallaxEntity;

import org.anddev.andengine.entity.sprite.AnimatedSprite;

import org.anddev.andengine.entity.sprite.Sprite;

import org.anddev.andengine.entity.text.Text;

import org.anddev.andengine.entity.util.FPSLogger;

import org.anddev.andengine.input.touch.TouchEvent;

import org.anddev.andengine.opengl.font.Font;

import org.anddev.andengine.opengl.texture.Texture;

import org.anddev.andengine.opengl.texture.TextureManager;

import org.anddev.andengine.opengl.texture.TextureOptions;

import org.anddev.andengine.opengl.texture.region.TextureRegion;

import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;

import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;

import org.anddev.andengine.opengl.texture.source.AssetTextureSource;

import org.anddev.andengine.util.HorizontalAlign;

import android.graphics.Color;

import android.graphics.Typeface;

import android.util.Log;

public class GameMainActivity extends JJYLGameActivity implements

IOnAreaTouchListener{

private static final int BUTTON_WIDTH = 128;

private static final int BUTTON_HEIGHT = 64;

private Texture mBackgroundTexture;

private TextureRegion mBackgroud;

private Texture mButtonTexture;

private TiledTextureRegion mStartRegion;

private TiledTextureRegion mSettingsRegion;

private TiledTextureRegion mExitRegion;

private Texture mFontTexture;

private Font mButtonFont;

private Sound mButtonSound;

//加载游戏资源

public void onLoadResources() {

//获取纹理管理器

TextureManager textureManager = mEngine.getTextureManager();

//加载背景图片资源

mBackgroundTexture = new Texture(1024,512,TextureOptions.DEFAULT);

mBackgroud = TextureRegionFactory.createFromAsset(mBackgroundTexture, this, "gfx/start.jpg", 0, 0);

// 申请显示按钮所需的纹理资源

mButtonTexture = new Texture(BUTTON_WIDTH, BUTTON_HEIGHT * 2,

TextureOptions.BILINEAR_PREMULTIPLYALPHA);

// 基于所申请的纹理资源构建按钮

AssetTextureSource source = new AssetTextureSource(this,

"gfx/button.png");

mStartRegion = TextureRegionFactory.createTiledFromSource(

mButtonTexture, source, 0, 0, 1, 2);

mSettingsRegion = TextureRegionFactory.createTiledFromSource(

mButtonTexture, source, 0, 0, 1, 2);

mExitRegion = TextureRegionFactory.createTiledFromSource(

mButtonTexture, source, 0, 0, 1, 2);

// 申请构建字体所需的纹理资源

mFontTexture = new Texture(BUTTON_WIDTH, BUTTON_HEIGHT,

TextureOptions.DEFAULT);

// 构建字体

mButtonFont = new Font(mFontTexture, Typeface.create(Typeface.DEFAULT,

Typeface.BOLD), 16, true, Color.WHITE);

// 将纹理资源加载到纹理管理器中

textureManager.loadTexture(mButtonTexture);

textureManager.loadTexture(mBackgroundTexture);

textureManager.loadTexture(mFontTexture);

// 加载字体资源

mEngine.getFontManager().loadFont(mButtonFont);

if (getGame().isSoundOn()) {

// 加载声音资源

SoundFactory.setAssetBasePath("sound/");

try {

mButtonSound = SoundFactory.createSoundFromAsset(getEngine()

.getSoundManager(), this, "Sound_5.mp3");

mButtonSound.setVolume(10f);

} catch (IOException e) {

Log.e("Game", e.getMessage());

}

}

}

//加载场景类

public Scene onLoadScene() {

this.mEngine.registerUpdateHandler(new FPSLogger());

//创建scene

Scene scene = new Scene();

//为scene创建背景

float StartGamePositionX= 50;

float StartGamePositionY = 270;

AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);

autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, new Sprite(0,

JJYL.CAMERA_HEIGHT - this.mBackgroud.getHeight(), this.mBackgroud)));

scene.setBackground(autoParallaxBackground);

// 创建按钮对象

AnimatedSprite spriteStart = new AnimatedSprite(StartGamePositionX, StartGamePositionY, BUTTON_WIDTH,

BUTTON_HEIGHT, mStartRegion);

spriteStart.setUserData(JJYL.START_GAME);

// 创建按钮文本

Text textStart = new Text(StartGamePositionX, StartGamePositionY, mButtonFont, JJYL.START_GAME,

HorizontalAlign.CENTER);

float textX = StartGamePositionX + (BUTTON_WIDTH - textStart.getWidthScaled()) / 2;

float textY =StartGamePositionY + (BUTTON_HEIGHT - textStart.getHeightScaled()) / 2;

textStart.setPosition(textX, textY);

StartGamePositionY += BUTTON_HEIGHT * 1.5f;

AnimatedSprite spriteSettings = new AnimatedSprite(StartGamePositionX, StartGamePositionY, BUTTON_WIDTH,

BUTTON_HEIGHT, mSettingsRegion);

spriteSettings.setUserData(JJYL.SETTINGS);

Text textSettings = new Text(StartGamePositionX, StartGamePositionY, mButtonFont, JJYL.SETTINGS,

HorizontalAlign.CENTER);

textX =StartGamePositionX + (BUTTON_WIDTH - textSettings.getWidthScaled()) / 2;

textY =StartGamePositionY + (BUTTON_HEIGHT - textSettings.getHeightScaled()) / 2;

textSettings.setPosition(textX, textY);

StartGamePositionY += BUTTON_HEIGHT * 1.5f;

AnimatedSprite spriteExit = new AnimatedSprite(StartGamePositionX, StartGamePositionY, BUTTON_WIDTH,

BUTTON_HEIGHT, mExitRegion);

spriteExit.setUserData(JJYL.EXIT);

Text textExit = new Text(StartGamePositionX, StartGamePositionY, mButtonFont, JJYL.EXIT,

HorizontalAlign.CENTER);

textX =StartGamePositionX + (BUTTON_WIDTH - textExit.getWidthScaled()) / 2;

textY =StartGamePositionY + (BUTTON_HEIGHT - textExit.getHeightScaled()) / 2;

textExit.setPosition(textX, textY);

// 注册按钮触发监听事件

scene.registerTouchArea(spriteStart);

// 将按钮和文本添加到Scene

scene.attachChild(spriteStart);

scene.attachChild(textStart);

scene.registerTouchArea(spriteSettings);

scene.attachChild(spriteSettings);

scene.attachChild(textSettings);

scene.registerTouchArea(spriteExit);

scene.attachChild(spriteExit);

scene.attachChild(textExit);

// 注册Touch事件监听器

scene.setOnAreaTouchListener(this);

return scene;

}

public void onLoadComplete() {

}

//释放资源

public void onUnLoadResources(){

super.onUnloadResources();

if(getGame().isSoundOn()){

if(mButtonSound != null){

//释放声音资源

mButtonSound.stop();

mButtonSound.release();

}

}

}

public boolean onAreaTouched(TouchEvent pSceneTouchEvent,

ITouchArea pTouchArea, float pTouchAreaLocalX,

float pTouchAreaLocalY) {

//如果按钮被按下

if(pSceneTouchEvent.isActionDown()){

//播放声音效果

if(getGame().isSoundOn()){

mButtonSound.play();

}

//播放动画效果

AnimatedSprite sprite = (AnimatedSprite)pTouchArea;

sprite.animate(new long[]{200,200,200,200},0,3,true);

// 通知游戏主控制类

getGame().notifyButtonTouched(

new GameTouchEvent(pSceneTouchEvent, pTouchArea));

}

return false;

}

}



更多源码 | 好库简介 | 网站地图 | 帮助中心 | 版权说明

Copyright© 2009-2012 OKBASE.NET All Rights Reserved 好库网 版权所有

斗破苍穹java_安卓斗破苍穹游戏源码相关推荐

  1. 安卓超级玛丽游戏源码完整下载

    今天很高兴在源码天堂android源码频道上看到了一个安卓超级玛丽游戏源码完整,该源码比较不错,而且源码游戏也是我们经常玩的一种,非常不错,现在分享给大家看看吧. 源码下载:http://code.6 ...

  2. 高仿精仿安卓疯狂猜图游戏源码

    给大家分享一款不错的高仿精仿安卓疯狂猜图游戏源码,喜欢的朋友可以下载看看. 游戏 <ignore_js_op> 源码下载 http://code.662p.com/view/2960.ht ...

  3. 分享一款最近比较火爆的宝石迷情游戏游戏源码安卓版

    这个是本人上几个月的一个作品,该作品我已经发布到安卓教程网了,现在分享这款宝石迷情游戏游戏源码安卓版吧,这是一款经典的宝石迷情小游戏源码宝石迷情是一款跨平台的宝石消除类游戏,和之前的宝石类消除游戏不同 ...

  4. unity3D埃及探险游戏源码,支持安卓+IOS双端 unity2019 C#语言开发

    unity3D埃及探险游戏源码,支持安卓+IOS双端 unity2019 C#语言开发.完整的源码可直接运营.拿来学习研究和二次开发都很不错. 源码下载 unity3D埃及探险游戏源码C#语言开发.完 ...

  5. 3D休闲游戏夺宝向前冲3D游戏源码H5+安卓+IOS三端源码

    cocos creator3D1.2休闲游戏夺宝向前冲3D游戏源码H5+安卓+IOS三端源码,开发脚本为typeScript方便扩展和阅读,支持cocos creator3D版本,完整的源码可直接运营 ...

  6. cocos creator2.4.4 英文卡牌游戏源码H5+安卓+IOS三端源码

    cocos creator2.4.4 英文卡牌游戏源码H5+安卓+IOS三端源码,开发脚本为typeScript方便扩展和阅读,支持cocos creator2.X版本,完整的源码可直接运营.纯英文版 ...

  7. cocos creator2.4.4益智教育游戏源码《顶级食物链》源码H5+安卓+IOS三端源码

    cocos creator2.4.4益智教育游戏源码<顶级食物链>源码H5+安卓+IOS三端源码,开发脚本为typeScript方便扩展和阅读,支持cocos creator2.X版本,完 ...

  8. Unity密室逃脱-逃离房间游戏源码.,支持安卓+IOS双端 unity2021 C#语言开发

    Unity密室逃脱-逃离房间游戏源码.,支持安卓+IOS双端 unity2021 C#语言开发.完整的源码可直接运营.拿来学习研究和二次开发都很不错. 源码下载 unity密室逃脱-逃离房间游戏源码C ...

  9. unity5.X简易的3d跑酷游戏源码。支持安卓+IOS双端 C#语言开发。

    unity5.X简易的3d跑酷游戏源码.支持安卓+IOS双端 C#语言开发.拿来学习研究和二次开发都很不错. 完整源码下载 unity5.X简易的3d跑酷游戏源码.支持安卓+IOS双端C#语言开发-U ...

最新文章

  1. 「工科神器」MATLAB风波未平,「化学神器」ChemOffice再爆清查国内盗版行为
  2. 登陆窗体显示动态效果
  3. 模拟usb设备_高速USB数据采集卡
  4. strong与em、q、cite、blockquote区别
  5. Oracle外键需要建索引吗?
  6. linux如何升级cmake,ubuntu下升级cmake
  7. [转]张孟苏考上的不是大学
  8. python编程求极限_Sympy笔记一
  9. pytorch ner
  10. javascript xml转json
  11. 从caffe2 开源的代码中抽取 用于加载已训练神经网络参数,使用CPU进行预测的 部分代码,并运行成功一个预测模型...
  12. Linux Linux内核参数调优
  13. 2.1简单计算问题的求解
  14. 创强教师办公用计算机配备要求,教师办公室电脑使用与管理有哪些规定
  15. Ruby / Rails代码气味基础01
  16. nextpolish安装_使用nextpolish对三代组装进行polish
  17. 在python中用于获取用户输入的是-在Python中,用于获取用户输入的函数是
  18. php云扫墓平台_让“云”成为清明祭扫新平台
  19. SAP PS 第2节 项目状态及字段选择
  20. 必看!2021年云计算行业五大趋势,云南昆明企业小型云计算平台搭建及解决方案

热门文章

  1. 为淘宝网店免费使用流量统计教程
  2. 《重构》第三章 - 读后感(发散、散弹、依恋)
  3. HTML5期末大作业:在线电影介绍(6页) HTML+CSS+JavaScript 大学生毕设网页设计源码HTML web网页设计制作成品
  4. 《途客圈创业记:不疯魔,不成活》一一2.6 组建团队
  5. 关于全球苹果手机的型号版本介绍
  6. android 黑白棋源码,黑白棋源代码
  7. 北大考研复试上机——W's Cipher
  8. CCF A类会议或期刊----多视图,多模态近两年论文
  9. 女程序员开淘宝店兼职---详细注册成为淘宝商家步骤
  10. 神经网络优化算法总结