[V2.x OGE tutorial 14] control usage

Source: Internet
Author: User

 

The following describes how to use genie, animated genie, button genie, and text.

 

1. genie-related

 

1. Add a genie

// Create an genie

Sprite bar_up = new sprite (400, 0, regionres. getregion (res. bar_up), getvertexbufferobjectmanager ());

// Add the genie to baseentitygroup or its sub-classes (such as scene and layer)

Baseentitygroup. attachchild (bar_up );

2. Genie flip

// The default value is false.

Bar_up.setflippedhorizontal (pflippedhorizontal); // flip horizontally

Bar_up.setflippedvertical (pflippedvertical) // vertical flip

3. Genie Separation

Method 1:

Object. detachchild (bar_up); // The object must be referenced by attachchild.

Method 2:

Bar_up.detachself (); // reference its parent object to detach it

 

2. animation genie 1. Add an animation genie

// Frames required to create an animation genie must be on the same texture

Animatedsprite bird = new animatedsprite (0, 0, res. brid_yellow,

Getvertexbufferobjectmanager ());

// Add the genie to baseentitygroup or its sub-classes (such as scene and layer)

Baseentitygroup. attachchild (BIRD );

2. Play an animation

In the animatedsprite class, there are various animate methods for playing Frame Graphs. The following are the meanings of parameters in the animate method:

 

Pframedurationeach: playback time per frame (MS)

Ianimationlistener: Listen to the listener. After the playback, the frame is switched and the loop ends.

Ploop: whether to cycle

Ploopcount: number of cycles

Pframedurations: Specifies the playback time of each frame.

Pfirsttileindex: from which frame to play

Plasttileindex: from which frame the playback ends (firsttileindex must be smaller than lasttileindex)

Pframes []: Custom playback frame

Ianimationdata: interface for setting Animation Parameters

3. Play an animation listener

The ianimationlistener interface is used in the animatedsprite class to listen to animations.

 

// Animatedsprite. loop_continuous is an infinite loop

Public void onanimationstarted (final animatedsprite panimatedsprite, final int pinitialloopcount );

 

// Called when the animation frame changes

Public void onanimationframechanged (final animatedsprite panimatedsprite, final int poldframeindex, final int pnewframeindex );

 

// Call at the end of a loop

Public void onanimationloopfinished (final animatedsprite panimatedsprite, final int premainingloopcount, final int pinitialloopcount );

 

// Called when the animation is played

Public void onanimationfinished (final animatedsprite panimatedsprite );

 

4. Separated animation genie

Method 1:

Object. detachchild (bar_up); // The object must be referenced by attachchild.

Method 2:

Bar_up.detachself (); // reference its parent object to detach it

 

3. Button genie

The button genie uses tiledregion to enable the button to change the frame chart in different states of buttonsprite. State to enhance the expression effect. The onareatouched method is rewritten to provide a good user experience. Registering onclicklistener to listen for click events

1. Add button

// The frame image 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 listening

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); // unavailable

 

The disabled status can be changed only when setenable (penabled) is set.

4. Split button

Method 1:

Object. detachchild (btnok); // The object must be referenced by attachchild.

Method 2:

Btnok. detachself (); // reference its parent object to detach it

 

 

Iv. Text-related 1. Add text

// Ensure that bitmapfont is loaded and contains the required text

// The maximum text length allowed by pcharactersmaximum. If it exceeds the limit, the subsequent part is not displayed.

Text bitmaptext = new text (0, 0, bitmapfont, "Hello world! ", 200

New textoptions (horizontalalign. Center ),

This. getvertexbufferobjectmanager ());

// Add the genie to baseentitygroup or its sub-classes (such as scene and layer)

This. attachchild (bitmaptext );

 

2. Update text

// After the text is updated, the rectangle will increase or decrease according to the text content. Therefore, you need to use setposition to change the coordinates again.

Bitmaptext. settext ("just a demo ");

3. Separate text

Method 1:

Object. detachchild (bitmaptext); // The object must be referenced by attachchild.

Method 2:

Bitmaptext. detachself (); // reference its parent object to detach it

4. Soft Keyboard monitoring

 

 

/** Information displayed when the hint text is null

* Text default text

* Input type isoftinput. input_type_xxx

* Maximum number of input bytes

* Text listening

Device. getdevice (). getsoftinput (). showsoftinput (hint, text, inputtype, maxtextlength, onsoftinputlistener );

 

V. Line and rectangle 1. Create line and rectangle

// Two points are required for creation.

Line line = new line (0, 0, 0, 0, pvertexbufferobjectmanager );

// Add the genie to baseentitygroup or its sub-classes (such as scene and layer)

Baseentitygroup. attachchild (line );

 

// Set the width and height for Creation

Rectangle rect = new rectangle (0, 0,100,100, getvertexbufferobjectmanager ());

// Add the genie to baseentitygroup or its sub-classes (such as scene and layer)

Baseentitygroup. attachchild (rect );

2. separation line and rectangle

Method 1:

Object. detachchild (line); // The object must be referenced by attachchild.

Object. detachchild (rect); // The object must be referenced by attachchild.

Method 2:

Line. detachself (); // reference its parent object to detach it

Rect. detachself (); // reference its parent object to detach it

 

 

 

[V2.x OGE tutorial 14] control usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.