我正在 libgdx 游戏中制作成就屏幕。我想将 scrollPane 中的表格与顶部对齐,现在它垂直和水平居中,我不知道为什么。.top()
当我尝试创建新行时使用方法不起作用。
stage = new Stage();
Gdx.input.setInputProcessor(stage);
outerTable = new Table();
innerTable = new Table();
innerTable.setFillParent(true);
for(int i=0;i<score_bound; i++){
if(i<score_state){
innerTable.row().width(achie_width).height(achie_height).top();
innerTable.add(new Image(ltm.assets.score_textures[i]));
}else{
innerTable.row().width(achie_width).height(achie_height).top();
innerTable.stack(new Image(ltm.assets.score_textures[i]),new Image(ltm.assets.kurtyna));
}
}
for(int i=0;i<letin_bound; i++){
if(i<letin_state){
innerTable.row().width(achie_width).height(achie_height).top();
innerTable.add(new Image(ltm.assets.letin_textures[i]));
}else{
innerTable.row().width(achie_width).height(achie_height).top();
innerTable.stack(new Image(ltm.assets.letin_textures[i]),new Image(ltm.assets.kurtyna));
}
}
scrollPane = new ScrollPane(innerTable);
outerTable.setPosition(0, 0);
outerTable.setSize(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());
outerTable.debug();
outerTable.add(scrollPane).fill().expand();
stage.addActor(outerTable);
Run Code Online (Sandbox Code Playgroud) 我想在游戏中使用流畅的文字.我发现解决方案是像素着色器,所以我做的每件事都像github文档中描述的那样 .我有font.vert和font.frag文件,在本文档中说我应该使用const float smoothing = 0.25f /(spread*scale).我的字体是48像素大小因此我使用0.25f/48.0f但我的字体是stil锐利和破烂.我究竟做错了什么 ?
这是font.frag:
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_texture;
varying vec4 v_color;
varying vec2 v_texCoord;
const float smoothing = 0.25/48.0 ;
void main() {
float distance = texture2D(u_texture, v_texCoord).a;
float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
gl_FragColor = vec4(v_color.rgb, alpha);
}
Run Code Online (Sandbox Code Playgroud)
我也为我的字体使用线性过滤器:
arial_white_48.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
Run Code Online (Sandbox Code Playgroud)
文本"你的分数"是用像素着色器和线性滤镜写的
文本"高分"只能使用线性滤波器进行写入,但它是尖锐的
我在http://en.cppreference.com/w/cpp/language/partial_specialization上找到了这个例子
template <int I, int J, int K> struct B {};
template <int I> struct B<I, I*2, 2> {}; // OK: first parameter is deducible
Run Code Online (Sandbox Code Playgroud)
使用-std = c ++ 11和-std = c ++ 14编译时出错
怎么编译呢?或者可能是错误的例子?
error: template argument ‘(I * 2)’ involves template parameter(s)
template <int I> struct B<I, I*2, 2> {}; // OK: first parameter is deducible
Run Code Online (Sandbox Code Playgroud) 我正在做一个简单的libgdx游戏.当我使用sound.play()在android 4.0上编辑这个bug apear 时,我有滞后(游戏停止0.5秒) 2.3一切正常.
方法.我用这段代码播放声音:
if(CollisionDetector.detect(touchArea, hoodie.getTouchArea())){
GameScreen.totalScore++;
setPosition();
System.out.println("played");
Assets.eatSound.play();
}
Run Code Online (Sandbox Code Playgroud)
我用这种方法加载声音:
static long waitForLoadCompleted(Sound sound,float volume) {
long id;
while ((id = sound.play(volume)) == -1) {
long t = TimeUtils.nanoTime();
while (TimeUtils.nanoTime() - t < 100000000);
}
return id;
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?或者我该怎么做才能解决这个滞后问题?
编辑:
我刚刚尝试用sound.play()做线程,但它也不起作用:
new Thread(new Runnable() {
@Override
public void run() {
// do something important here, asynchronously to the rendering thread
// post a Runnable to the rendering thread that processes the result
Gdx.app.postRunnable(new …
Run Code Online (Sandbox Code Playgroud) 我想创建模板递归,让我通过使用make_sequence <4>创建序列<0,1,2,3,4>,但似乎递归不会在特化时停止,只是继续运行直到stackoverfolw.
#include <iostream>
#include <cstdio>
template <std::size_t... Indices>
struct sequence {};
template<std:: size_t N, std::size_t ... Indices>
struct make_sequenceAppend{
using type = typename make_sequenceAppend<N-1, N, Indices...>::type;
};
template<std:: size_t , std::size_t ... Indices>
struct make_sequenceAppend<0ul, Indices...>{
using type = typename sequence< Indices...>::type;
};
template <std::size_t N>
struct make_sequence{
using type = typename make_sequenceAppend<N-1, N>::type;
};
int main()
{
make_sequence<4>();
return 0;
}
Run Code Online (Sandbox Code Playgroud) Text
在以下情况下,当屏幕不适合时,有没有办法自动断行文本?
Row(
children: [
SizedBox(width: 40, height:40),
Container(
child: Text("Long text without explicit line breaks, but still long.")
)
SizedBox(width: 40, height:40)
]
)
Run Code Online (Sandbox Code Playgroud) 鉴于此代码:
class Dog{
String name = "Dog";
int age = 2;
}
final list = [Dog(), Dog()]
final dogNameToAge = Map.fromIterable(
list, key: (value)=> value.name, value: (value)=>value.age)
Run Code Online (Sandbox Code Playgroud)
“key”lambda 的类型是否String Function(dynamic)?
有一种使用类似以下内容的方法:String Function(Dog)?
这样它会更加类型安全?
我想使用struct作为fucntion的返回值,但它不起作用,我不知道为什么.运行此程序时程序崩溃.我得到了RTE.这段代码有什么问题:
#include <iostream>
using namespace std;
struct Tablica{
int T[201][201];
};
Tablica test(Tablica A, int m){
if(m==1)return A;
if(m%2 ==1){
return test(A, m-1);
}else{
cout <<" #1 m " << m<<endl;
Tablica B = test(A,m/2);
cout <<" #2 m " << m<<endl;
return B;
}
}
int main(){
Tablica T;
test(T,10);
}
Run Code Online (Sandbox Code Playgroud)