2014-10-05 28 views
0

有人能告诉我什么在libgdx中调用画图方法吗?在libgdx中画图的解释

@Override 
public void draw (Batch batch, float parentAlpha) { 
//whatever goes here 
} 

我不知道如果我能解释这很好,但我的问题是,实施抽签方法之后,谁不断地调用它?在演员类,例如:

public void draw (Batch batch, float parentAlpha) { 
} 

我猜,但我不知道,有一些代码的地方,负责拜访每一位的渲染什么。

+0

@Alexķ感谢适应英语 – 2014-10-05 13:19:04

+0

Render方法是从渲染在后台运行的线程调用。 – Veljko 2014-10-05 16:41:59

+0

Veljko要求回答 – 2014-10-06 17:05:09

回答

0

短Answer.-

阶段要求所有演员的绘制方法。

长的答案只是completeness.-

阶段要求绘制它的(根)集团的方法。

Stage.java -L118

public void draw() { 
    Camera camera = viewport.getCamera(); 
    camera.update(); 

    if (!root.isVisible()) return; 

    Batch batch = this.batch; 
    if (batch != null) { 
     batch.setProjectionMatrix(camera.combined); 
     batch.begin(); 
     root.draw(batch, 1); 
     batch.end(); 
    } 

    if (debug) drawDebug(); 
} 

和根集团调用其drawChildren方法。

Group.java -L56

public void draw (Batch batch, float parentAlpha) { 
    if (transform) applyTransform(batch, computeTransform()); 
    drawChildren(batch, parentAlpha); 
    if (transform) resetTransform(batch); 
} 

这是谁调用所有的小演员画法的方法。

Group.java -L66

protected void drawChildren (Batch batch, float parentAlpha) { 
    parentAlpha *= this.color.a; 
    SnapshotArray<Actor> children = this.children; 
    Actor[] actors = children.begin(); 
    Rectangle cullingArea = this.cullingArea; 
    if (cullingArea != null) { 
     // Draw children only if inside culling area. 
     float cullLeft = cullingArea.x; 
     float cullRight = cullLeft + cullingArea.width; 
     float cullBottom = cullingArea.y; 
     float cullTop = cullBottom + cullingArea.height; 
     if (transform) { 
      for (int i = 0, n = children.size; i < n; i++) { 
       Actor child = actors[i]; 
       if (!child.isVisible()) continue; 
       float cx = child.x, cy = child.y; 
       if (cx <= cullRight && cy <= cullTop && cx + child.width >= cullLeft && cy + child.height >= cullBottom) 
        child.draw(batch, parentAlpha); 
      } 
     } else { 
      // No transform for this group, offset each child. 
      float offsetX = x, offsetY = y; 
      x = 0; 
      y = 0; 
      for (int i = 0, n = children.size; i < n; i++) { 
       Actor child = actors[i]; 
       if (!child.isVisible()) continue; 
       float cx = child.x, cy = child.y; 
       if (cx <= cullRight && cy <= cullTop && cx + child.width >= cullLeft && cy + child.height >= cullBottom) { 
        child.x = cx + offsetX; 
        child.y = cy + offsetY; 
        child.draw(batch, parentAlpha); 
        child.x = cx; 
        child.y = cy; 
       } 
      } 
      x = offsetX; 
      y = offsetY; 
     } 
    } else { 
     // No culling, draw all children. 
     if (transform) { 
      for (int i = 0, n = children.size; i < n; i++) { 
       Actor child = actors[i]; 
       if (!child.isVisible()) continue; 
       child.draw(batch, parentAlpha); 
      } 
     } else { 
      // No transform for this group, offset each child. 
      float offsetX = x, offsetY = y; 
      x = 0; 
      y = 0; 
      for (int i = 0, n = children.size; i < n; i++) { 
       Actor child = actors[i]; 
       if (!child.isVisible()) continue; 
       float cx = child.x, cy = child.y; 
       child.x = cx + offsetX; 
       child.y = cy + offsetY; 
       child.draw(batch, parentAlpha); 
       child.x = cx; 
       child.y = cy; 
      } 
      x = offsetX; 
      y = offsetY; 
     } 
    } 
    children.end(); 
} 
+0

谢谢你,你的回复非常好,谢谢你的时间,但是我的问题是谁在抽奖和呈现在上面的水平,而且我认为在阅读你的帖子后正在寻找其他网站和我我想我找到了我想象中的答案,在创建,恢复,呈现,暂停或销毁时调用ApplicationListener。所有方法都在当前OpenGL上下文的线程中调用。因此,您可以安全地创建和操作图形资源。 – 2014-10-06 17:05:24