Saturday, September 7, 2013

Bài 2.1 : Entity Modifier - Removing Entity - TouchEvent

1. Entity Modifier :- Bạn có thể sử đổi trạng thái của Entity như : dịch chuyển, xoay, phóng to, thu nhỏ, đôi màu v.v. Mọi class hổ trợ việc này nằm trong gói org.andengine.entity.modifier  bạn có thể vào tìm hiểu. Bài viết này mình chỉ hướng dẫn đăng ký Modifier.
- Để đăng ký một Modifier cho entity bạn làm như sau :
     - Tạo một Modifier và đắng ký cho Entity:

  1. MoveXModifier x = new MoveXModifier(200f,fromX,toX);
  2. x.setAutoUnregisterWhenFinished(true);//tự động hủy đăng ký khi kết thúc
  3. entity.registerEntityModifier(x);
     - Để một Modifier lặp đi lặp lại nhiều lần, sử dụng bạn sửa dòng 3 lại như sau :
  1. entity.registerEntityModifier(new LoopEntityModifier(x));
    - Ngoài ra, bạn có thể thêm các sự kiện khi bắt đâu, hoặc kết thúc Modifier bằng cách tạo một IEntityModifier.IEntityModifierListener lúc này bạn sẽ phải override 2 phương thức onModifierStarted và onModifierFinished. Và truyền vào tham số cuối cùng của modifier.

2.Removing Entity
Để xóa một Entity ra khỏi scene bạn làm như sau :

  1. activity.runOnUpdateThread(new Runnable() {
  2. @Override
  3. public void run() {
  4. entity.clearEntityModifiers();
  5. entity.clearUpdateHandlers();
  6. mScene.unregisterTouchArea(entity);//nếu đã được đăng ký Touch Event
  7. entity.detachSelf();
  8. entity.dispose();
  9. }
  10. }
3. TouchEvent
Đăng ký Touch Event cho Entity:
   - Để đăng ký một sự kiện khi người chơi chạm vào  Entity. Lúc khởi tạo Entity bạn override lại phương thức onAreaTouched. Ví dụ khí touch vào sprite thì xóa sprite đó :

  1. Sprite image = new Sprite(0, 0, mPlayerTextureRegion,
  2. mEngine.getVertexBufferObjectManager()){
  3.    @Override
  4.    public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
  5. float pTouchAreaLocalX, float pTouchAreaLocalY) {
  6.            if (pSceneTouchEvent.isActionDown()) {
  7.               activity.runOnUpdateThread(new Runnable() {
  8. @Override
  9. public void run() {
  10. image.clearEntityModifiers();
  11. image.clearUpdateHandlers();
  12. scene.unregisterTouchArea(image);
  13. image.detachSelf();
  14. image.dispose();
  15.                  image.reset();
  16. }
  17.            }
  18. };
  19. scene.registerTouchArea(image);

19 comments:

  1. anh ơi viết tiếp sceen đi a

    ReplyDelete
  2. I really want to read more your posts.I'm trying to learn more knowledge and your articles are so useful for me.I believe that many people like me wait for your next posts.
    facebook live chat help facebook chat boxautoketing.com

    ReplyDelete
  3. apps autoketing
    shipping bar shopify
    App Shipping Bar Master
    Hmm is anyone else experiencing problems with the images on this
    blog loading? I’m tryhing to determine if its a problem on my end or if it’s the blog.

    ReplyDelete
  4. : Im no master, however I trust you simply made an amazing point. You surely completely comprehend what youre talking about, and I can genuinely get behind that.
    Discount master, Create Discount master, autoketing

    ReplyDelete
  5. It's great to be able to read the author's shared lines, wish you always success, and have more great postings.
    currency converter box free, currency converter app download, best autoketing app

    ReplyDelete
  6. Thanks for your amazing content. I appreciate your useful information. Whatsapp group links funny
    friv10games club girl, kizi-2018 games free online, juegos gogy xyz

    ReplyDelete
  7. Howdy! Do you use Twitter? I’d like to follow you if that would be okay. I’m definitely enjoying your blog and look forward to new posts.
    Fortnite Building Simulator GamePlay
    Shell Shockers Game
    Sling-drift Game

    ReplyDelete
  8. This is a great inspiring article. I don't know what to say except that I have enjoyed reading.Some genuinely interesting info , well written and loosely user pleasant.
    jogos abcya3 motox3m3 play now gogy games free online

    ReplyDelete
  9. I am incapable of reading articles online very often, but I’m happy I did today. It is very well written, and your points are well-expressed. I request you warmly, please, don’t ever stop writing.
    madalin stunt cars 2 club 2 player , juegos the world cup soccer 2018 club , geometry jump club free online ,

    ReplyDelete
  10. Wonderful article! This is the kind of info that should be shared across the web. Disgrace on the seek engines for no longer positioning this post upper! Come on over and seek advice from my web site . Thanks
    Ice cream maker game online
    4 player sheep party best online game
    Colorzzle online

    ReplyDelete
  11. I’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article
    mr dubstep free , game moto x3m 4 winter , santa claus jump unblocked games ,

    ReplyDelete
  12. I have read all your articles. I'm full of the joys of spring when see your new posts. When I was facing problems, I read your articles.thanks for the post.
    Papa's Scooperia free game Def Island Kick The Buddy game for kids

    ReplyDelete
  13. I really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot!
    bob the robber 4 japan online games , fireboy and watergirl 4 online free , mario banzai online ,

    ReplyDelete
  14. It should be easy for users to find what they need, to go to and from pages, and to basically provide a user-friendly experience
    miniclip games for girls, a10 for free, Jogo 2019

    ReplyDelete
  15. jogo io online
    free online friv Games
    play 2 player games
    Hello There. I found your blog using msn. This is an extremely well written article. I will be sure to bookmark it and return to read more of your useful information.
    I wanted to thank you for this excellent read!! I definitely loved every little bit of it.

    ReplyDelete


  16. play food games
    basketball games
    soccer free games
    sure to bookmark it and return to read more of your useful information.
    I wanted to thank you for this excellent read!! I definitely loved every little bit of it.

    ReplyDelete
  17. These articles are exactly what I need. I have a liking for your posts. Thanks to your sharing, I can enrich my knowledge. Of course, I wish that you will write and share many posts. Do you know that I wait for them?
    free games
    jogos 4 school
    jogos gratis 360

    ReplyDelete

  18. Barbie Beauty Bath
    Golf Park
    Football Heads: 2013-14 Serie A
    A debt of gratitude is in order for giving late reports with respect to the worry, I anticipate read more.

    ReplyDelete