Game Development Reference
In-Depth Information
its width and height. For this reason, the sprite component also keeps track of the
entity's physical size as well as the image that represents the entity visually.
var Packt = Packt || {};
Packt.Components = Packt.Components || {};
Packt.Components.Sprite = function(pEntity,
pImgSrc, pWidth, pHeight) {
var entity = pEntity;
var img = new Image();
img.src = pImgSrc;
var width = pWidth;
var height = pHeight;
var sWidth = pWidth;
var sHeight = pHeight;
var sX = 0;
var sY = 0;
var ctx = null;
// Inject the canvas context where the
rendering of the entity
// managed by this component is done
function setCtx(context) {
ctx = context;
}
// Public access to the private function
setCtx
this.setCtx = setCtx;
// If the image used to render the entity
managed by thiscomponent
// is part of an atlas, we can specify the
specific region
// within the atlas that we want rendered
this.setSpriteCoords = function(x, y, width,
height) {
sX = x;
Search WWH ::




Custom Search