设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 4820|回复: 9
打印 上一主题 下一主题

[通用发布] 【RPG MAKER MV】在地图上显示文字的脚本 2.0

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
37 小时
注册时间
2015-11-8
帖子
8
跳转到指定楼层
1
发表于 2015-11-8 18:54:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 (^_^) 于 2017-7-12 02:19 编辑

在地图上显示文字的脚本。可以实现诸如在宝箱上方显示“不要靠近”;在角色下方显示“HP 91”;在角色上方显示红色的“-99999”,接着文字会向上滑行并在2秒后消失等功能。

SimpleText Write Player_1 eventID:-1,duration:0,isFollow:true
SimpleText Write -1 eventID:-1,duration:1000,isFollow:false,moveY:1
SimpleText Write Map_1 offsetY:200

Write后面的那些顺序无所谓,大小写无所谓,但是不能有空格。其中,eventID是变量名,冒号是分隔符,-1是赋予eventID的值。如果把eventID这项省略的话文字就会出现在屏幕中心。可以通过offsetX/offsetY来修改坐标。isFollow决定文字是否跟随event。duration是保留文字的时间,0或者负数意味着永久保留。moveX/moveY用来移动文字。

SimpleText Font font:GameFont,color:#910010,size:26,outlineColor:rgba(0,0,0,0.5)

修改字体不会影响前面已经写出的文字,但是会影响后面所有生成的文字。其他机理同上。

SimpleText ClearAll
SimpleText ClearMap
SimpleText ClearByEventID -1
SimpleText ClearByGroup MONSTER1

