【问题标题】:how to move, zoom in or out the layer like coc in cocos2d-x?如何在 cocos2d-x 中像 coc 一样移动、放大或缩小图层?
【发布时间】:2013-07-05 02:56:50
【问题描述】:

我创建了一个包含所有游戏内容的关卡层,例如背景,敌人,子弹,玩家和其他贴花,我想让这个层可以移动,放大和缩小,最有可能冲突部落,有什么建议或理想,谢谢。

【问题讨论】:

    标签: move cocos2d-x layer zooming


    【解决方案1】:

    假设您的图层名称是 exampleLayer

    图层移动

    在你的层中ccTouchMoved函数实现以下代码

     void ccTouchMoved(CCTouch* touch, CCEvent* event)
        {
            CCPoint diff = touch->getDelta();
            CCPoint currentPos = exampleLayer->getPosition();
            exampleLayer->setPosition(ccpAdd(currentPos, diff));
        }
    

    放大和缩小

    void zoomIn()
    {
        exampleLayer->setPosition(-(CCDirector::sharedDirector()->getWinSize().width/2),-(CCDirector::sharedDirector()->getWinSize().height/2)); // for positioning the laer in middle
        exampleLayer->setScale(1); // you can set your scale factor 1 is for example
    }
    
    void zoomOut()
    {
        exampleLayer->setPosition(0,0);
        exampleLayer->setScale(1); // set your desired scale factor
    }
    

    您可以在 zoomIn 和 zoomOut 按钮上调用这些方法,或者根据您的游戏设计。 希望对你有帮助。

    【讨论】:

    • 感谢您的帖子,我现在可以移动图层了,但接下来就是绑定图层,防止背景移动到视口之外。
    • 谢谢,我认为真正的问题是带有相机的滚动层。 :-)
    猜你喜欢
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    • 1970-01-01
    • 2015-04-28
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多