Android opengles animated text logic? -
i have gotten text render using opengl es on android , trying find out how "animate" in pokemon games "reveals" characters left right @ speed. how done?
basically, "text-sliding-in" other animations.
for example, @ sample code:
public class gameobject { // each element in char array contains // single character, representing serie of text. private char[] mtext; // frames before new character appears. private int mframes; // current frame. private int mcurrentframe; // current index (which character last). private int mindex; public gameobject(string defaulttext, int framespercharacter) { final int textlength = defaulttext.length(); mtext = new char[textlength]; (int x = 0; x < textlength; x++) { mtext[x] = defaulttext.charat(x); } mframes = framespercharacter; } public void drawtext() { // not have room enough explain drawing apis, // you'll idea. (int x = 0; x < mindex; x++) { // draw text, beginning current index. // depending on drawing api, might have // change x , y coordinates each character. apidrawtext.drawtext(mtext[x]); } // reset counter if character's "animation" // done , add 1 index. // otherwise, add 1 current frame. if (mcurrentframe >= mframes) { mcurrentframe = 0; mindex++; } else { mcurrentframe++; } if (mindex >= mtext.length) { // reset index counter (will display text on again). mindex = 0; } } }
notice game object class has more fields describing them, example purposes should enough.
/** * basic opengl es implementation on android. * should contain onsurfacecreated() , onsurfacechanged(). */ public class glrenderer extends glsurfaceview implements renderer { private gameobject mgameobject; public glrenderer() { // add default text , add 25 frames per character. mgameobject = new gameobject("default text!", 25); } /** * ordinary draw function on android. code should * similiar this. */ @override public void ondrawframe(gl10 gl) { // use method got render text opengl // here. mgameobject.drawtext(); } }
well, happens? summarize:
first frame: d <- increase mcurrentframe one.
second frame: d <- increase mcurrentframe one.
...
twenty-sixth frame: de <- mindex has increased 1 (it loop through mtext variable 2 times).
...
all text has been displayed: <- reset mindex zero, reset mcurrentframe zero. play animation beginning.
this basic idea. can add more methods change frames per character amount, change text, slow/speed animation after each character, etc.
i wrote example of this, canvas
system. should easy adapt whatever choose.
you can find example here.
Comments
Post a Comment