/****
* Classes
****/
// The game engine will automatically create and load the assets
// Create a class for the cycle
var Cycle = Container.expand(function () {
var self = Container.call(this);
var cycleGraphics = self.attachAsset('cycle', {
anchorX: 0.5,
anchorY: 0.5
});
self.distanceTravelled = 0;
self.update = function () {
if (self.distanceTravelled < 5000) {
self.distanceTravelled += 5;
} else {
LK.showGameOver();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Add city background to the game
var cityBackground = LK.getAsset('cityBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(cityBackground);
// Initialize the cycle
var cycle = game.addChild(new Cycle());
cycle.x = 2048 / 2;
cycle.y = 2732 / 2;
// Display the distance travelled by the cycle
var distanceTxt = new Text2('0 km', {
size: 150,
fill: "#ffffff"
});
LK.gui.top.addChild(distanceTxt);
// Update the game every tick
game.update = function () {
cycle.update();
distanceTxt.setText(cycle.distanceTravelled + ' km');
}; ===================================================================
--- original.js
+++ change.js
@@ -28,8 +28,16 @@
/****
* Game Code
****/
+// Add city background to the game
+var cityBackground = LK.getAsset('cityBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 2048 / 2,
+ y: 2732 / 2
+});
+game.addChild(cityBackground);
// Initialize the cycle
var cycle = game.addChild(new Cycle());
cycle.x = 2048 / 2;
cycle.y = 2732 / 2;