2011-07-01 12 views
0

私はアンドロイドでopenglを使ってレンダリングするテキストを手に入れましたが、現在、ポケモンゲームのように、文字をあるスピードで左から右に「明らかにする」ように「アニメート」する方法を見つけようとしています。 これはどのように行われますか?Androidオープンテキストのアニメーションテキストロジックですか?

+0

ビデオ、スクリーンショット、モックアップなど – genpfault

+0

私はあなたが何を意味するのかよく分かりません – semajhan

+0

あなたが話していることのビデオ、スクリーンショット、またはモックアップを投稿してください。 – genpfault

答えて

1

基本的に、この「テキストスライドイン」は他のすべてのアニメーションと同様です。例えば

は、このサンプルコードを見て:ゲームオブジェクトのクラスがそれらを記述した複数のフィールドを持っていますが、例の目的のために、これが十分でなければならないこと

public class GameObject { 
    // Each element in this char array contains 
    // a single character, representing a serie of text. 
    private char[] mText; 
    // Frames before a new character appears. 
    private int mFrames;   
    // Current frame. 
    private int mCurrentFrame; 
    // Current index (which character is currently the last). 
    private int mIndex; 

    public GameObject(String defaultText, int framesPerCharacter) { 
     final int textLength = defaultText.length(); 
     mText = new char[textLength]; 

     for (int x = 0; x < textLength; x++) { 
      mText[x] = defaultText.charAt(x); 
     } 

     mFrames = framesPerCharacter; 
    } 

    public void drawText() { 
     // I do not have room enough to explain drawing APIs, but 
     // you'll get the idea. 
     for (int x = 0; x < mIndex; x++) { 
      // Draw text, from the beginning to the current index. 
      // Depending on the drawing API, you might have to 
      // change the x and y coordinates for each character. 
      APIDrawText.drawText(mText[x]); 
     } 

     // Reset the counter if the character's "animation" 
     // is done and add one to the index. 
     // Otherwise, add one to the current frame. 
     if (mCurrentFrame >= mFrames) { mCurrentFrame = 0; mIndex++; } 
     else { mCurrentFrame++; } 

     if (mIndex >= mText.length) { 
      // Reset the index counter (will display the text all over again). 
      mIndex = 0; 
     } 
    } 
} 

お知らせ。

/** 
* Basic OpenGL ES implementation on Android. 
* Should contain onSurfaceCreated() and onSurfaceChanged(). 
*/ 
public class GLRenderer extends GLSurfaceView implements Renderer { 
    private GameObject mGameObject; 

    public GLRenderer() { 
     // Add default text and add 25 frames per character. 
     mGameObject = new GameObject("Default text!", 25); 
    } 

    /** 
    * The ordinary draw function on Android. Your code should 
    * look something similiar to this. 
    */ 
    @Override 
    public void onDrawFrame(GL10 gl) { 
     // Use the method which you got to render text with OpenGL 
     // here. 
     mGameObject.drawText();   
    } 
} 

要約する:

最初のフレーム:D <を - 一つによってmCurrentFrameを増やします。

第二枠:D < - 一つによってmCurrentFrameを増やします。

...

第26のフレーム:デ<からmIndexは( MTEX​​T可変二度を通してループ)を一度に増加しています。

...

すべてのテキストはを表示していた:< - ゼロにmCurrentFrame をリセットし、ゼロにmIndexをリセットします。これにより、最初からアニメーションが再生されます。

これは基本的な考えです。文字数ごとにフレームを変更したり、テキストを変更したり、各文字の後にアニメーションを遅く/スピードアップする方法を追加することができます。Canvasシステムの例も書いてあります。あなたが選んだものに適応することは容易でなければなりません。

私の例はhereです。

+0

私は見る!私はそのように考えなかった、ありがとう! – semajhan

関連する問題