- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在LibGDX开发游戏,游戏中有登录界面和注册界面。 HTML 版本的游戏有剪贴板的沙盒环境,意味着:
任何从游戏中复制的东西,都不能粘贴到游戏外&从外部复制的任何内容都不能粘贴到游戏的文本字段中
我只是想复制文本,有什么方法可以将沙箱剪贴板与系统剪贴板合并吗?
我想要的是:当用户在文本字段中按 Ctr+V 时,它应该从文本字段中的系统剪贴板中抓取文本 & 当用户按 Ctr+C 时:它应该将文本放入系统剪贴板
我正在尝试:
public class HtmlLauncher extends GwtApplication {
private static HtmlLauncher instance;
public void onModuleLoad() {
instance = this;
setLoadingListener(new LoadingListener() {
@Override
public void beforeSetup() {}
@Override
public void afterSetup() {
setupCopyListener();
}
});
}
native void setupCopyListener()
/*-{
var htmlLauncher_onCopy = $entry(@com.myapp.game.client.HtmlLauncher::addToClipboard());
$wnd.addEventListener("copy", htmlLauncher_onCopy, false);
}-*/
;
public static void addToClipboard() {
instance.copy();
}
private void copy() {
//getClipboard().setContents("");
consoleLog("copied");
}
}
谁能帮我:
编辑(5 月 2 日,尝试了 JustACluelessNewbie 的建议):继承剪贴板:
public class MyClipboard implements com.badlogic.gdx.utils.Clipboard{
private String cachedContent = "";
public MyClipboard() {
createTextArea();
}
@Override
public String getContents() {
String contents = getClipBoard();
return (contents == null) ? cachedContent : cachedContent = contents;
}
@Override
public void setContents(String content) {
cachedContent = content == null ? "" : content;
setClipBoard(content);
}
public static native void createTextArea() /*-{
var textArea = document.createElement('textarea');
textArea.style.position='fixed';
textArea.style.top=0;
textArea.style.left=0;
textArea.style.width='2em';
textArea.style.height='2em';
textArea.style.padding=0;
textArea.style.border='none';
textArea.style.outline='none';
textArea.style.boxShadow='none';
textArea.style.background='transparent';
$wnd._copy=textArea;
}-*/;
public static native String getClipBoard() /*-{
if(window.clipboardData){
return window.clipboardData.getData('Text');
}else {
document.body.appendChild($wnd._copy);
try{
$wnd._copy.value = "";
$wnd._copy.focus();
$wnd._copy.select();
console.log(document.queryCommandSupported("paste")); //prints true
var result = document.execCommand('paste');
console.log(result); //prints false
return $wnd._copy.value;
}catch(err){
return null;
}finally{
document.body.removeChild($wnd._copy);
}
}
}-*/;
public static native void setClipBoard(String content) /*-{
document.body.appendChild($wnd._copy);
try{
$wnd._copy.value = content;
$wnd._copy.select();
var result = document.execCommand('copy');
console.log("after exec copy "+result)
}catch(err){
console.log("error:"+err);
}finally{
document.body.removeChild($wnd._copy);
}
}-*/ ;
}
最佳答案
最后我让它工作了,如果有人还在寻找这个,我会发布我的答案
package myPackage;
public class HtmlLauncher extends GwtApplication {
private static HtmlLauncher instance;
@Override
public void onModuleLoad() {
super.onModuleLoad();
instance = this;
setLoadingListener(new LoadingListener() {
@Override
public void beforeSetup() {
}
@Override
public void afterSetup() {
setupCopyListener();
}
});
}
native void setupCopyListener() /*-{
var self = this;
var isSafari = navigator.appVersion.search('Safari') != -1 && navigator.appVersion.search('Chrome') == -1 && navigator.appVersion.search('CrMo') == -1 && navigator.appVersion.search('CriOS') == -1;
var isIe = (navigator.userAgent.toLowerCase().indexOf("msie") != -1 || navigator.userAgent.toLowerCase().indexOf("trident") != -1);
var ieClipboardDiv = $doc.getElementById('#ie-clipboard-contenteditable');
var hiddenInput = $doc.getElementById("hidden-input");
var getTextToCopy = $entry(function(){
return self.@myPackage.HtmlLauncher::copy()();
});
var pasteText = $entry(function(text){
self.@myPackage.HtmlLauncher::paste(Ljava/lang/String;)(text);
});
var focusHiddenArea = function() {
// In order to ensure that the browser will fire clipboard events, we always need to have something selected
hiddenInput.value = '';
hiddenInput.focus();
hiddenInput.select();
};
// Focuses an element to be ready for copy/paste (used exclusively for IE)
var focusIeClipboardDiv = function() {
ieClipboardDiv.focus();
var range = document.createRange();
range.selectNodeContents((ieClipboardDiv.get(0)));
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
};
// For IE, we can get/set Text or URL just as we normally would,
// but to get HTML, we need to let the browser perform the copy or paste
// in a contenteditable div.
var ieClipboardEvent = function(clipboardEvent) {
var clipboardData = window.clipboardData;
if (clipboardEvent == 'cut' || clipboardEvent == 'copy') {
clipboardData.setData('Text', getTextToCopy());
focusIeClipboardDiv();
setTimeout(function() {
focusHiddenArea();
ieClipboardDiv.empty();
}, 0);
}
if (clipboardEvent == 'paste') {
var clipboardText = clipboardData.getData('Text');
ieClipboardDiv.empty();
setTimeout(function() {
pasteText(clipboardText);
ieClipboardDiv.empty();
focusHiddenArea();
}, 0);
}
};
// For every broswer except IE, we can easily get and set data on the clipboard
var standardClipboardEvent = function(clipboardEvent, event) {
var clipboardData = event.clipboardData;
if (clipboardEvent == 'cut' || clipboardEvent == 'copy') {
clipboardData.setData('text/plain', getTextToCopy());
}
if (clipboardEvent == 'paste') {
pasteText(clipboardData.getData('text/plain'));
}
};
['cut', 'copy', 'paste'].forEach(function (event) {
$doc.addEventListener(event,function (e) {
console.log(event);
if(isIe) {
ieClipboardEvent(event);
} else {
standardClipboardEvent(event, e);
focusHiddenArea();
e.preventDefault();
}
})
})
}-*/;
private void paste(String text) {
consoleLog("in paste"+text);
String oldText = getClipboard().getContents();
if(!oldText.equals(text)){
getClipboard().setContents(text);
Actor focusedActor = ((BasicScreen)((Game)getApplicationListener()).getScreen()).getStage().getKeyboardFocus();
if (focusedActor != null && focusedActor instanceof TextField) {
if(!oldText.equals("")) {
String textFieldText = ((TextField)focusedActor).getText();
textFieldText = textFieldText.substring(0,textFieldText.lastIndexOf(oldText));
((TextField)focusedActor).setText(textFieldText);
}
((TextField)focusedActor).appendText(text);
}
}
}
private String copy() {
return getClipboard().getContents();
}
}
我为所有屏幕创建了一个父类(super class),这个问题所需的最小结构:
public abstract class BasicScreen extends ScreenAdapter implements InputProcessor {
protected MyStage stage;
public BasicScreen () {
stage = new MyStage();
}
public MyStage getStage () {
return stage;
}
}
你需要在同一阶段添加文本框
在 index.html 中,添加这两行:
<div id="ie-clipboard-contenteditable" class="hidden" contenteditable="true"></div>
<input id="hidden-input" class="hidden" type="text" value=""/>
在css中,添加:
.hidden {
position: fixed;
bottom: 0;
left: 0;
width: 10px;
height: 10px;
display: block;
font-size: 1;
z-index: -1;
color: transparent;
background: transparent;
overflow: hidden;
border: none;
padding: 0;
resize: none;
outline: none;
-webkit-user-select: text;
user-select: text;
/* Because for user-select:none, Safari won't allow input */
}
它在 chrome 中完美运行,没有在其他浏览器上测试。
我引用了: https://www.lucidchart.com/techblog/2014/12/02/definitive-guide-copying-pasting-javascript/
关于javascript - LibGDX html 剪贴板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36941236/
libGDX Array类的javadoc说:一个可调整大小,有序或无序的对象数组。如果是无序的,则此类在删除元素时避免了内存复制(最后一个元素移动到删除的元素的位置)。 去除元素的改进是此类的唯一优
声音API似乎缺少指示声音播放完毕的功能。还有其他方法可以确定声音是否完成了吗? 最佳答案 据我所知,OpenAL和Android的底层声音后端甚至都没有内部跟踪信息,尽管Music API具有的is
我在应用程序启动时执行了此代码 val resolver = InternalFileHandleResolver() asset.setLoader(FreeTypeFontGenerator::c
我想要获取点 1 和点 2 之间相对于中心点的角度。如何使用 Vector2 执行此操作? Vector2 center = new Vector2((float)Gdx.graphics.getWi
我正在尝试渲染平滑的可缩放位图字体。检查后question answers之一提到使用距离场字体。 我正在按照 LibGDX wiki article 中提到的方式进行操作关于距离场字体。但是我无法让
我已经寻找答案大约 2 个小时了,但还没有找到我想要的答案。我的问题是,是否可以以及如何绘制圆形纹理,以便在圆形之外,纹理将是透明的,这甚至可能吗? 提前致谢!到目前为止,该网站提供了很大的帮助! 最
我用 libgdx 开始了一个项目,我有一个 GameStateManager 用于我的 GameStates 菜单和播放。 如果我运行该项目,它会显示菜单,然后我可以单击一个按钮来打开 Play G
我正在使用 libgdx。我需要缩放和定位文本。假设我想绘制 30 像素高的 X,并且我希望它位于屏幕中间。我想在不同的位置和不同的比例画更多的人。 有什么办法可以实现吗?我在任何地方都找不到解决方案
我正在 Libgdx 中制作纹理打包机,其中如果我使用打包机 2,048 * 2,048 的大小,只制作一个大小为 3.14 Mb 的打包机图像,如果我使用打包机的大小 1,024 * 1,024 那
我在每一帧中都进行了大量的三角函数计算。 Java 的 Math 函数是否比 Libgdx 的 MathUtils 更快? 或者我可以使用任何其他比这两个都更快的库吗? 最佳答案 com.badlog
你好,对于 LibGDX 来说有点新,目前在 pc 上的全屏模式存在问题,我想要做的是每当有人按下一个键时将我的游戏设置为全屏,而当我在 main 方法中输入一些东西时,这不会做任何事情桌面启动器.j
几年前我开始开发我的游戏,中间有很大的停顿。那时没有 gradle,只有简单的 java 安装应用程序。如何找到所使用的 LibGDX 版本? 最佳答案 干得好: Gdx.app.log("Gdx v
我正在尝试使用 libGDX 实现一个简单的动画,但目前我遇到了一件事。假设我有一堆 Sprite 需要一些时间才能完成。例如,大约 30 个 Sprite 像这个链接:https://github.
如何在游戏过程中更改窗口标题?我找不到任何方法。例如,我想在标题栏中显示我得了多少分。 最佳答案 尝试这个 : Gdx.graphics.setTitle(""+yourScore); 祝你好运 !
我正在使用 LibGdx 中的声音接口(interface)来播放 mp3 音频文件。 And when choose to loop playing the sound more than one
所以我在 LibGDX 中制作游戏,我使用 AssetManager 加载我的所有 Assets 。 我只是不确定哪种是正确的使用方法。 目前我正在第一个屏幕之前加载所有游戏 Assets 。 然后我
我一直在寻找来自 libgdx SVN 的 skinpacker,但没有成功。 然后我知道它不再存在。所以,问题是如何创建一个 skin.json 文件以在我的 libgdx 项目中使用。你知道有什么
我正在制作连点类型的游戏,我必须在屏幕上触摸的位置画一条线,所以我使用矢量来存储我触摸的各个点。 我用过 if(Gdx.input.isTouched()) { touchpos.set(Gd
我查看了测试项目中的默认皮肤文件。 我不明白为什么 uiskin.png 里面有字体图片。 uiskin.atlas 文件还包含拆分字段,我不明白为什么需要它以及如何使用它。 我在哪里可以找到所有事情
我到处搜索,但没有引用。 我想用this着色器从 shadertoy 到我的 libgdx 项目,所以我尝试首先从以下位置导入简单着色器:https://www.shadertoy.com/view/
我是一名优秀的程序员,十分优秀!