zoukankan      html  css  js  c++  java
  • 【v2.x OGE课程 14】 控制使用


    在这里,精灵、动画精灵、button天才、经常使用的文本的使用

    一个、相关精灵

    1.加入精灵

    //创建精灵

    Sprite bar_up = new Sprite(400, 0, RegionRes.getRegion(Res.BAR_UP),    getVertexBufferObjectManager());

    //将精灵加入至BaseEntityGroup或其子类(如:SceneLayer等)

    BaseEntityGroup.attachChild(bar_up);

    2.精灵翻转

    //两者默认是false

    bar_up.setFlippedHorizontal(pFlippedHorizontal);//水平翻转

    bar_up.setFlippedVertical(pFlippedVertical)//垂直翻转

    3.精灵分离

    方法一:

    object.detachChild(bar_up);//object必须是attachChild时所引用的对象

    方法二:

    bar_up.detachSelf();//引用其Parent对象将其detach

    二、动画精灵相关

    1.加入动画精灵

    //创建动画精灵 所需帧图必须在同一纹理上

    AnimatedSprite bird = new AnimatedSprite(0, 0, Res.BRID_YELLOW, 

    getVertexBufferObjectManager());

    //将精灵加入至BaseEntityGroup或其子类(如:SceneLayer等)

    BaseEntityGroup.attachChild(bird);

    2.播放动画

    AnimatedSprite类中有各种animate方法对帧图进行播放,下面是animate方法中各參数意思:

    pFrameDurationEach:每帧播放时间(毫秒)

    IAnimationListener :监听当播放前后,切换帧,循环结束后。

    pLoop:是否循环

    pLoopCount:循环次数

    pFrameDurations:自己定义每帧播放时间

    pFirstTileIndex:从哪一帧開始播放 

    pLastTileIndex:从哪一帧结束播放 (FirstTileIndex必须小于LastTileIndex)

    pFrames[]:自己定义播放的帧

    IAnimationData:设置动画參数的接口

    3.播放动画监听

    AnimatedSprite类中用IAnimationListener接口来监听动画

    //AnimatedSprite.LOOP_CONTINUOUS是无限循环

    public void onAnimationStarted(final AnimatedSprite pAnimatedSprite, final int pInitialLoopCount);

    //动画的帧改变时会调用

    public void onAnimationFrameChanged(final AnimatedSprite pAnimatedSprite, final int pOldFrameIndex, final int pNewFrameIndex);

    //循环一次结束时调用

    public void onAnimationLoopFinished(final AnimatedSprite pAnimatedSprite, final int pRemainingLoopCount, final int pInitialLoopCount);

    //动画播放完时调用

    public void onAnimationFinished(final AnimatedSprite pAnimatedSprite);

     

    4.分离动画精灵

    方法一:

    object.detachChild(bar_up);//object必须是attachChild时所引用的对象

    方法二:

    bar_up.detachSelf();//引用其Parent对象将其detach

    三、button精灵

    button精灵使用TiledRegion使得button在ButtonSprite.State不同状态中切换帧图。加强表达效果,重写onAreaTouched方法给予用户良好体验,注冊OnClickListener监听点击事件发生

    1.加入button

    //创建button精灵 所需帧图必须在同一纹理上

    ButtonSprite btnOK = new ButtonSprite(0, 0, Res.GAME_READY, 

    getVertexBufferObjectManager());

    this.attachChild(btnOK);

    2.button监听

    btnOK.setOnClickListener(new OnClickListener() {

    @Override

    public void onClick(ButtonSprite pButtonSprite, float pTouchAreaLocalX, 

    float pTouchAreaLocalY) {

    //TODO 

    }

    });

    3.button状态

    NORMAL(0),//普通

    PRESSED(1),//按下

    DISABLED(2);//不可用

    DISABLED状态需设置setEnable(pEnabled)才可改变

    4.分离button

    方法一:

    object.detachChild(btnOK);//object必须是attachChild时所引用的对象

    方法二:

    btnOK.detachSelf();//引用其Parent对象将其detach

    四、文本相关

    1.加入文本

    //确保BitmapFont已载入。而且已包括所需文字

    //pCharactersMaximum 所同意最大文本长度。若超出则后面部分不显示

    Text bitmapText = new Text(0, 0, bitmapFont, "Hello World!",200

    new TextOptions(HorizontalAlign.CENTER),

    this.getVertexBufferObjectManager());

    //将精灵加入至BaseEntityGroup或其子类(如:SceneLayer等)

    this.attachChild(bitmapText);

    2.更新文本

    //更新文本后矩形会依据文字内容增大或缩小,所以须要配合setPosition将坐标又一次更改

    bitmapText.setText("Just a Demo");

    3.分离文本

    方法一:

    object.detachChild(bitmapText);//object必须是attachChild时所引用的对象

    方法二:

    bitmapText.detachSelf();//引用其Parent对象将其detach

    4.软键盘监听

    /**hint 文本为空时出现的信息

    * text 默认文本

    输入类型ISoftInput.INPUT_TYPE_XXX

    最大输入字节数

    文本监听

    Device.getDevice().getSoftInput().showSoftInput(hint, text, inputType, maxTextLength, onSoftInputListener);

    五、线、矩形相关

    1.创建线、矩形

    //创建须要两个点

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

    //将精灵加入至BaseEntityGroup或其子类(如:SceneLayer等)

    BaseEntityGroup.attachChild(line);

    //创建须要设定宽高

    Rectangle rect = new Rectangle(0, 0, 100, 100, getVertexBufferObjectManager());

    //将精灵加入至BaseEntityGroup或其子类(如:SceneLayer等)

    BaseEntityGroup.attachChild(rect);

    2.分离线、矩形

    方法一:

    object.detachChild(line);//object必须是attachChild时所引用的对象

    object.detachChild(rect);//object必须是attachChild时所引用的对象

    方法二:

    line.detachSelf();//引用其Parent对象将其detach

    rect.detachSelf();//引用其Parent对象将其detach

    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    17. Letter Combinations of a Phone Number
    16. 3Sum Closest
    15. 3Sum
    14. Longest Common Prefix
    13. Roman to Integer
    12. Integer to Roman
    11. Container With Most Water
    10. Regular Expression Matching
    9. Palindrome Number
    8. String to Integer (atoi)
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4615734.html
Copyright © 2011-2022 走看看