JAVASCRIPT 代码复制
  1. /*:
  2. * @plugindesc Display texts on screen. Version: 2.0
  3. * @author Rui
  4. * @help
  5. * ----------------------------------------
  6. * SimpleText Write Text Args
  7. * ----------------------------------------
  8. * write text on screen. all texts will be saved with map, only need to add once.
  9. *
  10. * Text
  11. *       String without spaces. Apple_tree will be displayed as Apple tree.
  12. * Args
  13. *       eventID: event id which text will be centered at. value of -1 indicates player. ignore this parameter indicates center of screen.
  14. *       offsetX/offsetY: Offset from original position. Default: 0.
  15. *       duration: text display duration. value of 0 or less indicates permanent. default: 0.   
  16. *       moveX/moveY: movement of text. default: 0.
  17. *       isFollow: whether text follows event or not. this parameter is ignored when eventID is ignored. defualt: true  
  18. *       group: texts can be cleard by group. case insensitive. default: ALL.
  19. *       eg. SimpleText Write Player_1 eventID:-1,duration:0,isFollow:true
  20. *       eg. SimpleText Write -1 eventID:-1,duration:1000,isFollow:false,moveY:1
  21. *       eg. SimpleText Write Map_1 offsetY:200
  22. *       parameters are separated by comma. spaces are not allowed.
  23. *       all commands are case insensitive.
  24. *
  25. * ----------------------------------------
  26. * SimpleText Font Args
  27. * ----------------------------------------
  28. * setup font. call this command will not affect texts that have already been created.
  29. *
  30. * Args
  31. *       font, size, isItalic, color, outlineWidth, outlineColor, opacity
  32. *       eg. SimpleText Font font:GameFont,color:#910010,size:26,outlineColor:rgba(0,0,0,0.5),opacity:255
  33. *       parameters are separated by comma. spaces are not allowed.
  34. *       all commands are case insensitive.
  35. *        
  36. * ----------------------------------------
  37. * SimpleText ClearAll
  38. * SimpleText ClearMap
  39. * SimpleText ClearByEventID eventID
  40. * SimpleText ClearByGroup group
  41. * ----------------------------------------
  42. * clear texts on screen
  43. * Args
  44. *       eventID: clear all texts bind to this event.
  45. *       group: clear all texts bind to this group.
  46.         eg. SimpleText ClearByEventID -1
  47. *       all commands are case insensitive.
  48. *
  49. *
  50. * License: Free for personal and commercial use
  51. */
  52.  
  53.  
  54. (function() {
  55.     //SimpleText
  56.     function SimpleText() {
  57.         this.simpleTextObjList = {};    //dictionary with mapID as key
  58.         this.fontFace = "GameFont";
  59.         this.fontSize = 21;
  60.         this.fontItalic = false;
  61.         this.textColor = "#ffffff";
  62.         this.outlineColor = "rgba(0,0,0,0.5)";
  63.         this.outlineWidth = 2;
  64.         this.opacity = 255;
  65.     }
  66.  
  67.     SimpleText.prototype.changeFont = function(args) {
  68.         var commandList = args.split(',');
  69.  
  70.         for (var i = commandList.length - 1; i >= 0; i--) {
  71.             var command = commandList[i].toUpperCase();
  72.  
  73.             if (command.lastIndexOf("FONT:", 0) === 0) {
  74.                 this.fontFace = command.substring("FONT:".length).replace(/_/g, " ");
  75.             }
  76.             else if (command.lastIndexOf("SIZE:", 0) === 0) {
  77.                 this.fontSize = parseInt(command.substring("SIZE:".length));
  78.             }
  79.             else if (command.lastIndexOf("ISITALIC:", 0) === 0) {
  80.                 this.fontItalic = command.substring("ISITALIC:".length) === "TRUE";
  81.             }
  82.             else if (command.lastIndexOf("COLOR:", 0) === 0) {
  83.                 this.textColor = command.substring("COLOR:".length);
  84.             }
  85.             else if (command.lastIndexOf("OUTLINEWIDTH:", 0) === 0) {
  86.                 this.outlineWidth = parseInt(command.substring("OUTLINEWIDTH:".length));
  87.             }
  88.             else if (command.lastIndexOf("OUTLINECOLOR:", 0) === 0) {
  89.                 this.outlineColor = command.substring("OUTLINECOLOR:".length);
  90.             }
  91.             else if (command.lastIndexOf("OPACITY:", 0) === 0) {
  92.                 this.opacity = parseInt(command.substring("OPACITY:".length));
  93.             }
  94.         }
  95.     }
  96.  
  97.     SimpleText.prototype.getSimpleTextObjListByMapID = function() {
  98.         var mapID = $gameMap.mapId().toString();
  99.         if (DataManager.___simpleText___.simpleTextObjList.hasOwnProperty(mapID)) {
  100.             return DataManager.___simpleText___.simpleTextObjList[mapID];
  101.         }
  102.         else {
  103.             DataManager.___simpleText___.simpleTextObjList[mapID] = [];
  104.             return DataManager.___simpleText___.simpleTextObjList[mapID];
  105.         }        
  106.     };
  107.  
  108.     //SimpleTextObj object
  109.     function SimpleTextObj(text, args) {
  110.         this.text = text.replace(/_/g, " ");
  111.         this.eventID = null;
  112.         this.duration = null;
  113.         this.offsetX = 0;
  114.         this.offsetY = 0;
  115.         this.moveX = 0;
  116.         this.moveY = 0;
  117.         this.isFollow = true;
  118.         this.group = "ALL";
  119.  
  120.         this.fontFace = DataManager.___simpleText___.fontFace;
  121.         this.fontSize = DataManager.___simpleText___.fontSize;
  122.         this.fontItalic = DataManager.___simpleText___.fontItalic;
  123.         this.textColor = DataManager.___simpleText___.textColor;
  124.         this.outlineColor = DataManager.___simpleText___.outlineColor;
  125.         this.outlineWidth = DataManager.___simpleText___.outlineWidth;
  126.         this.opacity = DataManager.___simpleText___.opacity;
  127.  
  128.         var commandList = args.split(',');
  129.  
  130.         for (var i = commandList.length - 1; i >= 0; i--) {
  131.             var command = commandList[i].toUpperCase();
  132.  
  133.             if (command.lastIndexOf("EVENTID:", 0) === 0) {
  134.                 this.eventID = parseInt(command.substring("EVENTID:".length));
  135.             }
  136.             else if (command.lastIndexOf("DURATION:", 0) === 0) {
  137.                 this.duration = parseInt(command.substring("DURATION:".length));
  138.                 if (this.duration <= 0)
  139.                     this.duration = null;
  140.             }
  141.             else if (command.lastIndexOf("OFFSETX:", 0) === 0) {
  142.                 this.offsetX = parseInt(command.substring("OFFSETX:".length));
  143.             }
  144.             else if (command.lastIndexOf("OFFSETY:", 0) === 0) {
  145.                 this.offsetY = parseInt(command.substring("OFFSETY:".length));
  146.                 this.offsetY = this.offsetY * -1;
  147.             }
  148.             else if (command.lastIndexOf("MOVEX:", 0) === 0) {
  149.                 this.moveX = parseInt(command.substring("MOVEX:".length));
  150.             }
  151.             else if (command.lastIndexOf("MOVEY:", 0) === 0) {
  152.                 this.moveY = parseInt(command.substring("MOVEY:".length));
  153.                 this.moveY = this.moveY * -1;
  154.             }
  155.             else if (command.lastIndexOf("ISFOLLOW:", 0) === 0) {
  156.                 this.isFollow = command.substring("ISFOLLOW:".length);
  157.                 this.isFollow = this.isFollow === "TRUE"
  158.             }
  159.             else if (command.lastIndexOf("GROUP:", 0) === 0) {
  160.                 this.group = command.substring("GROUP:".length);
  161.             }
  162.         }
  163.  
  164.         if (this.eventID != null && this.isFollow == false) {
  165.             var event = this.findEvent();
  166.             this.startX = event._realX;
  167.             this.startY = event._realY;
  168.             this.adjustY = event.shiftY() + event.jumpHeight();
  169.         }
  170.  
  171.         this.delete = false;
  172.  
  173.         DataManager.___simpleText___.getSimpleTextObjListByMapID().push(this);
  174.     }
  175.  
  176.     //add sprite when creating text or starting scene
  177.     SimpleTextObj.prototype.addSprite = function(spriteset_Map, x, y) {
  178.         var sprite = new Sprite();
  179.         sprite.anchor.x = 0.5;
  180.         sprite.anchor.y = 1;
  181.         sprite.z = 9;
  182.         sprite.bitmap = new Bitmap(this.fontSize * this.text.length + this.outlineWidth * 2 + 6, this.fontSize + this.outlineWidth * 2 + 6);
  183.         sprite.bitmap.fontFace = this.fontFace;
  184.         sprite.bitmap.fontSize = this.fontSize;
  185.         sprite.bitmap.fontItalic = this.fontItalic;
  186.         sprite.bitmap.textColor = this.textColor;
  187.         sprite.bitmap.outlineColor = this.outlineColor;
  188.         sprite.bitmap.outlineWidth = this.outlineWidth;
  189.         sprite.bitmap.drawText(this.text, 0, 0, sprite.bitmap.width, sprite.bitmap.height, "center");
  190.         sprite.opacity = this.opacity;
  191.         sprite.___simpleTextObjRef___ = this;
  192.  
  193.         spriteset_Map._tilemap.addChild(sprite);
  194.  
  195.         sprite.x = x;
  196.         sprite.y = y;
  197.  
  198.         return sprite;
  199.     };
  200.  
  201.     //get event
  202.     SimpleTextObj.prototype.findEvent = function() {
  203.         if ($gameParty.inBattle()) {
  204.             return null;
  205.         }
  206.         else if (this.eventID == null) {
  207.             return null;
  208.         }
  209.         else if (this.eventID < 0) {
  210.             return $gamePlayer;
  211.         }
  212.         else {
  213.             return $gameMap.event(this.eventID);
  214.         }
  215.     }
  216.  
  217.     //update function
  218.     SimpleTextObj.prototype.update = function(index, spriteset_Map) {
  219.         var event = null;
  220.         var found = false;
  221.         var child = null;
  222.  
  223.         //if event is null
  224.         if (this.delete == false) {
  225.             if (this.eventID != null) {
  226.                 event = this.findEvent();
  227.                 if (event == null) {
  228.                     this.delete = true;
  229.                 }
  230.             }
  231.         }
  232.  
  233.         //if duration not null
  234.         if (this.delete == false) {
  235.             if (this.duration != null) {
  236.                 this.duration--;
  237.                 if (this.duration <= 0) {
  238.                     this.delete = true;
  239.                 }
  240.             }
  241.         }
  242.  
  243.         for (var i = spriteset_Map._tilemap.children.length - 1; i >= 0; i--) {
  244.             child = spriteset_Map._tilemap.children[i];
  245.  
  246.             if (typeof(child.___simpleTextObjRef___)==='undefined') {
  247.                 continue;
  248.             }
  249.             else {
  250.                 if (child.___simpleTextObjRef___ == this) {
  251.                     found = true;
  252.  
  253.                     if (this.delete == true) {
  254.                         child.bitmap = null;
  255.                         spriteset_Map._tilemap.removeChildAt(i);
  256.                     }
  257.  
  258.                     break;
  259.                 }
  260.             }
  261.         }
  262.  
  263.         if (this.delete == true) {
  264.             DataManager.___simpleText___.getSimpleTextObjListByMapID().splice(index, 1);
  265.             return;
  266.         }
  267.  
  268.         //get center position
  269.         var centerX = 0;
  270.         var centerY = 0;
  271.  
  272.         if (event == null) {
  273.             centerX = Graphics.width / 2;
  274.             centerY = Graphics.height / 2;
  275.         }
  276.         else {
  277.             if (this.isFollow == false) {
  278.                 var scrolledX = $gameMap.adjustX(this.startX);
  279.                 var scrolledY = $gameMap.adjustY(this.startY);
  280.  
  281.                 var tw = $gameMap.tileWidth();
  282.                 var screenX = Math.round(scrolledX * tw + tw / 2);
  283.  
  284.                 var th = $gameMap.tileHeight();
  285.                 var screenY = Math.round(scrolledY * th + th - this.adjustY);
  286.  
  287.                 centerX = screenX;
  288.                 centerY = screenY - $gameMap.tileHeight();
  289.             }
  290.             else {
  291.                 centerX = event.screenX();
  292.                 centerY = event.screenY() - $gameMap.tileHeight();
  293.             }
  294.         }
  295.  
  296.         centerX += this.offsetX;
  297.         centerY += this.offsetY;
  298.  
  299.         if (found == false) {
  300.             child = this.addSprite(spriteset_Map, centerX, centerY);
  301.         }
  302.         else {
  303.             child.x = centerX;
  304.             child.y = centerY;
  305.         }
  306.  
  307.         //update offsets
  308.         this.offsetX += this.moveX;
  309.         this.offsetY += this.moveY;
  310.     };
  311.  
  312.     //create SimpleText in DataManager
  313.     var _DataManager_createGameObjects = DataManager.createGameObjects;
  314.     DataManager.createGameObjects = function() {
  315.         _DataManager_createGameObjects.call(this);
  316.  
  317.         if (typeof(DataManager.___simpleText___)==='undefined')
  318.             DataManager.___simpleText___ = new SimpleText();
  319.     };
  320.  
  321.     //remove sprites on creeate tilemap
  322.     var _Spriteset_Map_prototype_createTilemap = Spriteset_Map.prototype.createTilemap;
  323.     Spriteset_Map.prototype.createTilemap = function() {
  324.         _Spriteset_Map_prototype_createTilemap.call(this);
  325.  
  326.         //remove all text sprites if exits
  327.         for (var i = this._tilemap.children.length - 1; i >= 0; i--) {
  328.             var child = this._tilemap.children[i];
  329.  
  330.             if (typeof(child.___simpleTextObjRef___)==='undefined') {
  331.                 continue;
  332.             }
  333.             else {
  334.                 child.bitmap = null;
  335.                 this._tilemap.removeChildAt(i);
  336.             }
  337.         }
  338.     }
  339.  
  340.     //update SimpleTextObjList
  341.     var _Spriteset_Map_prototype_updateTilemap = Spriteset_Map.prototype.updateTilemap;
  342.     Spriteset_Map.prototype.updateTilemap = function() {
  343.         _Spriteset_Map_prototype_updateTilemap.call(this);
  344.  
  345.         var simpleTextObjList = DataManager.___simpleText___.getSimpleTextObjListByMapID();
  346.         for (var i = simpleTextObjList.length - 1; i >= 0; i--)
  347.             simpleTextObjList[i].update(i, this);
  348.     };
  349.  
  350.     //read plugin command
  351.     var _Game_Interpreter_prototype_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  352.     Game_Interpreter.prototype.pluginCommand = function(command, args) {
  353.         _Game_Interpreter_prototype_pluginCommand.call(this, command, args);
  354.  
  355.         //only work with Scene_Map
  356.         if (SceneManager._scene instanceof Scene_Map == false)
  357.             return;
  358.  
  359.         if (command.toUpperCase() == "SIMPLETEXT") {
  360.             var argsLength = args.length;
  361.             var action = args[0].toUpperCase();
  362.             if (action == "WRITE") {
  363.                 if (argsLength == 3) {
  364.                     var simpleTextObj = new SimpleTextObj(args[1], args[2]);
  365.                 }
  366.             }
  367.             else if (action == "FONT") {
  368.                 if (argsLength == 2) {
  369.                     DataManager.___simpleText___.changeFont(args[1]);
  370.                 }
  371.             }
  372.             else if (action == "CLEARALL") {
  373.                 for (var mapID in DataManager.___simpleText___.simpleTextObjList) {
  374.                     var simpleTextObjList = DataManager.___simpleText___.simpleTextObjList[mapID];
  375.  
  376.                     for (var i = simpleTextObjList.length - 1; i >= 0; i--)
  377.                         simpleTextObjList[i].delete = true;
  378.                 }
  379.             }
  380.             else if (action == "CLEARMAP") {
  381.                 var simpleTextObjList = DataManager.___simpleText___.getSimpleTextObjListByMapID();
  382.                 for (var i = simpleTextObjList.length - 1; i >= 0; i--)
  383.                     simpleTextObjList[i].delete = true;
  384.             }
  385.             else if (action == "CLEARBYEVENTID") {
  386.                 if (argsLength == 2) {
  387.                     var eventID = parseInt(args[1]);
  388.  
  389.                     var simpleTextObjList = DataManager.___simpleText___.getSimpleTextObjListByMapID();
  390.                     for (var i = simpleTextObjList.length - 1; i >= 0; i--) {
  391.                         var simpleTextObj = simpleTextObjList[i];
  392.                         if (simpleTextObj.eventID === eventID)
  393.                             simpleTextObj.delete = true;
  394.                     }
  395.                 }
  396.             }
  397.             else if (action == "CLEARBYGROUP") {
  398.                 if (argsLength == 2) {
  399.                     var group = args[1].toUpperCase();
  400.  
  401.                     var simpleTextObjList = DataManager.___simpleText___.getSimpleTextObjListByMapID();
  402.                     for (var i = simpleTextObjList.length - 1; i >= 0; i--) {
  403.                         var simpleTextObj = simpleTextObjList[i];
  404.                         if (simpleTextObj.group === group)
  405.                             simpleTextObj.delete = true;
  406.                     }
  407.                 }
  408.             }
  409.         }
  410.     };
  411. })();

