当前位置: 首页 > 工具软件 > WiEngine > 使用案例 >

WiEngine游戏引擎学习笔记(一)

艾弘义
2023-12-01

1. MenuItemLabel 可以算是WiEngine封装的使用起来比较简单的Menu组件。

第一种,只需要给菜单添加文字,就可以生成菜单。"Start"是菜单的文字,"onStart"是菜单的响应方法,MenuItemLabel里是用映射来响应的,按照例子,它会自动去寻找方法名是onStart的方法,并调用之。

MenuItemLabel item = MenuItemLabel.make("Start", this, "onStart");
MenuItemLabel item1 = MenuItemLabel.make("End", this, "onEnd");
Menu menu = Menu.make(item, item1);
menu.alignItemsVertically();
addChild(menu);

2. AtlasLabel 相当与制作得分的一个组件。

CharMap map = CharMap.make();
map.autoRelease();
map.mapChar(WYRect.make(0, 0, ResolutionIndependent.resolveDp(20), ResolutionIndependent.resolveDp(25)), '0');
map.mapChar(WYRect.make(ResolutionIndependent.resolveDp(20), 0, ResolutionIndependent.resolveDp(10), ResolutionIndependent.resolveDp(25)), '1');
map.mapChar(WYRect.make(ResolutionIndependent.resolveDp(30), 0, ResolutionIndependent.resolveDp(21), ResolutionIndependent.resolveDp(25)), '2');
map.mapChar(WYRect.make(ResolutionIndependent.resolveDp(51), 0, ResolutionIndependent.resolveDp(21), ResolutionIndependent.resolveDp(25)), '3');
map.mapChar(WYRect.make(ResolutionIndependent.resolveDp(72), 0, ResolutionIndependent.resolveDp(21), ResolutionIndependent.resolveDp(25)), '4');
map.mapChar(WYRect.make(ResolutionIndependent.resolveDp(93), 0, ResolutionIndependent.resolveDp(21), ResolutionIndependent.resolveDp(25)), '5');
map.mapChar(WYRect.make(ResolutionIndependent.resolveDp(114), 0, ResolutionIndependent.resolveDp(21), ResolutionIndependent.resolveDp(25)), '6');
map.mapChar(WYRect.make(ResolutionIndependent.resolveDp(135), 0, ResolutionIndependent.resolveDp(21), ResolutionIndependent.resolveDp(25)), '7');
map.mapChar(WYRect.make(ResolutionIndependent.resolveDp(156), 0, ResolutionIndependent.resolveDp(21), ResolutionIndependent.resolveDp(25)), '8');
map.mapChar(WYRect.make(ResolutionIndependent.resolveDp(177), 0, ResolutionIndependent.resolveDp(21), ResolutionIndependent.resolveDp(25)), '9');
Texture2D tex = Texture2D.makePNG(R.drawable.number);
AtlasLabel label = AtlasLabel.make("13579", tex, map);
label.setPosition(ResolutionIndependent.resolveDp(20 * 5 / 2), ResolutionIndependent.resolveDp(tex.getHeight() / 2));
addChild(label);


 类似资料: