Cocos2d-X 安卓中禁止锁屏,音量调节,TexturePacker文件在函数中的具体使用
来源:互联网 发布:战斗行动预测数据库 编辑:程序博客网 时间:2024/05/01 23:29
做游戏过程中会有一些比较有价值的方法或要点,在此记下,为了方便自己日后查看,也为了给大家一个提醒!
1、有时候临时加载一个帧较多的动画可能会有点卡,但更重要的是可能会影响到其它的功能,我曾经遇到这样的问题:在点击菜单按钮时播放一个动画,结果这个动画帧数较多,播放的时候有些卡,接着可能出现点击了2次按钮动画才播放,同时这个按钮对应的方法也执行了两次,这就出现了大问题。出现这种情况时,我只找到了一个简单的方法,就是在init方法中预加载。因为图片资源加载到内存后,第二次播放就不会那么卡了。
2、安卓下的两个应用:关于调节声音和禁止锁屏
//禁止屏幕锁屏getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);//声音设置setVolumeControlStream(AudioManager.STREAM_MUSIC);
3、TexturePacker合成文件的使用步骤
使用TexturePacker的好处:
_1、在.h中初始化一个全局变量
CCSpriteFrameCache *cacheNpc;//怪物图
_2、在init函数或构造中初始化
cacheNpc = CCSpriteFrameCache::sharedSpriteFrameCache();
cacheNpc->addSpriteFramesWithFile("enemy.plist");
(这么写不对:cacheNpc = CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("enemy.plist");)
_3、使用合成图片资源
CCSprite *sp= CCSprite::createWithSpriteFrame(cacheNpc->spriteFrameByName("enemy1ying.png"));
_4、合成图片集可以在别的类中使用(比如说你要在GameMap类中使用GameLayer类中曾使用过的图片集中的某个图片)
我们在GameLayer类中按照以上前3个步骤完成了图片集的初始化:
(1)在GameLayer.h中添加:
//初始化一个变量名称cacheNpc
CCSpriteFrameCache *cacheNpc;//怪物图
static GameLayer* shareGameLayer();
写成一个静态方法是为了别的类中调用方便
(2)在GameLayer.cpp中实现一些方法:
static GameLayer * gl;
GameLayer* GameLayer::shareGameLayer()
{
if (gl !=NULL)
{
return gl;
}
return NULL;
}
cacheNpc->addSpriteFramesWithFile("enemy.plist");
_5、关于_4中说的问题补充个例子,也补充些其他内容,也注意几个问题
CCSpriteFrameCache *spriteFrame_go;在Go.cpp文件的init()方法中,完成初始化:
spriteFrame_go=CCSpriteFrameCache::sharedSpriteFrameCache();spriteFrame_go->addSpriteFramesWithFile("go.plist");gl=this;
则在GameStart.cpp中使用时,记得添加引用
#include "Go.h"代码如下:
//添加金币图片 CCSprite *gold=CCSprite::createWithSpriteFrame(Go::sharedGo()->spriteFrame_go->spriteFrameByName("gold.png")); gold->setPosition(ccp(190,455)); this->addChild(gold);上面的代码部分只是参考,也可以创建一个单独的类,来实现该动能:
#pragma once#include "cocos2d.h"using namespace cocos2d;class BackGroundJpg:public cocos2d::CCLayer{public://变量//背景图片参数CCSpriteFrameCache *backGroundJpg;//函数static BackGroundJpg *sharedBackGroundJpg();BackGroundJpg(void);~BackGroundJpg(void);};BackGroundJpg.cpp文件中代码:
#include "BackGroundJpg.h"static BackGroundJpg*gl;BackGroundJpg::BackGroundJpg(void){backGroundJpg=CCSpriteFrameCache::sharedSpriteFrameCache();backGroundJpg->addSpriteFramesWithFile("background.plist");gl=this;}BackGroundJpg *BackGroundJpg::sharedBackGroundJpg(){BackGroundJpg *bg=new BackGroundJpg();//只有new时,才会执行构造函数,完成初始化if (gl!=NULL){return gl;}return NULL;}在别的类中使用时先添加引用:
#include "BackGroundJpg.h"
shouye = CCSprite::createWithSpriteFrame(BackGroundJpg::sharedBackGroundJpg()->backGroundJpg->spriteFrameByName("shouye.jpg"));shouye->setPosition(ccp(400,240));this->addChild(shouye);
- Cocos2d-X 安卓中禁止锁屏,音量调节,TexturePacker文件在函数中的具体使用
- TexturePacker打包后的文件在cocos2d-x加载和使用
- Cocos2d-x TexturePacker的使用
- Cocos2d-x TexturePacker的使用
- 【cocos2d-x】TexturePacker 使用心得
- Cocos2d-x:TexturePacker的使用
- cocos2d-x在Command Line中使用TexturePacker
- cocos2d-x 控制android硬件音量大小调节按钮
- Cocos2D-x 用CCControlSlider设置调节音量的大小
- 为cocos2d-x添加调节视频音量的功能(Android)
- cocos2d-x之texturepacker的使用
- cocos2d-x 项目里使用TexturePacker
- cocos2d-x使用TexturePacker打包图片及使用生成的plist文件创建精灵动画
- cocos2d-x使用TexturePacker打包图片及使用生成的plist文件创建精灵动画
- cocos2d 使用TexturePacker制作plist文件
- TexturePacker打包后的带透明度的图片在cocos2d-x中使用时有黑边
- lua使用cocos2d-x中的函数
- 【Cocos2d-x游戏引擎开发笔记(22)】TexturePacker的使用
- 整理点缺少framework的报错信息
- C语言中将二维数组作为参数传递给函数的方法
- shell脚本,自动登陆ftp,下载文件
- php实现下载远程文件的代码
- python的redis客户端性能
- Cocos2d-X 安卓中禁止锁屏,音量调节,TexturePacker文件在函数中的具体使用
- python实现aes加密解密,RSA签名和验签,RSA加密解密,并调用接口
- IOS7过渡之---Layout and Appearance 布局和外观
- 多表链接的问题
- maven study 2
- gearmand及对应php扩展的安装
- 创建Unicode版本的VC工程
- javascript实现模仿迅雷电影评分
- 基于Eclipse的交叉编译环境的建立