- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我看过很多关于 LibGDX 和屏幕/凸轮坐标的主题,还有一些关于窗口大小调整的主题,但我就是找不到解决以下问题的方法。
在这个阶段制作基本舞台和基本 Actor 时,比如说windowsize 480x320,一切都OK。我可以点击我的 Actor ,它会响应。但是当我调整我的窗口大小时,比如 600x320,一切看起来正确,但我的 clicklistener 不再工作了。此外,舞台坐标被移动或弄乱了。
我使用以下代码:
stage.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
//determine if actor was hit
System.out.println(stage.hit(x, y, true));
return true;
}
});
另外,我正在调整我的舞台摄像机视口(viewport)以对应窗口:
stage.getCamera().viewportWidth = Gdx.graphics.getWidth();
stage.getCamera().viewportHeight = Gdx.graphics.getHeight();
因此,在调整大小时,我在屏幕上获得了所需的效果,但我的听众没有响应 - Actor 似乎“偏移”了我点击的位置。我究竟做错了什么?我应该移动我的 Actor 或我的摄像头,还是根据调整大小缩放我的摄像头?有人可以向我解释一下吗?
提前非常感谢!
编辑:下面是我类(class)的完整代码。
public class HelpMePlease implements ApplicationListener{
// A standard simple Actor Class
class CustomActor extends Actor {
Texture texture = new Texture(Gdx.files.internal("data/testTex2.png"));
TextureRegion pixelTexture = new TextureRegion(texture, 0, 0, 1, 1);
Sprite sprite = new Sprite(texture);
public CustomActor() {
setWidth(128);
setHeight(128);
setBounds(getX(), getY(), getWidth(), getHeight());
}
@Override
public void draw(SpriteBatch batch, float parentAlpha) {
batch.draw(sprite, getX(), getY(), 0f, 0f, getWidth(), getHeight(), getScaleX(), getScaleY(), getRotation());
}
}
public Stage stage;
public CustomActor actor;
@Override
public void create() {
stage = new Stage(480,320,true);
actor = new CustomActor();
stage.addListener(new InputListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
//determine if actor was hit
System.out.println(stage.hit(x, y, true));
return true;
}
});
Gdx.input.setInputProcessor(stage);
stage.addActor(actor);
}
@Override
public void resize(int width, int height) {
//resize cam viewport
stage.getCamera().viewportWidth = Gdx.graphics.getWidth();
stage.getCamera().viewportHeight = Gdx.graphics.getHeight();
}
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
stage.getCamera().update(); //just to be sure, I don't know if this is necessary
stage.act();
stage.draw();
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override
public void dispose() {
// TODO Auto-generated method stub
}
}
最佳答案
您可以使用最新的每晚更改调整大小。
@Override
public void resize(int width, int height) {
stage.getViewport().update(width, height, true);
}
最后一个参数“true”将使相机在屏幕中居中
关于resize - LibGDX 舞台坐标在窗口调整大小时发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23373601/
我有一个 View ,不是窗口的大小,也不是窗口本身,当它调整大小时,我想比较调整大小的开始值和结束值。然而,JQ-UI 的 resize ui 对象只包含以前的状态,而不是原始状态,所以它只是按像素
我有一个简单的可调整大小 jQueryUI 元素。 element.resizable({ start: function(event, ui) {...}, resize: func
我有几个嵌套的可调整大小的 div,需要调整大小以适应子大小。一切正常,直到我尝试调整其中一个外部 div 的大小(垂直)然后它卡住了。 这是一个 fiddle . $(function () { $
CNN 模型将大小为 (112x112) 的图像张量作为输入,并给出 (1x512) 大小的张量作为输出。 使用 Opencv 函数 cv2.resize() 或在 pytorch 中使用 Trans
经过大量搜索和研究,我找不到任何答案。 我将非常感谢可以帮助我的人。 在 SWT Java 中, 我希望我的窗口不能调整大小,所以我这样定义它: shell = new Shell(SWT.CLOSE
$(window).bind('resize') 和 $(window).resize() 有什么区别? 我看到bind嵌套在resize之上。它有什么影响?请参阅下面的代码。 我知道.resize(
使用 Vaadin 14.1.19 和 Vaadin“我的入门元素”元素,我尝试创建一个多行 TextArea。乍一看它工作正常,但是当调整 TextArea 大小时,它不会调整行数。这是我的代码:
我有一个使用 Ext.js 的侧面板。在浏览器调整大小之前,侧面板中的其中一个面板很好。浏览器调整大小时,它会切断面板的组件。 如何在浏览器调整大小时调整面板大小? { xtype:
我需要一种可靠的方法来检测 $(window).on('resize') 是否已由用户交互或 jQuery .trigger 调用触发。 我尝试了以下方法,但我似乎没有在函数调用中取回参数: $(wi
我有一个可调整大小的 div,现在我想在调整此框大小/用户完成调整大小时编辑 cookie。 (我有cookie插件) 我该怎么做? PS:我有多个具有不同 id 的 .div。 我的代码不起作用
这些游标类型有什么区别?我在 Chrome/windows 中看到了所有 3 个相同的光标 .e-resize {cursor: e-resize;} .ew-resize {cursor: ew-r
我使用了一个指令,它调用了一个返回一些值的方法,该方法运行良好。但我的问题是它反复调用它,而我想要的是它应该只在调整大小完成时调用该方法。我采取了这种代码形式 https://codepen.io/f
为了检查这种意外行为,我只是将 TextArea 直接放入 PrimaryStage 包含的 Scene 中:在应用程序启动时,TextArea 完全适合窗口(正如预期的那样)。 但是如果我移动窗口的
我在我的项目中使用 jquery-ui-resizable 插件。 默认情况下,当您制作 DOM 对象 jquery-ui-resizable 时,可调整大小的句柄将出现在右下角,我需要在左下角显示可
我正在 MonoTouch 中使用来自 AV Foundation 的 AVPlayer API 开发视频播放器(但 objective-c 中的解决方案也可能不错)。我正在尝试实现全屏模式。 为了显
我只是想让我的响应式 div 示例像这里一样工作 http://voormedia.com/blog/2012/11/responsive-background-images-with-fixed-o
我正在制作一个包含一个 .html 文件和一个 .css 文件的页面。 我已将 bootstrap 4 CDN 合并到我的 html 头中。 网格在中等屏幕尺寸下显示正确,但在我的手机上查看时它没有调
所以我有一个最近出现的非常具体的问题(就在我们计划的明天发布日之前),我不确定如何解决它。我用我有限的前端技能构建了我们的 HTML 模板网站,我们对此非常满意。但是,我似乎无法解决这个问题。 问题:
据我了解,有类instance.method(parameters)=class.method(instance,parameters),所以只是记法上的区别。但是 np.resize(ndarray
window.resize() 和 window.on('resize' , function()) 有什么区别在 jquery 中? 最佳答案 来自 jQuery页面.resize(): This
我是一名优秀的程序员,十分优秀!