1 decade ago by Gary
I've been trying to create 'building' entities to dynamically spawn across the canvas at various different heights.
Thus far I seem to be doing ok with the entity size itself, but I'm struggling with the animation sheet.
Initially I was planning to tile an image to a specific height by drawing it directly, but I found a post somewhere that suggested creating an image just taller than the maximum height of my entity and adjusting the size of the animation sheet... This sounded much easier!
What I need to do, is override the height of the animationSheet, but I seem unable to do this.
My entity looks like this:
As you can see, I'm attempting to set the height of the animSheet on init. If I send the animSheet to the console, I can see the correct height listed - but the height of the image used doesn't change.
I have some defaults for buildingHeight and the size of the entity, but these are being overwritten but my spawnEntity call. This seems to work fine for the size of the entity, but not for the animationSheet.
Can anyone see what I'm doing wrong?
Is there perhaps, a more sensible way to do this?
Thanks
Thus far I seem to be doing ok with the entity size itself, but I'm struggling with the animation sheet.
Initially I was planning to tile an image to a specific height by drawing it directly, but I found a post somewhere that suggested creating an image just taller than the maximum height of my entity and adjusting the size of the animation sheet... This sounded much easier!
What I need to do, is override the height of the animationSheet, but I seem unable to do this.
My entity looks like this:
// Building EntityBuilding = ig.Entity.extend({ size: {x:32, y:272} , type: 1 , buildingHeight: 50 , buildingBlockHeight: 8 , animSheet: new ig.AnimationSheet('media/buildings.png', 32) // Collision , type: ig.Entity.TYPE.A , checkAgainst: ig.Entity.TYPE.BOTH , collides: ig.Entity.COLLIDES.FIXED , init: function(x, y, settings) { this.parent(x, y, settings); this.addAnim('idle', 1, [0]); // Multiply the block size by the specified building height this.buildingHeight = this.buildingHeight * this.buildingBlockHeight; this.size.y = this.buildingHeight; this.animSheet.height = this.buildingHeight }
As you can see, I'm attempting to set the height of the animSheet on init. If I send the animSheet to the console, I can see the correct height listed - but the height of the image used doesn't change.
I have some defaults for buildingHeight and the size of the entity, but these are being overwritten but my spawnEntity call. This seems to work fine for the size of the entity, but not for the animationSheet.
// Loop for a row of buildings for (i=0; i < this.maxBuildings; i++) { // Set building settings var buildingSettings = { type: Math.floor(Math.random() * 6) + 1 , buildingHeight: randomFromInterval(6, this.maxBuildingHeight) } // Spawn building this.spawnEntity(EntityBuilding, buildingPosition + 4, 0, buildingSettings); // Update building position buildingPosition = buildingPosition + 32; }
Can anyone see what I'm doing wrong?
Is there perhaps, a more sensible way to do this?
Thanks