Android的opengles动画文本的逻辑? [英] Android opengles animated text logic?

查看:147
本文介绍了Android的opengles动画文本的逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了文本在Android上使用OpenGL ES的渲染,目前正在试图找出如何动画它像口袋妖怪游戏中它以一定的速度从左向右,揭示的大字。
如何做到这一点?

I have gotten text to render using opengl es on android and currently am trying to find out how to "animate" it like in pokemon games where it "reveals" the characters from left to right at a certain speed. How is this done?

推荐答案

基本上,这个文滑动式,是像所有其他的动画。

Basically, this "text-sliding-in" is like all other animations.

例如,看看这个样本code:

For example, look at this sample code:

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

请注意,一个游戏对象类描述他们更多的领域,但举例而言,这应该是足够了。

Notice that a game object class has more fields describing them, but for example purposes this should be enough.

/**
 * 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();         
    }
}

好了,会发生什么?总结:

Well, what happens? To summarize:

第一帧:D&LT; - 增加的 mCurrentFrame 的一个

First frame: D <- Increase mCurrentFrame by one.

二帧:D&LT; - 增加的 mCurrentFrame 的一个

Second frame: D <- Increase mCurrentFrame by one.

...

第二十六届帧:德&LT; - MINDEX 的已通过增加一个(它循环
  多行文字变量两次)。

Twenty-sixth frame: De <- mIndex has increased to one (it loop through the mText variable two times).

...

所有文本已经显示:其中; - 重设的 MINDEX 的零,重置的 mCurrentFrame
  到零。这将从头开始播放动画。

All text has been displayed: <- Reset the mIndex to zero, reset mCurrentFrame to zero. This will play the animation from the beginning.

这是基本的想法。您可以添加在这里你改变每个字符的数量,更改文本,慢/加速动画帧的每个字符后更多的方法等。

This is the basic idea. You can add more methods where you change the frames per character amount, change text, slow/speed up the animation after each character, etc.

我也写了一个这样的例子,但对于画布系统。它应该很容易让你适应你选择的。

I also wrote an example of this, but for the Canvas system. It should be easy for you to adapt to whatever you choose.

您可以找到我的例子这里

这篇关于Android的opengles动画文本的逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