Note that there are some explanatory texts on larger screens.

plurals
  1. POhtml5 canvas sprite sheet random rows/columns
    primarykey
    data
    text
    <p>At the moment the code chooses from one row of images from the sprite sheet and displays it going from left to right of the screen, what I'd like to do is select random images like its doing but from a different row, for example I have 3 rows with 1 row of 3 different coloured asteroids 32 by 32, 2nd row 3 different coloured 64 by 64 and final row 3 different coloured 128 by 128. How would I random the rows to show different sizes as well as colours</p> <p>This is the current code, any help would be fantastic.</p> <pre><code>function Enemy() { this.srcX = 0; this.srcY = 528; this.width = 32; this.height = 33; this.previousSpeed = 0; this.speed = 2; this.acceleration = 0.005; this.imageNumber = Math.floor(Math.random()*3); this.drawX = Math.floor(Math.random() * 1000) + gameWidth; this.drawY = Math.floor(Math.random() * gameHeight); this.collisionPointX = this.drawX + this.width; this.collisionPointY = this.drawY + this.height; } Enemy.prototype.draw = function () { this.drawX -= this.speed; ctxEnemy.drawImage(imgSprite,this.srcX+this.imageNumber*this.width,this.srcY,this.width,this.height,this.drawX,this.drawY,this.width,this.height); this.checkEscaped(); }; Enemy.prototype.assignValues = function() { } Enemy.prototype.checkEscaped = function () { if (this.drawX + this.width &lt;= 0) { this.recycleEnemy(); } }; Enemy.prototype.recycleEnemy = function () { this.drawX = Math.floor(Math.random() * 1000) + gameWidth; this.drawY = Math.floor(Math.random() * gameHeight); }; function clearCtxEnemy() { ctxEnemy.clearRect(0, 0, gameWidth, gameHeight); } </code></pre>
    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. 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