Project1

标题: 【抛砖引玉】地图格子光标 [打印本页]

作者: sundeshuo    时间: 2024-2-20 22:51
标题: 【抛砖引玉】地图格子光标

JAVASCRIPT 代码复制
  1. const _Spriteset_Map_createLowerLayer = Spriteset_Map.prototype.createLowerLayer;
  2. Spriteset_Map.prototype.createLowerLayer = function () {
  3.     _Spriteset_Map_createLowerLayer.call(this);
  4.     if (Utils.isNwjs()) {
  5.         this.createCursor();
  6.     }
  7. }
  8.  
  9. Spriteset_Map.prototype.createCursor = function () {
  10.     this._cursorSprite = new Sprite_Cursor();
  11.     this._cursorSprite.z = 2;
  12.     this._tilemap.addChild(this._cursorSprite);
  13. }
  14.  
  15. class Sprite_Cursor extends Sprite {
  16.     initialize() {
  17.         super.initialize();
  18.         this.create();
  19.     }
  20.  
  21.     create() {
  22.         const bitmap = new Bitmap(48, 48);
  23.         const c = "#B22222";
  24.         bitmap.fillRect(0, 0, 48, 48, c);
  25.         bitmap.clearRect(12, 0, 24, 48);
  26.         bitmap.clearRect(0, 12, 48, 24);
  27.         bitmap.clearRect(3, 3, 42, 42);
  28.         this.bitmap = bitmap;
  29.     }
  30.  
  31.     update() {
  32.         super.update();
  33.         const mapX = $gameMap.canvasToMapX(TouchInput.x);
  34.         const mapY = $gameMap.canvasToMapY(TouchInput.y);
  35.         const sx = $gameMap.adjustX(mapX) * $gameMap.tileWidth();
  36.         const sy = $gameMap.adjustY(mapY) * $gameMap.tileHeight();
  37.         this.move(sx, sy);
  38.     }
  39. }

作者: Arrose    时间: 2024-2-21 11:13
支持,刚好要用到




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1