【问题标题】:How can I make a rectangular on the moving sprite in Cocos2d android?如何在 Cocos2d android 中的移动精灵上制作一个矩形?
【发布时间】:2013-02-25 07:13:38
【问题描述】:
CGRect targetRect = CGRect.make(target.getPosition().x - (target.getContentSize().width),
            target.getPosition().y - (target.getContentSize().height),
            target.getContentSize().width,
            target.getContentSize().height);

target 是一个精灵......我在精灵的边框上创建了一个矩形。 我试图通过 draw(GL10 gl) 来完成这项工作,但我没有办法调用它。 所以,如果有人知道如何做到这一点。请帮我解决这个问题...提前谢谢

【问题讨论】:

  • cocos2d-iphone 中有一个宏可以绘制边界框。还有 ccDrawLine - rectangle = 4 行。

标签: cocos2d-android


【解决方案1】:
public void draw(GL10 gl){
        gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
        gl.glLineWidth(4);
        CCDrawingPrimitives.ccDrawCircle(gl, centerAnchor, 20*scaleX, ccMacros.CC_DEGREES_TO_RADIANS(90), 50, true);

            CCDrawingPrimitives.ccDrawCircle(gl, CGPoint.make((handposition.x-40f)*scaleX,(handposition.y+10f)*scaleY), 45*scaleX, ccMacros.CC_DEGREES_TO_RADIANS(90), 50, true);

            CCDrawingPrimitives.ccDrawPoint(gl, centerAnchor);

        gl.glLineWidth(1);
        gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
        gl.glPointSize(1);
    }

同样你可以使用 ccDrawRect() 方法绘制矩形

【讨论】:

  • 我试试告诉你?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多