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

Project1

 找回密码
 注册会员
搜索
查看: 7316|回复: 15

[有事请教] 初学代码,请教一下关于blt显示的问题

[复制链接]

Lv1.梦旅人

梦石
0
星屑
102
在线时间
20 小时
注册时间
2018-3-22
帖子
16
发表于 2020-2-8 22:11:51 | 显示全部楼层 |阅读模式
10星屑
本帖最后由 郭小受 于 2020-2-8 22:12 编辑

小女最近初学插件,学习了如何制造窗口,按照他的讲解,成功在窗口显示了文字,然后突发奇想,想在窗口上显示图片。我查阅帮助,在bitmap里面看到了blt方法,但是使用了以后并没有显示图片,是我代码写错了吗?望大佬指点,小女感激不尽。
只显示了窗口:
搜狗截图20年02月08日2202_1.jpg
代码如下(我不会插入代码)
/*:
@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); //把窗口添加到窗口层

};

大佬,小女跪谢了

最佳答案

查看完整内容

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类,有些函数读取不了

点评

MV读取图片一般为异步读取,非即读即用,需要在 bitmap 读取时加一个回调方法。  发表于 2020-2-9 20:01

Lv3.寻梦者

梦石
0
星屑
2276
在线时间
576 小时
注册时间
2018-9-13
帖子
36
发表于 2020-2-8 22:11:52 | 显示全部楼层
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 23:45
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
4881
在线时间
425 小时
注册时间
2019-10-22
帖子
666
发表于 2020-2-9 08:38:30 | 显示全部楼层
小女
还挺有意思的   代码那个  编辑帖子的时候  工具栏上有一个
<>  
这样的图标

点一下就懂了

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

只懂得编辑帖子蛤  blt在mv里面的问题我就不懂了  
你看看是不是x y 的问题   是相对坐标还是绝对坐标
















回复

使用道具 举报

头像被屏蔽

Lv4.逐梦者 (禁止发言)

梦石
0
星屑
5701
在线时间
922 小时
注册时间
2013-8-29
帖子
1468
发表于 2020-2-9 11:01:28 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
102
在线时间
20 小时
注册时间
2018-3-22
帖子
16
 楼主| 发表于 2020-2-9 11:07:17 | 显示全部楼层
坏数据 发表于 2020-2-9 08:38
小女
还挺有意思的   代码那个  编辑帖子的时候  工具栏上有一个
  

好的呢,我尝试一下。
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
102
在线时间
20 小时
注册时间
2018-3-22
帖子
16
 楼主| 发表于 2020-2-9 18:46:54 | 显示全部楼层
  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也显示不出来
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3446
在线时间
1158 小时
注册时间
2016-8-9
帖子
2389

开拓者

发表于 2020-2-9 19:11:20 | 显示全部楼层
加油小闺女 不懂代码,帮不到你。。。 如果是美术方面的话可以帮你

点评

好的,小姐姐呢  发表于 2020-2-9 22:46
酸酸甜甜就④哇噢
回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2276
在线时间
576 小时
注册时间
2018-9-13
帖子
36
发表于 2020-2-9 19:51:39 | 显示全部楼层
本帖最后由 阿诺奈亚 于 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);
}
加上这一句代码即可
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
102
在线时间
20 小时
注册时间
2018-3-22
帖子
16
 楼主| 发表于 2020-2-9 22:45:39 | 显示全部楼层
阿诺奈亚 发表于 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();仍是报错,请问错在哪里?
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
102
在线时间
20 小时
注册时间
2018-3-22
帖子
16
 楼主| 发表于 2020-2-9 23:03:28 | 显示全部楼层
阿诺奈亚 发表于 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. };
复制代码

不知道错在哪里呀
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-18 20:19

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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