点评

叫我干嘛  发表于 2015-11-9 12:22

评分

参与人数 1星屑 +66 收起 理由
余烬之中 + 66

查看全部评分

Lv1.梦旅人

梦石
0
星屑
50
在线时间
37 小时
注册时间
2015-11-8
帖子
8
2
 楼主| 发表于 2015-11-9 08:14:52 | 只看该作者
本帖最后由 (^_^) 于 2017-7-9 02:34 编辑

.                                       
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
55
在线时间
64 小时
注册时间
2014-3-25
帖子
6
3
发表于 2015-11-9 12:00:55 | 只看该作者
能不能发一个举例的工程,小白,不会用
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
37 小时
注册时间
2015-11-8
帖子
8
4
 楼主| 发表于 2015-11-9 15:59:55 | 只看该作者
本帖最后由 (^_^) 于 2017-7-9 02:34 编辑

.                                    
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9275
在线时间
2504 小时
注册时间
2011-5-20
帖子
15389

开拓者

5
发表于 2015-11-14 18:53:49 | 只看该作者
(^_^) 发表于 2015-11-9 15:59
在工程里启用这个脚本后,建立新事件。随便选择一个角色作为图片,然后建立plugin command,在文本框内输 ...

在一张地图的不同位置同时显示也可以吗···会不会卡爆?
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
37 小时
注册时间
2015-11-8
帖子
8
6
 楼主| 发表于 2015-11-16 13:50:48 | 只看该作者
