1 decade ago by SirPereira
Hello,
Currently I've setup a game where I do have an ig.Image that is being drawn in ig.game.draw method.
Apart of that, I'm trying to do some canvas drawing in an entity.
My ig.game.draw looks like the following:
And my draw method in entity:
The result I'm looking for is:
- Background image
- Entities over background (in this case, a canvas drawn on top of background)
- Text over entities and background
AFAIK when calling this.parent() on ig.game.draw it clears whatever was already drawn, however, I do need to use it to draw my entities.
What should I be using here to get this working?
Thanks!
Currently I've setup a game where I do have an ig.Image that is being drawn in ig.game.draw method.
Apart of that, I'm trying to do some canvas drawing in an entity.
My ig.game.draw looks like the following:
draw: function() {
// Background
this.titleImage.draw(0,0);
// Draw all entities
this.parent();
// Last drawn stuff (like texts on top of screen)
this.fonts.text.draw( ig.storage.name, 286, 240, ig.Font.ALIGN.LEFT );
}
And my draw method in entity:
draw: function () {
var ctx = ig.system.context;
var s = ig.system.scale;
var x = this.settings.x * s - ig.game.screen.x * s;
var y = this.settings.y * s - ig.game.screen.y * s;
var sizeX = this.settings.sizeX * s;
var sizeY = this.settings.sizeY * s;
ctx.save();
ctx.beginPath();
ctx.fillStyle = this.settings.color;
ctx.fillRect( x, y, sizeX, sizeY );
ctx.closePath();
this.parent();
ctx.restore();
this.parent();
}
The result I'm looking for is:
- Background image
- Entities over background (in this case, a canvas drawn on top of background)
- Text over entities and background
AFAIK when calling this.parent() on ig.game.draw it clears whatever was already drawn, however, I do need to use it to draw my entities.
What should I be using here to get this working?
Thanks!
