当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to draw part of an image in custom context menu?

问题描述:

So I made custom context menu which looks like this

In html I have only unordered list with high z-index:

<ul id="custom-menu">

</ul>

And in Javascript I loop through mobs and items and add them as list items like that.

options += '<li class="option"> ${mobs[i].name} </li>'

But I can not figure out how to also make a minature of items on the left side of entries. These images are saved in tileset and I want to draw particular rectangles based on what was clicked (for example for feather I want to draw part of items.png which start at 64px from left 64px from right and has 32px width and height). So in javascript i just go drawImage(img,64,64,32,32);

What is the easiest way to draw minatures of clicked things on the custom context menu?

分享给朋友:
您可能感兴趣的文章:
随机阅读: