Add createSprites convenience function

feature/coffeescript
Sven Slootweg 10 years ago
parent 12a0b150b5
commit 177e80336d

@ -16,6 +16,7 @@ Engine = (function() {
this.getObject = __bind(this.getObject, this);
this.getScene = __bind(this.getScene, this);
this.createTileset = __bind(this.createTileset, this);
this.createSprites = __bind(this.createSprites, this);
this.createSprite = __bind(this.createSprite, this);
this.createSound = __bind(this.createSound, this);
this.createObject = __bind(this.createObject, this);
@ -195,10 +196,19 @@ Engine = (function() {
};
Engine.prototype.createSprite = function(name, image) {
console.log("gget", this.resource_manager.getImage(image));
return this.sprites[name] = new Sprite(this, name, this.resource_manager.getImage(image));
};
Engine.prototype.createSprites = function(sprites) {
var image, name, _results;
_results = [];
for (name in sprites) {
image = sprites[name];
_results.push(this.createSprite(name, image));
}
return _results;
};
Engine.prototype.createTileset = function(name, image, tile_width, tile_height) {
return this.tilesets[name] = new Tileset(this, name, this.resource_manager.getImage(image), tile_width, tile_height);
};

@ -39,19 +39,18 @@ $(->
manager.load ->
# Game asset initialization...
engine.createSprite("cursor", "images/cursor.png")
engine.createSprite("diamond", "images/diamond.png")
engine.createSprite("diamond_inverted", "images/diamond_inverted.png")
engine.createSprite("diamond_shimmer", "images/diamond_shimmer.png")
engine.createSprite("yellow", "images/yellow.png")
engine.createSprite("yellow_inverted", "images/yellow_inverted.png")
engine.createSprite("yellow_shimmer", "images/yellow_shimmer.png")
engine.createSprite("blue", "images/blue.png")
engine.createSprite("blue_inverted", "images/blue_inverted.png")
engine.createSprite("blue_shimmer", "images/blue_shimmer.png")
engine.createSprites({
"cursor": "images/cursor.png",
"diamond": "images/diamond.png",
"diamond_inverted": "images/diamond_inverted.png",
"diamond_shimmer": "images/diamond_shimmer.png",
"yellow": "images/yellow.png",
"yellow_inverted": "images/yellow_inverted.png",
"yellow_shimmer": "images/yellow_shimmer.png",
"blue": "images/blue.png",
"blue_inverted": "images/blue_inverted.png",
"blue_shimmer": "images/blue_shimmer.png",
})
# Object definitions
loader = engine.createObject("loader")

@ -24,16 +24,18 @@
engine.setInitialScene(engine.createScene("main"));
return manager.load(function() {
var cursor, diamond, loader;
engine.createSprite("cursor", "images/cursor.png");
engine.createSprite("diamond", "images/diamond.png");
engine.createSprite("diamond_inverted", "images/diamond_inverted.png");
engine.createSprite("diamond_shimmer", "images/diamond_shimmer.png");
engine.createSprite("yellow", "images/yellow.png");
engine.createSprite("yellow_inverted", "images/yellow_inverted.png");
engine.createSprite("yellow_shimmer", "images/yellow_shimmer.png");
engine.createSprite("blue", "images/blue.png");
engine.createSprite("blue_inverted", "images/blue_inverted.png");
engine.createSprite("blue_shimmer", "images/blue_shimmer.png");
engine.createSprites({
"cursor": "images/cursor.png",
"diamond": "images/diamond.png",
"diamond_inverted": "images/diamond_inverted.png",
"diamond_shimmer": "images/diamond_shimmer.png",
"yellow": "images/yellow.png",
"yellow_inverted": "images/yellow_inverted.png",
"yellow_shimmer": "images/yellow_shimmer.png",
"blue": "images/blue.png",
"blue_inverted": "images/blue_inverted.png",
"blue_shimmer": "images/blue_shimmer.png"
});
loader = engine.createObject("loader");
loader.onStep = function() {
return true;

@ -115,9 +115,12 @@ class Engine
@sounds[name] = new Sound(this, name, @resource_manager.getSound(sound))
createSprite: (name, image) =>
console.log("gget", @resource_manager.getImage(image))
@sprites[name] = new Sprite(this, name, @resource_manager.getImage(image))
createSprites: (sprites) =>
for name, image of sprites
@createSprite(name, image)
createTileset: (name, image, tile_width, tile_height) =>
@tilesets[name] = new Tileset(this, name, @resource_manager.getImage(image), tile_width, tile_height)

Loading…
Cancel
Save