小编Lea*_*s2D的帖子

在cocos2dx的Resources/Assets文件夹中列出文件/目录

我想列出来自android和ios的Resources文件夹中的文件夹和文件.我已经能够通过'dirent.h'中的'opendir'和'readdir'来实现,但只能在ios模拟器中实现.它在android中不起作用.有人面对这样的问题吗?谢谢.

android file-handling ios cocos2d-x

2
推荐指数
1
解决办法
1292
查看次数

如果没有init方法,如何正确地子类化SKNode?

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方法?

objective-c ios sprite-kit sknode

2
推荐指数
1
解决办法
1920
查看次数

在SpriteKit中设置精灵的角度

如何将精灵的角度设置为45度?

SKAction *rotate = [SKAction rotateByAngle: M_PI/4.0 duration:1];
Run Code Online (Sandbox Code Playgroud)

只是将角度增加了45度,我想要做的就是SKSprite旋转,但需要长时间才能达到45度然后停止.有没有方法或我必须硬编码?

谢谢!

ios sprite-kit

2
推荐指数
1
解决办法
602
查看次数

cocos2d-x EventDispatcher不再是单例吗?

我使用cocos2d-x 3.0 RC1,我有以下问题.据我所知,cocos2d-x有一个(集中式)事件调度程序,它实现为单例,以便我可以将事件从任何地方发送到任何地方.现在在最终版本中,它不是单身,我不能使用EventDispatcher::getInstance().为什么集中的EventDispatcher被认为是错误的?在这种情况下,我如何从一个不是a的类发送一个事件cocos2d::Node到另一个不是cocos2d::Node哪一个?

c++ event-dispatching cocos2d-x

2
推荐指数
1
解决办法
1170
查看次数

Cocos2d-x v3无法覆盖前向功能Draw

//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有什么新方法吗?

提前致谢.

cocos2d-x cocos2d-x-3.0

2
推荐指数
1
解决办法
4080
查看次数

使用自定义碎片着色器(Cocos2d-x)进行奇怪的y位置偏移

我正试图掩盖一个精灵,所以我写了一个简单的片段着色器,它只渲染未隐藏在另一个纹理(掩码)下的像素.问题是,在通过着色器后,我的纹理似乎有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)

c++ opengl-es cocos2d-x cocos2d-x-3.0

2
推荐指数
1
解决办法
1477
查看次数

在C++中添加代码执行的延迟

假设我需要在延迟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中为代码执行添加延迟的跨平台方式是什么?

c++ delay cocos2d-x cocos2d-x-3.0

2
推荐指数
1
解决办法
9100
查看次数

在导入cocos2d项目之后,eclipse引发了两个奇怪的错误:"Android Library Update","C/C++ Indexer"

将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)

提前致谢.

eclipse android cocos2d-x

2
推荐指数
1
解决办法
3193
查看次数

从eclipse运行项目时出错

我已经下载了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)

有没有人面临同样的问题或知道如何解决这个问题?

android cocos2d-x

2
推荐指数
1
解决办法
1495
查看次数

iOS 8自动旋转将图像从屏幕上旋转出来

所以我最近听到了客户关于一个奇怪问题的消息.当他们试图旋转屏幕时,屏幕会变黑.这似乎是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)

cocos2d-iphone ios8

2
推荐指数
1
解决办法
1389
查看次数