Thứ Năm, 12 tháng 12, 2013

Android

MyScene.registerTouchArea(animatedSprite);//Phải đăng ký là cho phép AnimatedSprite này được lắng nghe sự kiện 


BitmapTextureAllas dung de bo nho chua anh
 - Font
    private BitmapTextureAtlas bitmapTextureAtlas;//Lưu ảnh trong bộ nhớ
    
private TextureRegion textureRegion;//Lưu khi load ảnh
    
private Sprite sprite;//Sprite quả bóng 

BitmapTextureAtlas + Font +Text  dung cho Text

BitmapTextureAtlas + Font +ChangeableText  dung cho Text
thay doi Text
//Cập nhật (coi như vòn lặp hoạt cảnh)
        
MyScene.registerUpdateHandler(new IUpdateHandler() {
         
            @
Override
            
public void reset() {
                
// TODO Auto-generated method stub
             
            
}
         
            
//Muốn cập nhật cái gì thì cho vào đây
            
@Override
            
public void onUpdate(float pSecondsElapsed) {
                try {
                    
//Tạm dừng cập nhật trong 1s
                    
Thread.sleep(1000);
                } catch (
InterruptedException e) {
                    
// TODO Auto-generated catch block
                    
e.printStackTrace();
                }             
                
//Cập nhật lại những gì bạn cần vẽ lại liên tục
                
dem++;
                
textchange.setText(String.valueOf(dem));//Cứ sau 1s ta lại hiện thị đếm
            
}
        }); 


BitmapTextureAtlas + TextureRegion +Sprite
BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.bitmapTextureAtlasthis"sprite.png"0021);
         
this.mEngine.getTextureManager().loadTexture(this.bitmapTextureAtlas); 

this.mEngine.registerUpdateHandler(new FPSLogger());  //=====================================LẮNG NGHE SỰ KIỆN CHẠM VÀO MÀN HÌNH MyScene======================================================================
        //Bắt sự kiện khi chạm vào MyScene
        
MyScene.setTouchAreaBindingEnabled(true);//cho phép lắng nghe
        
MyScene.setOnSceneTouchListener(new IOnSceneTouchListener() {              
                public 
boolean onSceneTouchEvent(final Scene pScene, final TouchEvent pSceneTouchEvent) {
                    
System.out.println("Sprite onSceneTouchEvent: chạm vào màn hình");
                    
System.out.println("Tọa độ X = "+pSceneTouchEvent.getX());
                    
System.out.println("Tọa độ Y = "+pSceneTouchEvent.getY()); 
                  
                    
//Khi chạm vào màn hình ta di chuyển AnimatedSprite theo tọ độ y.
                    
animatedSprite.setPosition(animatedSprite.getX(), pSceneTouchEvent.getY());
                    return 
true;
                }
        }); 

//Check su kien va cham vao sprite
this.mSpirte = new Sprite(100, 100, textRegion){
//lang nghe su kien cham vao sprite
@Override
public boolean onAreaTouched(TouchEvent pSceneTouchEvent,
float pTouchAreaLocalX, float pTouchAreaLocalY) {
// TODO Auto-generated method stub
if(pSceneTouchEvent.getAction()==TouchEvent.ACTION_DOWN){
System.out.println("Sprite onTouched: Cham vao spirte");
System.out.println("Toa do sprite x: "+pTouchAreaLocalX);
System.out.println("Toa do sprite y: "+pTouchAreaLocalY);
}
return true;
}

};

BitmapTextureAtlas + TitledTextureRegion + AnimatedSprite 

2 nhận xét:

  1. Cái này phục vụ cho cái gì thế B? :P

    P/s: Ăn cắp bản quyền blog nha. :)
    Trả tiền, trả tiền :P

    Trả lờiXóa