Trouble creating multiple buttons

22 views
Skip to first unread message

Rob M

unread,
Aug 7, 2014, 8:13:43 PM8/7/14
to aw...@googlegroups.com
Hi, I'm trying to create multiple buttons to act as levels to click on.  The code is as follows:

override private function _init():Void 
{
super._init();
// extend here
_title.text = "LEVEL SELECTOR";
for (level in 1...6) {
createLevelButton(level, 50 + 60 * level, 100);
}
}
private function createLevelButton(level:Int, x:Float, y:Float):Void {
var _button = new BasicButton( _kernel, _assetManager.overlayLevelUp, _assetManager.overlayLevelOver, 
50, 50, x, y, null, onPlayClick);
addEntity(_button, true, 20 * level );
}
private function onPlayClick():Void {
_kernel.scenes.setScene(EScene.GAME);
}

This should create six buttons and I should be able to click on one of them.  What happens is only the last one is visible until I move my mouse over where the another one should be.  Then that one appears and the previous one disappears.  Can someone tell me what I'm doing wrong?

Thanks,

Rob

Rob Fell

unread,
Aug 7, 2014, 8:20:18 PM8/7/14
to aw...@googlegroups.com
Yes, the BitmapData in _assetManager.overlayLevelOver can only be in one place at a time - in this case the last addition.

Solution is to have overlayLevelOver use a getter that returns a unique view (with a unique instance of the BitmapData) each time.

private function get_overlayLevelOver():IView
{
return a new View containing a new instance of the BitmapData ...

Rob M

unread,
Aug 8, 2014, 6:57:42 PM8/8/14
to aw...@googlegroups.com
Yep, that did the trick.  Thanks a lot Rob!
Reply all
Reply to author
Forward
0 new messages