Extending context ignors source rects(in update function)?

4 views
Skip to first unread message

Terence Tan

unread,
May 27, 2011, 10:07:43 PM5/27/11
to The Render Engine
I was prototyping extending a Canvas context but it seems the
sourceRect are being ignored. I looked through to code and it seems
that unless I supply a 'GameObject', with width/height are ignored?

Code follows:
var Palette = function() {
return R.rendercontexts.CanvasContext.extend({
palettes: null,
paletteid:0,
targetRect:null,
constructor: function() {
this.base("Palette", 128, 128);
$(this.getSurface()).css("display", "none");
this.targetRect = R.math.Rectangle2D.create(0,0,32,32);
},
update: function(renderContext, time) {
if (this.palettes == null)
return;

renderContext.pushTransform();
this.base(renderContext, time);

var palette = this.palettes[0];
var attr = palette.info.tiles[0];
var tile = palette.getTile(attr.displayFrame);


renderContext.drawImage(this.targetRect,
palette.image,tile.sourceRect); <- The source rect is 0,0,32,32 and
the target rect is 0,0,32,32.

//this.get2DContext().putImageData(this.imgData, 0, 0);


renderContext.popTransform();
},

Brett Fattori

unread,
May 31, 2011, 11:14:03 AM5/31/11
to the-rend...@googlegroups.com
It shouldn't be ignored.  The "GameObject" is only there for HTML contexts which shouldn't be redrawn each frame, but should instead update the associated object each frame.

- Brett


--
You received this message because you are subscribed to "The Render Engine" group.
To post to this group, send email to the-rend...@googlegroups.com
To unsubscribe from this group, send email to
the-render-eng...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/the-render-engine?hl=en

Reply all
Reply to author
Forward
0 new messages