slifer 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slifer",
3
- "version": "0.2.0",
3
+ "version": "0.2.01",
4
4
  "description": "A game framework made for bun and typescript",
5
5
  "module": "index.ts",
6
6
  "devDependencies": {
@@ -65,13 +65,32 @@ class Graphics {
65
65
  return new Image(texture);
66
66
  }
67
67
 
68
- draw(image: Image, position: Vector2) {}
68
+ /**
69
+ * Method to draw to the screen simply
70
+ * @param image Image object to draw. Made using Slifer.Graphics.loadImage
71
+ * @param position position to draw the image
72
+ *
73
+ */
74
+ draw(image: Image, position: Vector2) {
75
+ const dstRect = new Uint32Array(4);
76
+ dstRect[0] = position.x;
77
+ dstRect[1] = position.y;
78
+ dstRect[2] = image.width;
79
+ dstRect[3] = image.height;
80
+
81
+ libsdl.symbols.SDL_RenderCopy(
82
+ Global.ptrRenderer,
83
+ (image as any).pointer,
84
+ null,
85
+ dstRect
86
+ );
87
+ }
69
88
 
70
89
  /**
71
- * Method to draw the image to the screen
90
+ * Method to draw the image to the screen with extended arguments
72
91
  *
73
92
  * @param image Image object to draw. Made using Slifer.Graphics.loadImage
74
- * @param x x position to draw image
93
+ * @param position position to draw the image
75
94
  * @param y y position to draw image
76
95
  * @param rotation (optional) rotation of image
77
96
  * @param xs (optional) scale of x axis
@@ -81,39 +100,27 @@ class Graphics {
81
100
  drawEx(
82
101
  image: Image,
83
102
  position: Vector2,
84
- clipRectangle?: Rectangle,
103
+ clipRectangle?: Rectangle | null,
85
104
  rotation?: number,
86
105
  xs?: number,
87
106
  ys?: number,
88
107
  flip?: true
89
108
  ) {
90
109
  const _dest = new Uint32Array(4);
91
- const wArr = new Uint32Array(1);
92
- const hArr = new Uint32Array(1);
93
110
  let srcRect: null | Uint32Array = null;
94
111
 
95
- if (clipRectangle == undefined) {
96
- libsdl.symbols.SDL_QueryTexture(
97
- (image as any).pointer,
98
- null,
99
- null,
100
- ptr(wArr),
101
- ptr(hArr)
102
- );
103
- } else {
112
+ if (clipRectangle != null) {
104
113
  srcRect = new Uint32Array(4);
105
- srcRect[0] = clipRectangle.x;
106
- srcRect[1] = clipRectangle.y;
107
- srcRect[2] = clipRectangle.width;
108
- srcRect[3] = clipRectangle.height;
109
- wArr[0] = clipRectangle.width;
110
- hArr[0] = clipRectangle.height;
114
+ srcRect[0] = clipRectangle.position.x;
115
+ srcRect[1] = clipRectangle.position.y;
116
+ srcRect[2] = clipRectangle.size.x;
117
+ srcRect[3] = clipRectangle.size.y;
111
118
  }
112
119
 
113
120
  _dest[0] = position.x;
114
121
  _dest[1] = position.y;
115
- _dest[2] = wArr[0] * (xs ? xs : 1);
116
- _dest[3] = hArr[0] * (ys ? ys : 1);
122
+ _dest[2] = image.width * (xs ? xs : 1);
123
+ _dest[3] = image.height * (ys ? ys : 1);
117
124
  const _center = new Uint32Array(2);
118
125
  _center[0] = _dest[2] / 2;
119
126
  _center[1] = _dest[3] / 2;
@@ -200,9 +207,25 @@ class Graphics {
200
207
 
201
208
  class Image {
202
209
  private pointer;
210
+ public readonly width;
211
+ public readonly height;
203
212
 
204
213
  constructor(texture: Pointer) {
205
214
  this.pointer = texture;
215
+
216
+ const _wArr = new Uint32Array(1);
217
+ const _hArr = new Uint32Array(1);
218
+
219
+ libsdl.symbols.SDL_QueryTexture(
220
+ texture,
221
+ null,
222
+ null,
223
+ ptr(_wArr),
224
+ ptr(_hArr)
225
+ );
226
+
227
+ this.width = _wArr[0];
228
+ this.height = _hArr[0];
206
229
  }
207
230
  }
208
231