Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am also working on a card game using <code>Backbone.js</code> on Canvas and came across this question. What I am currently doing is have a <code>CardView</code> that has <code>el</code> as a canvas tag so that a canvas will be created on initialization. All the drawing of the card is done on this view's <code>render</code> method. However, this canvas will not be added to the <code>DOM</code>.</p> <p>I then have a <code>Hand</code>, which is a <code>Backbone.Collection</code> to hold a collection of cards. This collection has a <code>Backbone.View</code> attached to the game canvas (the only and big one in the <code>DOM</code>). This view also holds an array of <code>Backbone.View</code>'s. Then I have:</p> <pre><code>render: function() { var that = this; this.ctx.save(); _(this._views).each(function(view) { that.ctx.drawImage(view.render().el, 0, 0); that.ctx.translate(view.el.width, 0); }); this.ctx.restore(); }, </code></pre> <p>Basically, I draw each view's canvas into the game canvas using <code>drawImage</code> of the context.</p> <p>I <code>addEventListener</code> to <code>HandView</code>'s canvas (which is its <code>el</code>) to handle click. In this handler, I check the mouse positions against which <code>CardView</code>, then manipulate that view.</p> <p>Mind you, this is just something I'm experimenting since I'm new to <code>Backbone.js</code> too. This maybe the worst way to do, but I just hope that you can see one of the ways to do it.</p> <p>I do wish that we could check mouse against a canvas that does not exists in the DOM. If it's possible, we could just <code>addEventListener</code> to <code>CardView</code>'s canvas and let it translate and re-render. No need for <code>HandView</code>'s canvas to loop through its views.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload