Project1

标题: 初学代码,请教一下关于blt显示的问题 [打印本页]

作者: 郭小受    时间: 2020-2-8 22:11
标题: 初学代码,请教一下关于blt显示的问题
本帖最后由 郭小受 于 2020-2-8 22:12 编辑

小女最近初学插件,学习了如何制造窗口,按照他的讲解,成功在窗口显示了文字,然后突发奇想,想在窗口上显示图片。我查阅帮助,在bitmap里面看到了blt方法,但是使用了以后并没有显示图片,是我代码写错了吗?望大佬指点,小女感激不尽。
只显示了窗口:

代码如下(我不会插入代码)
/*:
@author guo
@plugindesc 窗口示例
@help


*/
function Window_MapStatus() {
    this.initialize.apply(this, arguments)
}
Window_MapStatus.prototype = Object.create(Window_Base.prototype);
Window_MapStatus.prototype.initialize = function (x, y, width, height) {
    Window_Base.prototype.initialize.call(this, x, y, width, height);
        this._timeBitmap = ImageManager.loadHitMouse("time_roller");
        this.refresh();
}

Window_Base.prototype.drawButton = function(faceName, x, y, width, height) {    
    var bitmap = ImageManager.loadSystem(faceName);    
    this.contents.blt(bitmap, 0, 0, width, height, x, y);
};

ImageManager.loadHitMouse = function(filename, hue) {//
        return this.loadBitmap('img/HitMouse/', filename, hue, true);
};
Window_MapStatus.prototype.adjustSprite = function(sprite) {
        sprite.scale.x = this._scaleX * 0.85;
        sprite.scale.y = this._scaleY * 0.85;
    sprite.anchor.x = 0.5;
    sprite.anchor.y = 0.5;
        this.addChild(sprite);
};


Window_MapStatus.prototype.refresh = function () {
        //这里的图片显示不出来
        this._dizzyBitmap = ImageManager.loadHitMouse("star");
       
        this.contents.blt(this._dizzyBitmap, 0, 0, 120, 70, 5, 30,120,70);
}
Scene_Map.prototype.createDisplayObjects = function () {
    //创建精灵组
    this.createSpriteset();
    //创建地图名称窗口
    this.createMapNameWindow();
    //创建窗口层
    this.createWindowLayer();
    //创建所有窗口
    this.createAllWindows();

    //创建一个显示角色状态的窗口
    this.createStatusWindow();



};

//创建一个显示名字的窗口
Scene_Map.prototype.createStatusWindow = function () {
    this._StatusWindow = new Window_MapStatus(200, 200, 410, 216);
    this.addWindow(this._StatusWindow); //把窗口添加到窗口层

};

大佬,小女跪谢了
作者: 阿诺奈亚    时间: 2020-2-8 22:11
Scene_Map.prototype.createStatusWindow = function () {
    this._StatusWindow = new Window_MapStatus(0, 0, 410, 216);
    this.addWindow(this._StatusWindow); //把窗口添加到窗口层
        SceneManager.push(Window_MapStatus);
};
你在这句函数里面注释掉SceneManager.push(Window_MapStatus);这句代码,窗口类不是scene类,有些函数读取不了
作者: 坏数据    时间: 2020-2-9 08:38
小女
还挺有意思的   代码那个  编辑帖子的时候  工具栏上有一个
<>  
这样的图标

点一下就懂了

一般来说 还要折叠一下  折叠的图标是一个对话气泡  底下的提示文字是 Toggle  

只懂得编辑帖子蛤  blt在mv里面的问题我就不懂了  
你看看是不是x y 的问题   是相对坐标还是绝对坐标
作者: chanszeman1018    时间: 2020-2-9 11:01
提示: 作者被禁止或删除 内容自动屏蔽
作者: 郭小受    时间: 2020-2-9 11:07
坏数据 发表于 2020-2-9 08:38
小女
还挺有意思的   代码那个  编辑帖子的时候  工具栏上有一个
  

好的呢,我尝试一下。
作者: 郭小受    时间: 2020-2-9 18:46
  1. var create_canvas = function(){
  2.     var theCanvas = document.createElement("canvas");
  3.     if(!theCanvas){
  4.         document.write("no support canvas");
  5.         return ;
  6.     }
  7.     //mv的是816*624
  8.     theCanvas.width = 816;
  9.     theCanvas.height = 624;
  10.     theCanvas.style.position = "absolute";
  11.     theCanvas.style.margin = "auto";
  12.     theCanvas.style.top = 0 + "px";
  13.     theCanvas.style.left = 0 + "px";
  14.     theCanvas.style.right = 0 + "px";
  15.     theCanvas.style.bottom = 0 + "px";
  16.     theCanvas.style.zIndex = 20;
  17.     theCanvas.id = "theCanvas";
  18.     document.body.appendChild(theCanvas);

  19.     return theCanvas;
  20. };
  21. Window_MapStatus.prototype.refresh = function () {
  22.         //这里的图片显示不出来
  23.         //this._dizzyBitmap = ImageManager.loadHitMouse("star");
  24.        
  25.         //this.contents.blt(this._dizzyBitmap, 0, 0, 120, 70, 5, 30,120,70);
  26.         if(!document.getElementById("theCanvas")){
  27.         create_canvas();
  28.     }else{
  29.        var theCanvas = document.getElementById("theCanvas");
  30.         theCanvas.style.zIndex = 20;
  31.     }

  32.         var theCanvas = document.getElementById("theCanvas");
  33.         var context = theCanvas.getContext("2d");
  34.         var backGround = new Image();
  35.         backGround.src = "img/HitMouse/main.png";
  36.         //backGround.addEventListener("load", load_done, false);
  37.         context.drawImage(backGround, 100, 100);
  38. }
