【问题标题】:cocos2dx 3.3 animation implementationcocos2dx 3.3 动画实现
【发布时间】:2015-05-13 13:30:04
【问题描述】:

我是 cocos2dx 开发的新手。我使用 cpp 语言在 android 中几乎学习了 cocos2dx(3.3 版)的所有基本级别。我表明 cocos2dx.org 上有很多更新。

在android中我目前正在使用cocos2dx 3.3版开发俄罗斯方块游戏,我想知道实现令人敬畏的动画的最佳方法是什么分数增量。我想知道使用 c++ 在 android 中实现动画 cocos2dx。我们还需要制作支持多屏支持的游戏,我搜索了很多所有这些点在谷歌上找不到太多信息。

我为初学者很好地展示了声纳系统支持,我们非常感谢,我已经观看了声纳系统在 YouTube 上分享的所有视频。我在那里学到很多。我想知道cocos2dx中android的高级动画。

我们寻求任何帮助将不胜感激。

谢谢

【问题讨论】:

  • 你做过多屏支持吗?
  • 无法做到,但我们得到了另一家游戏开发公司的帮助,开发人员建议使用缩放因子。他们实际上使用 cocos2dx 开发 iPhone 游戏,然后移植到 android。他们说给其他平台提供支持的简单方法。
  • 我已经完成了……它很长……如果你愿意,我可以分享我的课程……
  • 请确保您能分享任何帮助,不胜感激
  • 其实我们喜欢cocos2dx提供不同的bucket文件夹(比如mdpi,hpdi,xhdpi,xxhdpi)来获取正确的资源。它工作正常,但规模不是自动完成的。

标签: c++ cocos2d-x cocos2d-x-3.0 cocos2d-android cocos2d-js


【解决方案1】:

这是我的 appmacros.h filr ..

#ifndef __APPMACROS_H__
#define __APPMACROS_H__

#include "cocos2d.h"



#define DESIGN_RESOLUTION_480X320    0
#define DESIGN_RESOLUTION_480X800    1
#define DESIGN_RESOLUTION_1024X768   2
#define DESIGN_RESOLUTION_1280X800   3
#define DESIGN_RESOLUTION_2048X1536  4

/* If you want to switch design resolution, change next line */
#define TARGET_DESIGN_RESOLUTION_SIZE  DESIGN_RESOLUTION_1280X800

typedef struct tagResource
{
    cocos2d::CCSize size;
    char directory[100];
}Resource;

static Resource smallResource  =  { CCSizeMake(480, 320),   "iphone" };
static Resource mysmallResource  =  { CCSizeMake(800, 480),   "iphone" };
static Resource mediumResource =  { CCSizeMake(1024, 768),  "ipad"   };
static Resource myResource =  { CCSizeMake(1280, 800),  "ipad" };
static Resource largeResource  =  { CCSizeMake(2048, 1536), "ipadhd" };

#if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320)
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(480, 320);
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X800)
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(800, 480);
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_1024X768)
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(1024, 768);
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_2048X1536)
static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(2048, 1536);
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_1280X800)
static CCSize designResolutionSize = cocos2d::CCSizeMake(1280, 800);
#else
#error unknown target design resolution!
#endif

// The font size 24 is designed for small resolution, so we should change it to fit for current design resolution
#define TITLE_FONT_SIZE  (cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width / myResource.size.width * 24)

#endif /* __APPMACROS_H__ */

现在我们可以在 appdelegate 中使用这个类.. 所以我的 appdelegate 看起来像......

#include "AppDelegate.h"
#include "MenuLayer.h"
#include "AppMacros.h"
#include "SimpleAudioEngine.h"
#include "cocos2d.h"


USING_NS_CC;


AppDelegate::AppDelegate() {

}

AppDelegate::~AppDelegate() {

}
void AppDelegate::initGLContextAttrs()
{
    //set OpenGL context attributions,now can only set six attributions:
    //red,green,blue,alpha,depth,stencil
    GLContextAttrs glContextAttrs = {8, 8, 8, 8, 24, 8};

    GLView::setGLContextAttrs(glContextAttrs);
}

bool AppDelegate::applicationDidFinishLaunching() {

    // initialize director
    auto director = Director::getInstance();
    auto glview = director->getOpenGLView();
    if(!glview) {
        glview = GLViewImpl::create("My Game");
        director->setOpenGLView(glview);
    }

    CCLOG("%s","applicationDidFinishLaunching ");
    // initialize director
//  CCDirector* pDirector = CCDirector::sharedDirector();
//  CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    director->setOpenGLView(glview);

    // Set the design resolution
    glview->setDesignResolutionSize(designResolutionSize.width,
            designResolutionSize.height, kResolutionFixedWidth);

    //CCSize frameSize = pEGLView->getFrameSize();
    CCSize frameSize = director->getVisibleSize();

    // if the frame's height is larger than the height of medium resource size, select large resource.
    if (frameSize.width > myResource.size.width) {

        director->setContentScaleFactor(
                largeResource.size.width / designResolutionSize.width);

    }
    // if the frame's height is larger than the height of small resource size, select medium resource.
    else if (frameSize.width > mediumResource.size.width) {

        director->setContentScaleFactor(
                myResource.size.width / designResolutionSize.width);

    } else if (frameSize.width > mysmallResource.size.width) {

        director->setContentScaleFactor(
                designResolutionSize.width / mediumResource.size.width);

    } else if (frameSize.width > smallResource.size.width) {

        director->setContentScaleFactor(
                designResolutionSize.width / mediumResource.size.width);

    }
    // if the frame's height is smaller than the height of medium resource size, select small resource.
    else {

        director->setContentScaleFactor(
                designResolutionSize.width / smallResource.size.width);

    }

    // turn on display FPS
    director->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0 / 60);


    CCScene *pScene = MenuLayer::scene();


    director->runWithScene(pScene);



    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
    CCDirector::sharedDirector()->stopAnimation();

    // if you use SimpleAudioEngine, it must be pause
    CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();


}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
    CCDirector::sharedDirector()->startAnimation();

    // if you use SimpleAudioEngine, it must resume here
    CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();


}

【讨论】:

  • 感谢您分享代码 它会试试这个,让我知道 "iphone" "iphone" 这是 iPhone 的资源目录我可以为 android 声明 "hdpi" "mdpi"
  • 它工作正常,你能告诉我我需要把所有资源图像放在哪里。
  • 目前我们将图片放在不同的bucket文件夹中。
  • 将所有与游戏相关的图片放在assets文件夹中,并将图标放在res目录下的不同drawables文件夹中..
  • 嗨,你能告诉我“TARGET_DESIGN_RESOLUTION_SIZE”实际上我现在定义了高分辨率,当我在我的设备上运行时它是 hdpi 设备,它看起来很好,可见尺寸更改为目标设计尺寸
【解决方案2】:

我也是 cocos2dx 3.3 的新手。好吧,我通过使用(.plist)粒子效果来使用爆炸(爆炸)动画 首先你需要一个 .plist 动画文件。有一个用于制作 .plist 文件的在线编辑器。你可以看看 这是链接。 http://www.effecthub.com/particle2dx

现在你可以使用这行代码

CCParticleSystemQuad *system = CCParticleSystemQuad::create("explodeEffect.plist");

system->setTexture(CCTextureCache::sharedTextureCache()->addImage("yourplayer.png"));
system->setDuration(0.05);
system->setScale(3.0f);
 system->setPosition(yourplayer->getPosition().x, yourplayer->getPosition().y);
this->addChild(system,1);
system->setAutoRemoveOnFinish(true);

这对你有帮助

【讨论】:

    猜你喜欢
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多