|
| 1 | + |
| 2 | +var Class = require('../../utils/Class'); |
| 3 | +var Mesh = require('../mesh/Mesh'); |
| 4 | + |
| 5 | +var Quad = new Class({ |
| 6 | + |
| 7 | + Extends: Mesh, |
| 8 | + |
| 9 | + initialize: |
| 10 | + |
| 11 | + function Quad (state, x, y, texture, frame) |
| 12 | + { |
| 13 | + // 0----3 |
| 14 | + // |\ B| |
| 15 | + // | \ | |
| 16 | + // | \ | |
| 17 | + // | A \| |
| 18 | + // | \ |
| 19 | + // 1----2 |
| 20 | + |
| 21 | + // var topLeft = { x: -250, y: -250 }; |
| 22 | + var topRight = { x: 250, y: -250 }; |
| 23 | + var bottomLeft = { x: -250, y: 250 }; |
| 24 | + var bottomRight = { x: 250, y: 250 }; |
| 25 | + |
| 26 | + // tl, bl, br, tr |
| 27 | + var vertices = [ |
| 28 | + 0, 0, |
| 29 | + bottomLeft.x, bottomLeft.y, |
| 30 | + bottomRight.x, bottomRight.y, |
| 31 | + topRight.x, topRight.y |
| 32 | + ]; |
| 33 | + |
| 34 | + var uv = [ 0, 0, 0, 1, 1, 1, 1, 0 ]; |
| 35 | + var indices = [ 0, 1, 2, 0, 2, 3 ]; |
| 36 | + |
| 37 | + Mesh.call(this, state, x, y, vertices, uv, indices, texture, frame); |
| 38 | + |
| 39 | + this.halfWidth = Math.floor(this.width / 2); |
| 40 | + this.halfHeight = Math.floor(this.height / 2); |
| 41 | + |
| 42 | + this._topLeft = { x: 0, y: 0 }; |
| 43 | + this._topRight = { x: 250, y: -250 }; |
| 44 | + this._bottomLeft = { x: -250, y: 250 }; |
| 45 | + this._bottomRight = { x: 250, y: 250 }; |
| 46 | + |
| 47 | + this.setTopLeft(this.halfWidth, this.halfHeight); |
| 48 | + |
| 49 | + // var v = this.vertices; |
| 50 | + |
| 51 | + // v[0] = -w; |
| 52 | + // v[1] = -h; |
| 53 | + // v[1] = -h; |
| 54 | + }, |
| 55 | + |
| 56 | + topLeftX: { |
| 57 | + |
| 58 | + get: function () |
| 59 | + { |
| 60 | + return this._topLeft.x; |
| 61 | + }, |
| 62 | + |
| 63 | + set: function (value) |
| 64 | + { |
| 65 | + this._topLeft.x = value; |
| 66 | + this.vertices[0] = value - this.x; |
| 67 | + } |
| 68 | + |
| 69 | + }, |
| 70 | + |
| 71 | + topLeftY: { |
| 72 | + |
| 73 | + get: function () |
| 74 | + { |
| 75 | + return this._topLeft.y; |
| 76 | + }, |
| 77 | + |
| 78 | + set: function (value) |
| 79 | + { |
| 80 | + this._topLeft.y = value; |
| 81 | + this.vertices[1] = value - this.y; |
| 82 | + } |
| 83 | + |
| 84 | + }, |
| 85 | + |
| 86 | + setTopLeft: function (x, y) |
| 87 | + { |
| 88 | + this.topLeftX = x; |
| 89 | + this.topLeftY = y; |
| 90 | + } |
| 91 | + |
| 92 | +}); |
| 93 | + |
| 94 | +module.exports = Quad; |
0 commit comments