复制代码

我用drawimage也显示不出来
作者: 白嫩白嫩的    时间: 2020-2-9 19:11
加油小闺女 不懂代码,帮不到你。。。 如果是美术方面的话可以帮你
作者: 阿诺奈亚    时间: 2020-2-9 19:51
本帖最后由 阿诺奈亚 于 2020-2-10 13:44 编辑

Window_MapStatus.prototype.update = function () {
        this._dizzyBitmap = ImageManager.loadHitMouse("star");
        this.contents.blt(this._dizzyBitmap, 0, 0, 120, 70, 5, 30,120,70);
}
加上这一句代码即可
作者: 郭小受    时间: 2020-2-9 22:45
阿诺奈亚 发表于 2020-2-9 19:51
Window_MapStatus.prototype.update = function () {
        this._dizzyBitmap = ImageManager.loadHitMo ...

大佬,我加入了以后报错了:undefined is not a function
只要我加了Window_MapStatus.prototype.update = function () {这句就会报错。
  1. Window_MapStatus.prototype.initialize = function (x, y, width, height) {
  2.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  3.         this.refresh();
  4.         this.update();
  5. }
复制代码

我尝试在initialize里面加了一句this.update();仍是报错,请问错在哪里?
作者: 郭小受    时间: 2020-2-9 23:03
阿诺奈亚 发表于 2020-2-9 19:51
Window_MapStatus.prototype.update = function () {
        this._dizzyBitmap = ImageManager.loadHitMo ...

我在update里面加了一句
  1. Window_MapStatus.prototype.update = function () {
  2.         Window_Base.prototype.update.call(this);        
  3. }
复制代码
仍然报错
我精简了一下代码
  1. /*:
  2. @author ttt
  3. @plugindesc 窗口示例
  4. @help


  5. */
  6. function Window_MapStatus() {
  7.     this.initialize.apply(this, arguments)
  8. }
  9. Window_MapStatus.prototype = Object.create(Window_Base.prototype);



  10. Window_MapStatus.prototype.initialize = function (x, y, width, height) {
  11.     Window_Base.prototype.initialize.call(this, x, y, width, height);
  12.         this.refresh();
  13.         this.update();
  14. }

  15. ImageManager.loadHitMouse = function(filename, hue) {//        
  16.         return this.loadBitmap('img/HitMouse/', filename, hue, true);
  17. };

  18. Window_MapStatus.prototype.refresh = function () {
  19.         //this.drawText($gameParty.members()[0]._name, 0, 0, this.Width);
  20.         //这里的图片显示不出来        
  21.         //this._dizzyBitmap = ImageManager.loadHitMouse("star");                 
  22.         //this.contents.blt(this._dizzyBitmap, 0, 0, 120, 70, 5, 30,120,70);
  23. }

  24. Window_MapStatus.prototype.update = function () {
  25.         Window_Base.prototype.update.call(this);        
  26.         //this._dizzyBitmap = ImageManager.loadHitMouse("star");         
  27.         //this.contents.blt(this._dizzyBitmap, 0, 0, 120, 70, 5, 30,120,70);
  28. }
  29. Scene_Map.prototype.createDisplayObjects = function () {
  30.     //创建精灵组
  31.     this.createSpriteset();
  32.     //创建地图名称窗口
  33.     this.createMapNameWindow();
  34.     //创建窗口层
  35.     this.createWindowLayer();
  36.     //创建所有窗口
  37.     this.createAllWindows();

  38.     //创建一个显示角色状态的窗口
  39.     this.createStatusWindow();



  40. };

  41. //创建一个显示名字的窗口
  42. Scene_Map.prototype.createStatusWindow = function () {
  43.     this._StatusWindow = new Window_MapStatus(0, 0, 410, 216);
  44.     this.addWindow(this._StatusWindow); //把窗口添加到窗口层
  45.         SceneManager.push(Window_MapStatus);
  46. };
复制代码

不知道错在哪里呀
作者: 阿诺奈亚    时间: 2020-2-9 23:54
郭小受 发表于 2020-2-9 23:03
我在update里面加了一句仍然报错
我精简了一下代码

Scene_Map.prototype.createStatusWindow = function () {
    this._StatusWindow = new Window_MapStatus(0, 0, 410, 216);
    this.addWindow(this._StatusWindow); //把窗口添加到窗口层
        SceneManager.push(Window_MapStatus);
};
这个函数注释或删掉SceneManager.push(Window_MapStatus);这句代码,窗口类不是场景类,有些函数窗口类调用不了。
作者: yang1zhi    时间: 2020-2-10 11:19
显示图片,RM比较麻烦。不是即时实现。
也就是,你
bitmap = ImageManager.loadFace
刚定义了bitmap
之后马上就blt
这样大多数情况下,是还没读取完图片的,是显示不了的。
已经读取过的在缓存里有,可以显示出来。

最好是用上这个
var bitmap = ImageManager.loadFace(actor.faceName());
这里定义bitmap
  bitmap.addLoadListener(function() {
这里的bitmap就是上面那个定义的bitmap。你定义的是yyy那就写yyy
    this.contents.blt(bitmap, sx, sy, 144, 144, dx, dy);
大括号里面写的就是bitmap读取到图片后要执行的内容。这里是blt,你也可以是别的。
    }.bind(this));
小括号里面是要传给这个小函数的内容。this是必须的。后面也可以加。
比如  this,x,y
这样就把x,y传给了这个小函数
可以在上面的(function() 小括号里写上(function(x,y) 就可以把xy在这个小函数里面使用的。
这在for里很有用




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