You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BitmapData.move(x, y) allows you to shift the contents of the BitmapData horizontally and vertically by the given amounts. The image wraps-around the edges of the BitmapData.
BitmapData.moveH(distance) allows you to horizontally shift the BitmapData with wrap-around the edges.
BitmapData.moveV(distance) allows you to vertically shift the BitmapData with wrap-around the edges.
Copy file name to clipboardExpand all lines: README.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -324,6 +324,9 @@ Version 2.4 - "Katar" - in dev
324
324
* TilemapLayer.resize allows you to resize a TilemapLayer. It will update the internal canvas object and corresponding texture dimensions (#1881)
325
325
* Pointer button handling has been given an overhaul. It has the following new boolean properties: `leftButton`, `rightButton`, `middleButton`, `backButton`, `forwardButton` and `eraserButton`. So you can now easily check which buttons are active and build right or middle click support into your games. The Pointer object normalises these properties for you, regardless if they came from a MouseEvent or PointerEvent (thanks @youssefdetovernickr for the idea #1848)
326
326
* Text has a new style property: tabs. This allows you to specify a pixel value (or values) that allows you to space out text that contains tab characters within it. `Text.tabs` can be either an integer, in which case all tabs share the same spacing, or an array of pixel values corresponding exactly to the number of tabs per line of text. This allows you to easily align columns of data in a single Text object.
327
+
* BitmapData.move(x, y) allows you to shift the contents of the BitmapData horizontally and vertically by the given amounts. The image wraps-around the edges of the BitmapData.
328
+
* BitmapData.moveH(distance) allows you to horizontally shift the BitmapData with wrap-around the edges.
329
+
* BitmapData.moveV(distance) allows you to vertically shift the BitmapData with wrap-around the edges.
* Shifts the contents of this BitmapData by the distances given.
232
+
*
233
+
* The image will wrap-around the edges on all sides.
234
+
*
235
+
* @method Phaser.BitmapData#move
236
+
* @param {integer} x - The amount of pixels to horizontally shift the canvas by. Use a negative value to shift to the left, positive to the right.
237
+
* @param {integer} y - The amount of pixels to vertically shift the canvas by. Use a negative value to shift up, positive to shift down.
238
+
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
239
+
*/
240
+
move: function(x,y){
241
+
242
+
if(x!==0)
243
+
{
244
+
this.moveH(x);
245
+
}
246
+
247
+
if(y!==0)
248
+
{
249
+
this.moveV(y);
250
+
}
251
+
252
+
returnthis;
253
+
254
+
},
255
+
256
+
/**
257
+
* Shifts the contents of this BitmapData horizontally.
258
+
*
259
+
* The image will wrap-around the sides.
260
+
*
261
+
* @method Phaser.BitmapData#moveH
262
+
* @param {integer} distance - The amount of pixels to horizontally shift the canvas by. Use a negative value to shift to the left, positive to the right.
263
+
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
264
+
*/
265
+
moveH: function(distance){
266
+
267
+
varc=this._swapCanvas;
268
+
varctx=c.getContext('2d');
269
+
varh=this.height;
270
+
varsrc=this.canvas;
271
+
272
+
ctx.clearRect(0,0,this.width,this.height);
273
+
274
+
if(distance<0)
275
+
{
276
+
distance=Math.abs(distance);
277
+
278
+
// Moving to the left
279
+
varw=this.width-distance;
280
+
281
+
// Left-hand chunk
282
+
ctx.drawImage(src,0,0,distance,h,w,0,distance,h);
283
+
284
+
// Rest of the image
285
+
ctx.drawImage(src,distance,0,w,h,0,0,w,h);
286
+
}
287
+
else
288
+
{
289
+
// Moving to the right
290
+
varw=this.width-distance;
291
+
292
+
// Right-hand chunk
293
+
ctx.drawImage(src,w,0,distance,h,0,0,distance,h);
294
+
295
+
// Rest of the image
296
+
ctx.drawImage(src,0,0,w,h,distance,0,w,h);
297
+
}
298
+
299
+
this.clear();
300
+
301
+
returnthis.copy(this._swapCanvas);
302
+
303
+
},
304
+
305
+
/**
306
+
* Shifts the contents of this BitmapData vertically.
307
+
*
308
+
* The image will wrap-around the sides.
309
+
*
310
+
* @method Phaser.BitmapData#moveV
311
+
* @param {integer} distance - The amount of pixels to vertically shift the canvas by. Use a negative value to shift up, positive to shift down.
312
+
* @return {Phaser.BitmapData} This BitmapData object for method chaining.
313
+
*/
314
+
moveV: function(distance){
315
+
316
+
varc=this._swapCanvas;
317
+
varctx=c.getContext('2d');
318
+
varw=this.width;
319
+
varsrc=this.canvas;
320
+
321
+
ctx.clearRect(0,0,this.width,this.height);
322
+
323
+
if(distance<0)
324
+
{
325
+
distance=Math.abs(distance);
326
+
327
+
// Moving up
328
+
varh=this.height-distance;
329
+
330
+
// Top chunk
331
+
ctx.drawImage(src,0,0,w,distance,0,h,w,distance);
332
+
333
+
// Rest of the image
334
+
ctx.drawImage(src,0,distance,w,h,0,0,w,h);
335
+
}
336
+
else
337
+
{
338
+
// Moving down
339
+
varh=this.height-distance;
340
+
341
+
// Bottom chunk
342
+
ctx.drawImage(src,0,h,w,distance,0,0,w,distance);
343
+
344
+
// Rest of the image
345
+
ctx.drawImage(src,0,0,w,h,0,distance,w,h);
346
+
}
347
+
348
+
this.clear();
349
+
350
+
returnthis.copy(this._swapCanvas);
351
+
352
+
},
353
+
354
+
grid: function(w,h,color){
355
+
356
+
this.context.fillStyle=color;
357
+
358
+
for(vary=0;y<this.height;y+=h)
359
+
{
360
+
this.context.fillRect(0,y,this.width,1);
361
+
}
362
+
363
+
for(varx=0;x<this.width;x+=w)
364
+
{
365
+
this.context.fillRect(x,0,1,this.height);
366
+
}
367
+
368
+
},
369
+
370
+
generate: function(data,palette,size){
371
+
372
+
if(typeofpalette==='undefined'){palette='arne';}
373
+
if(typeofsize==='undefined'){size=8;}
374
+
375
+
varw=data[0].length*size;
376
+
varh=data.length*size;
377
+
378
+
this.resize(w,h);
379
+
380
+
// Draw it
381
+
for(vary=0;y<data.length;y++)
382
+
{
383
+
varrow=data[y];
384
+
385
+
for(varx=0;x<row.length;x++)
386
+
{
387
+
vard=row[x];
388
+
389
+
if(d!=='.'&&d!==' ')
390
+
{
391
+
this.context.fillStyle=this.palettes[palette][d];
392
+
this.context.fillRect(x*size,y*size,size,size);
393
+
}
394
+
}
395
+
}
396
+
397
+
},
398
+
216
399
/**
217
400
* Updates the given objects so that they use this BitmapData as their texture. This will replace any texture they will currently have set.
0 commit comments