我想列出来自android和ios的Resources文件夹中的文件夹和文件.我已经能够通过'dirent.h'中的'opendir'和'readdir'来实现,但只能在ios模拟器中实现.它在android中不起作用.有人面对这样的问题吗?谢谢.
SKNode只提供+node方法.
如果你这样做:
+ (instancetype)node {
CustomNode *body = [CustomNode node]; // infinite loop
}
Run Code Online (Sandbox Code Playgroud)
如果你这样做:
+ (instancetype)node {
CustomNode *body = [super node]; // instance of SKNode, not CustomNode
}
Run Code Online (Sandbox Code Playgroud)
你如何继承一个只有一个方便构造函数的类,你可以覆盖构造函数?或者最好的做法是创建自己的+customNode方法?
如何将精灵的角度设置为45度?
SKAction *rotate = [SKAction rotateByAngle: M_PI/4.0 duration:1];
Run Code Online (Sandbox Code Playgroud)
只是将角度增加了45度,我想要做的就是SKSprite旋转,但需要长时间才能达到45度然后停止.有没有方法或我必须硬编码?
谢谢!
我使用cocos2d-x 3.0 RC1,我有以下问题.据我所知,cocos2d-x有一个(集中式)事件调度程序,它实现为单例,以便我可以将事件从任何地方发送到任何地方.现在在最终版本中,它不是单身,我不能使用EventDispatcher::getInstance().为什么集中的EventDispatcher被认为是错误的?在这种情况下,我如何从一个不是a的类发送一个事件cocos2d::Node到另一个不是cocos2d::Node哪一个?
//in my .h file
virtual void draw();
//in .cpp
void GameLayer:draw()
{
Layer::draw();
//draw code goes here
}
Run Code Online (Sandbox Code Playgroud)
它显示无法覆盖前向函数node :: draw()
据我所知,它正在研究旧版本.cocos2d-x 3.0有什么新方法吗?
提前致谢.
我正试图掩盖一个精灵,所以我写了一个简单的片段着色器,它只渲染未隐藏在另一个纹理(掩码)下的像素.问题是,在通过着色器后,我的纹理似乎有y坐标偏移.
这是我要屏蔽的精灵(GroundZone)的init方法:
bool GroundZone::initWithSize(Size size) {
// [...]
// Setup the mask of the sprite
m_mask = RenderTexture::create(textureWidth, textureHeight);
m_mask->retain();
m_mask->setKeepMatrix(true);
Texture2D *maskTexture = m_mask->getSprite()->getTexture();
maskTexture->setAliasTexParameters(); // Disable linear interpolation on the mask
// Load the custom frag shader with a default vert shader as the sprite’s program
FileUtils *fileUtils = FileUtils::getInstance();
string vertexSource = ccPositionTextureA8Color_vert;
string fragmentSource = fileUtils->getStringFromFile(
fileUtils->fullPathForFilename("CustomShader_AlphaMask_frag.fsh"));
GLProgram *shader = new GLProgram;
shader->initWithByteArrays(vertexSource.c_str(), fragmentSource.c_str());
shader->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION);
shader->bindAttribLocation(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORDS);
shader->link();
CHECK_GL_ERROR_DEBUG();
shader->updateUniforms();
CHECK_GL_ERROR_DEBUG();
int maskTexUniformLoc = shader->getUniformLocationForName("u_alphaMaskTexture"); …Run Code Online (Sandbox Code Playgroud) 假设我需要在延迟2秒的情况下调用一个函数.在cocos2d-x中,您可以使用以下操作:
auto action = Sequence::create(
DelayTime::create(2),
CallFunc::create(
[&]() {
// here is the lambda function that does whatever you want after 2 seconds
}
),
NULL
);
runAction(action);
Run Code Online (Sandbox Code Playgroud)
但是为了运行你需要的动作Node,这并不总是可用的.有些课程与课程无关Node.所以我想知道在C++ 11中为代码执行添加延迟的跨平台方式是什么?
将cocos2d项目导入eclipse后,会引发两个奇怪的错误:
"Android库更新","C/C++索引器"
错误:
An internal error occured during :"C/C++" . java.lang.NullPointerException.
An internal error occured during :"Android Library Update" . java.lang.NullPointerException.
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我已经下载了cocos2d x v3.3 beta并使用此命令在Windows中创建了一个项目
cocos.py new Tutorialv3cocos -p com.ghostdreamstudo.learning -l cpp -d D:\Development\Learning
Run Code Online (Sandbox Code Playgroud)
然后我将项目导入eclipse并试图运行但是eclipse给了我跟随错误
[2014-10-03 18:40:39 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/cocos2dx/lib/Cocos2dxAccelerometer;
[2014-10-03 18:40:39 - Tutorialv3cocos] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/cocos2dx/lib/Cocos2dxAccelerometer;
Run Code Online (Sandbox Code Playgroud)
有没有人面临同样的问题或知道如何解决这个问题?
所以我最近听到了客户关于一个奇怪问题的消息.当他们试图旋转屏幕时,屏幕会变黑.这似乎是iOS 8的东西,因为我的最新版本只是添加iOS 8.
从我的viewcontroller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//
// There are 2 ways to support auto-rotation:
// - The OpenGL / cocos2d way
// - Faster, but doesn't rotate the UIKit objects
// - The ViewController way
// - A bit slower, but the UiKit objects are placed in the right place
//
#if GAME_AUTOROTATION==kGameAutorotationNone
//
// EAGLView won't be autorotated.
// Since this method should return YES in at least 1 orientation,
// we return YES only in the …Run Code Online (Sandbox Code Playgroud)