【问题标题】:Want sample code for drawing on finger movement in cocos2d 3.9?想要在 cocos2d 3.9 中绘制手指运动的示例代码吗?
【发布时间】:2016-01-27 06:51:33
【问题描述】:

我们如何在 cocos2d 3.9 中实现这一点并解释

virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) 覆盖;

这个方法里面的这个参数是什么?提前谢谢。

【问题讨论】:

    标签: ios c++11 cocos2d-x-3.0


    【解决方案1】:

    您可以在 cocos2d-x 文件夹中默认提供的“cpp test”中找到好的示例。在 cpp 测试中运行名为“RenderTextureTest”的项目。

    如果您想以最简单的方式绘制手指运动,使用cocos2d::RenderTexture,这是一个您可以在其中绘制的节点。

    您的代码如下所示:

    void TestScene::onTouchMoved(Touch * touch, Event* event)
    {
        Vec2 start = touch->getLocation();
        Vec2 end   = touch->getPreviousLocation();
    
        // begin drawing to the render texture
        _renderTexture->begin();
    
        float distance = start.getDistance(end);
        if (distance > 1)
        {
            Sprite * brushSprite = Sprite::create("Images/fire.png");
            brushSprite->setColor(Color3B::RED);
            brushSprite->setOpacity(20);
    
            for (int i = 0; i < distance; i++)
            {
                float difx = end.x - start.x;
                float dify = end.y - start.y;
                float delta = (float)i / distance;
                brushSprite->setPosition(start.x + (difx * delta), start.y + (dify * delta));
                brushSprite->visit(); // Draw sprite to render texture
            }
        }
    
        // finish drawing and return context back to the screen
        _renderTexture->end();
    }
    

    对不起我的英语

    【讨论】:

    • 假设如果必须通过手指运动在某些结构中填充颜色,如何实现。
    • 什么样的结构?不是正方形?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-10
    • 1970-01-01
    • 2010-09-21
    • 2014-08-22
    • 1970-01-01
    相关资源
    最近更新 更多