2014-03-06 7 views
1

텍스트의 색상 및 크기를 변경하고 싶습니다. 나는 그 글꼴을 하나만 사용하고 싶다. 가능한가? 여기 텍스트 변경 크기 및 색상

내 코드입니다 : 정의 글꼴 & 텍스트

// for red color font 
redFont = FontFactory.createFromAsset(activity.getFontManager(), 
       fontTexture, activity.getAssets(), "YIKES__.TTF", 30, true, 
       Color.parseColor("#EF522A")); 
     redFont.prepareLetters("Score:1234567890 Sec Cash/Level" 
       .toCharArray()); 
     redFont.load(); 

// for white color font 
    ITexture whiteFontTexture = new BitmapTextureAtlas(
       activity.getTextureManager(), 256, 256, TextureOptions.BILINEAR); 

     whiteFont = FontFactory.createFromAsset(activity.getFontManager(), 
       whiteFontTexture, activity.getAssets(), "YIKES__.TTF", 30, true, 
       Color.WHITE); 
     whiteFont.prepareLetters("Score:1234567890 Sec Cash/Level" 
       .toCharArray()); 
     whiteFont.load(); 

다음 텍스트와 같은 크기 변경 초기화 :

gameOverText = new Text(0, 0, 
      ResourcesManager.getInstance().whiteFont, 
      "ABCDEFHIJKLMNOPQRSTUVWXYZ", 
      ResourcesManager.getInstance().vbom); 
    gameOverText.setPosition(45, 72); 
// gameOverText.setSize(490, 115); 
    gameOverText.setText(gameOver); 

과 같은 색상을 변경 :

// define the color 
pColor = new org.andengine.util.color.Color(255, 102, 51); 
gameOverText.setColor(pColor); 

하지만, 나는 성공하지 못한다. 그래서 아래에 가까운.

enter image description here

+0

이 방법으로 문제가 있었지만 해결책을 기억하지 못했습니다. 그것은 알파 채널과 관련이 있습니다 - 내 코드를보고 흰색이 아닌 다른 색상을 얻으려면이 Color.argb (int 알파, int 빨강, int 녹색, int 파랑)를 사용하여 알파 채널을 설정해야했습니다. 대신 parseColor 호출 – jmroyalty

답변

-2

사용 setTextColor() 또는 setTextSize()TextView에 당신도 잘해야합니다.

+0

감사 마크. 나는 AndEngine에있다! !! 안드로이드에 없습니다. TextView를 지원합니다. @ Mark –

1

이것은 오래된 게시물이며 이미 답변을 찾았 으면하지만 여전히 시도하지 못하는 사람들을 위해이 방법을 사용해보십시오. 글꼴 크기를 변경하는 것은 다소 간단합니다. andengine의 setScale 메소드를 사용하여 크기를 조절할 수 있습니다.

gameOverText.setScale(0.1f); //Scales both X and Y 
gameOverText.setScaleX(0.5f); //Scales X only 
gameOverText.setScaleY(1.0f); //Scales Y only 

필요에 따라 사용할 수있는 다른 크기 조정 방법이 있습니다. 또한 스케일 팩터 범위는 0 (최소)에서 1 (최대)까지입니다.

마지막으로, 하루 종일 알아 내야하는 색으로. Andengine 글꼴은 색상을 설정하기위한 setColor 메소드를 가지고 있지만 색상 객체를 android.graphics.Color.rgb (255,223,0) 클래스에서 설정 한 경우에만 작동합니다. 다른 색상을 사용하면 색상을 마스크하고 기대했던 것보다 이상한 결과가 나타납니다.

gameOverText.setColor(android.graphics.Color.rgb(255,0,0)); //For Red 

앞으로 도움이되기를 바랍니다.