chd114 发表于 2015-11-14 18:53
在一张地图的不同位置同时显示也可以吗···会不会卡爆?

可以同时在多个EVENT上面显示。显示太多的话总是会卡的吧。
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9275
在线时间
2504 小时
注册时间
2011-5-20
帖子
15389

开拓者

7
发表于 2015-11-16 22:15:09 | 只看该作者
(^_^) 发表于 2015-11-16 13:50
可以同时在多个EVENT上面显示。显示太多的话总是会卡的吧。

如果在地图边缘的事件上显示的文字长了会不会跑到屏幕外···
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
37 小时
注册时间
2015-11-8
帖子
8
8
 楼主| 发表于 2015-11-17 03:59:27 | 只看该作者
chd114 发表于 2015-11-16 22:15
如果在地图边缘的事件上显示的文字长了会不会跑到屏幕外···

会和其绑定的角色一起跑到屏幕外。文字过长的问题可以用多行的方法解决,通过改变文字的高度。
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
7 小时
注册时间
2016-1-22
帖子
4
9
发表于 2017-5-23 15:18:17 | 只看该作者
请问如果想要用玩家,参数使用-1可是执行却无反映要如何解决?(其他功能皆正常)
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
37 小时
注册时间
2015-11-8
帖子
8
10
 楼主| 发表于 2017-7-8 23:01:16 | 只看该作者
amagood 发表于 2017-5-23 15:18
请问如果想要用玩家,参数使用-1可是执行却无反映要如何解决?(其他功能皆正常) ...

已经修正了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-27 23:05

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表