Here, the use of sprites, animated sprites, button geniuses, and frequently used text
A, related wizard
1.Join the wizard
Creating Sprites
Sprite bar_up = new Sprite (0, Regionres.getregion (Res.bar_up), Getvertexbufferobjectmanager ()) ;
add sprites to baseentitygroup or their subclasses (e.g.Scene,Layer , etc.)
Baseentitygroup.attachchild (BAR_UP);
2.Sprite Flip
both default is false
Bar_up.setflippedhorizontal (pflippedhorizontal);// Flip horizontally
Bar_up.setflippedvertical (pflippedvertical)// Vertical Flip
3. Wizard Separation
Method One:
Object.detachchild (BAR_UP);//object must be the object referenced at attachchild
Method Two:
Bar_up.detachself ();// reference its Parent object to detach it
Second, Animation Wizard related 1.Add Animation Wizard
The frame graph required to create the animation sprite must be on the same texture
Animatedsprite bird = new animatedsprite (0, 0, Res.brid_yellow,
Getvertexbufferobjectmanager ());
add sprites to baseentitygroup or their subclasses (e.g.Scene,Layer , etc.)
Baseentitygroup.attachchild (bird);
2.Play Animations
There are various animate methods in the Animatedsprite class to play the frame graph, the following are the meanings of each of the parameters in the Animate method:
Pframedurationeach: Playback time per frame (ms)
Ianimationlistener : Listen when the playback, switch frame, after the end of the cycle.
Ploop: whether to loop
Ploopcount: Number of cycles
Pframedurations: Define your own playback time per frame
Pfirsttileindex: from which frame to start playing
Plasttileindex: from which frame to end playback (firsttileindex must be less than Lasttileindex)
Pframes[]: Define the frames you play
Ianimationdata: An interface to set animation parameters
3. Play an animated listener
The Animatedsprite class uses the Ianimationlistener interface to listen for animations
Animatedsprite.loop_continuous is an infinite loop
public void onanimationstarted (final animatedsprite panimatedsprite, final int pinitialloopcount);
called when the frame of the animation changes
public void onanimationframechanged (final animatedsprite panimatedsprite, final int poldframeindex, final int Pnewframeindex);
called when the loop ends at one time
public void onanimationloopfinished (final animatedsprite panimatedsprite, final int premainingloopcount, final int Pinitialloopcount);
called when the animation finishes playing
public void onanimationfinished (final animatedsprite panimatedsprite);
4.Detach Animation Sprite
Method One:
Object.detachchild (BAR_UP);//object must be the object referenced at attachchild
Method Two:
Bar_up.detachself ();// reference its Parent object to detach it
Third, Button Wizard
The button sprite uses tiledregion to make the button buttonsprite. Toggles the frame graph in different state states. Enhance the expression effect, rewrite the Onareatouched method to give the user a good experience, register Onclicklistener Monitor Click event occurred
1. Add button
The frame graph required to create the button sprite must be on the same texture
Buttonsprite Btnok = new Buttonsprite (0, 0, Res.game_ready,
Getvertexbufferobjectmanager ());
This.attachchild (Btnok);
2.button Monitoring
Btnok.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (Buttonsprite pbuttonsprite, float ptoucharealocalx,
Float ptoucharealocaly) {
Todo
}
});
3.button status
Normal (0),// normal
PRESSED (1),// Press
DISABLED (2);// Not available
DISABLED state needs to be set setenable (penabled) to change
4. Detach button
Method One:
Object.detachchild (Btnok);//object must be the object referenced at attachchild
Method Two:
Btnok.detachself ();// reference its Parent object to detach it
Iv. text related 1. Adding text
Make sure the bitmapfont is loaded. And it already includes the text you want .
Pcharactersmaximum the maximum text length agreed to. If it is exceeded, the following section does not display
Text Bitmaptext = new text (0, 0, Bitmapfont, "Hello world!", 200
New Textoptions (Horizontalalign.center),
This.getvertexbufferobjectmanager ());
add sprites to baseentitygroup or their subclasses (e.g.Scene,Layer , etc.)
This.attachchild (Bitmaptext);
2. Updating text
After you update the text, the rectangle grows or shrinks depending on the text, so you need to mate with setposition to change the coordinates again
Bitmaptext.settext ("Just a Demo");
3. Separating text
Method One:
Object.detachchild (Bitmaptext);//object must be the object referenced at attachchild
Method Two:
Bitmaptext.detachself ();// reference its Parent object to detach it
4. Soft keyboard monitoring
/**hint The message appears when the text is empty
* Text default
* input type isoftinput.input_type_xxx
* Maximum number of input bytes
* Text monitoring
Device.getdevice (). Getsoftinput (). Showsoftinput (hint, text, InputType, Maxtextlength, Onsoftinputlistener);
Five, the line, the rectangle correlation 1.create lines, rectangles
two points required to create a
Line line = new Line (0, 0, 0, 0, Pvertexbufferobjectmanager);
add sprites to baseentitygroup or their subclasses (e.g.Scene,Layer , etc.)
Baseentitygroup.attachchild (line);
create the need to set the width height
Rectangle rect = new Rectangle (0, 0, +, Getvertexbufferobjectmanager ());
add sprites to baseentitygroup or their subclasses (e.g.Scene,Layer , etc.)
Baseentitygroup.attachchild (rect);
2. Separating lines, rectangles
Method One:
Object.detachchild (line);//object must be the object referenced by attachchild
Object.detachchild (rect);//object must be the object referenced at attachchild
Method Two:
Line.detachself ();// reference its Parent object to detach it
Rect.detachself ();// reference its Parent object to detach it
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
"V2.x OGE Course 14" Control use