Search code examples
javascripthtmllimejs

LimeJS goog.event.listen not firing on child


I'm having some issues with this event. I've only recently started HTML5 game development and I'm using LimeJS. The following code will not fire the alert when I set it to listen on the field or flayer, it only responds to Game. Is it something I'm doing wrong with my order of doing things or something else that's causing the event to not fire?

Thank you for reading.

//set main namespace
goog.provide('rtstest');


//get requirements
goog.require('lime.Director');
goog.require('lime.Scene');
goog.require('lime.Layer');
goog.require('lime.RoundedRect');

// entrypoint
rtstest.start = function(){
var director = new lime.Director(document.body,1024,768).setDisplayFPS(false),
Game = new lime.Scene(),

menulayer = new lime.Layer().setAnchorPoint([0,0]).setPosition(0,668),
menubg = new     lime.RoundedRect().setSize(1024,200).setPosition(512,668).setFill('assets/menubg.png');


var field = new lime.Sprite().setSize(1024,568).setAnchorPoint([0,0]).setFill('assets/field1.jpg');
var flayer = new lime.Layer().setAnchorPoint([0,0]).setPosition(0,0);

goog.events.listen(flayer,['mousedown'],function(e){

    alert('derp');

});

menulayer.appendChild(menubg);
flayer.appendChild(field);

Game.appendChild(flayer);
Game.appendChild(menulayer);



director.replaceScene(Game);

}

Solution

  • Fixed by someone on the LimeJS board:

    The problem in my code is the setAnchorPoint calls with the array as a parameter. setAnchorPoint allows 2 numbers or a goog.math.Vec2 object. Layers have no anchorpoints(because they have not with and height).

    So it should be: menulayer = new lime.Layer().setPosition(0,668),

    and var field = new lime.Sprite().setSize(1024,568).setAnchorPoint(0,0).setFill('assets/field1.jpg');