Search code examples
cocos2d-android

How can I make a rectangular on the moving sprite in Cocos2d android?


CGRect targetRect = CGRect.make(target.getPosition().x - (target.getContentSize().width),
            target.getPosition().y - (target.getContentSize().height),
            target.getContentSize().width,
            target.getContentSize().height);

target is a sprite ... and I make to create a rectangular on the border of the sprite. I tried to do this work by draw(GL10 gl) but I'm not getting the way to call it . So, If someone have an idea how to do this . Please help me out of this... thanks in advance


Solution

  • 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);
        }
    

    similarly you can draw rectangle by using ccDrawRect() method