2009-02-17 14 views
6
[MenuItemFont setFontSize:20]; 
[MenuItemFont setFontName:@"Helvetica"]; 
//I'm trying to change the color of start (below item) 
MenuItem *start = [MenuItemFont itemFromString:@"Start Game" 
             target:self 
             selector:@selector(startGame:)]; 
MenuItem *help = [MenuItemFont itemFromString:@"Help" 
             target:self 
            selector:@selector(help:)]; 
Menu *startMenu = [Menu menuWithItems:start, help, nil]; 
[startMenu alignItemsVertically]; 
[self add:startMenu]; 

Trả lời

5
MenuItemFont *start = [MenuItemFont itemFromString:@"Start Game" 
              target:self 
              selector:@selector(startGame:)]; 

[start.label setRGB:0 :0 :0]; // Black menu item 

Label là một tài sản của MenuItemFont, một lớp con của MenuItem, vì vậy bạn mất nó trong dàn diễn viên ngầm để MenuItem.

Ngoài ra, bạn có thể làm:

[((MenuItemFont *)start).label setRGB:0 :0 :0] 

(nhưng đó là xấu xí, và startmenu sẽ mất một MenuItemFont không có khiếu nại).

Hãy nhớ rằng các màu sắc được mã hóa nhiều nhất trong MenuItemFont, vì vậy hãy gọi 'setIsEnabled' sẽ đặt màu trở lại thành màu xám hoặc trắng. Điều này xảy ra xung quanh dòng 239 của MenuItem.m nếu bạn cần phải tinh chỉnh nó. Nếu tôi nhận được xung quanh để thực hiện một bản vá để lộ chức năng này trên MenuItemFont (giả sử nó chưa có trong các nguồn trước .7.1), tôi sẽ cập nhật bài viết của mình.

3

Bạn có thể thay đổi nó như thế này (ít nhất là trên Cocos2d phiên bản 0.99.5)

CCMenuItemFont *startMenuItem = [CCMenuItemFont itemFromString:@"Start" target:self selector:@selector(startTapped:)]; 
[startMenuItem setColor:ccBLACK]; 
4

setRGB đã được thiết lập để setcolor trong các phiên bản mới hơn. Ví dụ:

[start.label setColor: ccc3(200,0,200)]; 
Các vấn đề liên quan