我在使用Libgdx绘制如何绘制简单的2D文本时遇到了很多麻烦.这是我到目前为止编写的代码:
SpriteBatch spriteBatch;
BitmapFont font;
CharSequence str = "Hello World!";
spriteBatch = new SpriteBatch();
font = new BitmapFont();
spriteBatch.begin();
font.draw(spriteBatch, str, 10, 10);
spriteBatch.end();
Run Code Online (Sandbox Code Playgroud)
代码确实绘制了Hello World字符串,但是它会弄乱我所有的其他绘图.他们在那里,只是残忍地残缺,并且所有这一切都在移动.我试着Gdx.gl11.glPushMatrix()和Gdx.gl11.glPopMatrix()周围只是陈述的每一个子集.
我已经将残缺不全的图纸缩小到了font.draw()电话,如果它被取出,一切正常(但当然没有文字).
我正在尝试将Linux中的英语词典读为一个关联数组,使用单词作为键并将预定义的字符串用作值。这样,我可以按关键字查找单词以查看它们是否存在。我还需要所有单词都小写。这很简单,但是bash语法妨碍了我。当我运行下面的代码时,出现“错误数组下标”错误。有什么想法为什么呢?
function createArrayFromEnglishDictionary(){
IFS=$'\n'
while read -d $'\n' line; do
#Read string into variable and put into lowercase.
index=`echo ${line,,}`
englishDictionaryArray[$index]="exists"
done < /usr/share/dict/words
IFS=$' \t\n'
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将使用 for 循环和 Razor 语法创建的单选按钮分组在一起。这是代码:
@for (var i = 0; i < Model.Sessions.Count(); i++)
{
@Html.HiddenFor(it => it.Sessions[i].Id)
@Html.RadioButtonFor(it => it.Sessions[i].Checkbox, "0", new {@class = "Sessions", @id = id, @name="Sessions"})
@Html.LabelFor(it => it.Sessions[i].Name, Model.Sessions[i].Name)
<span class="time-span"><em>@Model.Sessions[i].StartTime</em><em>@Model.Sessions[i].EndTime</em></span>
<br />
}
Run Code Online (Sandbox Code Playgroud)
for循环内的第三行就是问题所在。基本上名称不会改变,并且始终是“Sessions[x].Checkbox”。复选框是自定义类的属性(布尔)。我似乎无法掌握调试 Razor 内容的窍门,因此任何帮助将不胜感激,我猜这对这里的某人来说将是非常明显的。
编辑 迪米特洛夫的帖子很有帮助。下面是我使用的最终代码。我使用 @class 和 @id 属性,以便能够使用 Javascript 选择最初选择的会话(因为这是编辑,而不是创建表单)。
@for (var i = 0; i < Model.Sessions.Count(); i++)
{
@Html.HiddenFor(it => it.Sessions[i].Id)
var SId = @Model.Sessions[i].Id;
@Html.RadioButtonFor(it => it.selectedSession, Model.Sessions[i].Id, new { id = SId, @class = "Sessions" }) …Run Code Online (Sandbox Code Playgroud) 我正在尝试从本地javascript文件(本地运行的HTML/javascript程序的一部分)运行python脚本.
我一直在谷歌搜索这几个小时,并找到了很多解决方案,其中没有一个真正适合我.
这是javascript:
$.ajax({
type: "POST",
url: "test.py",
data: { param: " "}
}).done(function( o ) {
alert("OK");
});
Run Code Online (Sandbox Code Playgroud)
test.py文件与脚本/ html文件位于同一文件夹中.
这是脚本:
#!/usr/bin/python
import os
filepath = os.getcwd()
def MakeFile(file_name):
temp_path = filepath + file_name
with open(file_name, 'w') as f:
f.write('''\
def print_success():
print "sucesss"
''')
print 'Execution completed.'
MakeFile("bla.txt");
Run Code Online (Sandbox Code Playgroud)
正常运行时工作正常.
在我的Firefox控制台上,我收到"格式不正确"的错误,并且脚本没有创建文件.但是,我可以看到Firefox确实获取了脚本,因为我可以通过单击文件名在浏览器中查看它.
ajax ×1
asp.net-mvc ×1
bash ×1
graphics ×1
html ×1
html-helper ×1
http ×1
java ×1
javascript ×1
libgdx ×1
linux ×1
python ×1
razor ×1
scripting ×1
syntax ×1