Closed filipux closed 6 years ago
I tried reducing the treasureHunter demo to it's bare minimum and I can't get anything to work now. It turns out my player object is undefined all but the first time the game loop runs in this example:
<html>
<head></head>
<body>
<script src="hexi-master/bin/hexi.js"></script>
<script>
var g = hexi(512, 512, setup);
g.start();
var player = undefined,
gameScene = undefined;
function setup() {
gameScene = g.group();
player = g.rectangle(32, 32, "red");
gameScene.addChild(player);
g.state = play;
}
function play() {
console.log(player);
}
</script>
</body>
</html>
What am I missing here?
Does declaring player
and gameScene
before g
make a difference?
Yes it does!
Declaring player and gameScene before g solved it; now player is a Sprite object instead of undefined. Time to make a game :)
Great, glad it works! This is a bug in the initialization process that I don't quite understand yet, but we've found that just declaring the global game variables earlier in the code seems to be an OK workaround for now.
I just downloaded hexi and played around with the demos. The first thing I tried was to remove the sound effect from the 01_treasureHunter demo but that somehow created an exception. Can't for my life figure out why.
I made the following changes:
Then I got an error in the console:
Latest hexi-master osx Chrome Version 63.0.3239.132 (Official Build) (64-bit)