我正在使用Cocos2D在Android中制作2D游戏,用Java编写.这是我的主要代码:
public void gameLoop(float dt) {
//Player Gravity
if(canExecuteMovement(0, 6)) {
guy.moveY(6);
}
//Player Movement
if(direction == 1) {
if(canExecuteMovement(-3, 0))
guy.moveX(-3);
} else if(direction == 2) {
if(canExecuteMovement(3, 0))
guy.moveX(3);
}
}
private boolean canExecuteMovement(int xChange, int yChange) {
int projectedX = guy.getBounds().left + xChange;
int projectedY = guy.getBounds().top + yChange;
Log.i("DD", "guy:" + guy.getBounds().toString());
Rect projectedBounds = new Rect(projectedX, projectedY, projectedX + guy.getWidth(), projectedY + guy.getHeight());
Log.i("DD", "guy:" + projectedBounds.toString());
for (int i = 0; i < platformCount; …Run Code Online (Sandbox Code Playgroud) 我试图在我的Visual C++项目中使用"printf",但它无法正常工作.使用Lazy Foo的教程,我在我的项目中设置了SDL,但是当我播放它时,printf什么都不做.
#include "SDL.h"
#include <stdio.h>
int main( int argc, char* args[] ) {
printf("Testing");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出如下所示:
The program '[4664] SDL Testing.exe: Native' has exited with code 0 (0x0).
Run Code Online (Sandbox Code Playgroud)
这就是它.可能有什么不对?
我在本页使用的是教程:http: //www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
它告诉我更改主要活动,除了此错误外,一切进展顺利:"导入的com.google无法解析"
突出显示的是:
import com.google.android.c2dm.C2DMessaging;
Run Code Online (Sandbox Code Playgroud)
可能是什么问题呢?它应该是我的项目名称而不是com.google吗?因为我有一个java文件,即Web.SMS.C2DMessaging.
这是有问题的PDO代码:
$db->prepare("INSERT INTO user (id, name, password, salt, email, join_date, chats)
VALUES (NULL, ?, ?, ?, ?, ?, ?)");
$db->execute(array($name, $password, $salt, $email, $joindate, ''));
Run Code Online (Sandbox Code Playgroud)
我得到致命的错误:Fatal error: Call to undefined method PDO::execute() in register.php on line 12第12行是上面的执行.可能有什么不对?该数组包含完美的字符串,使用print_r进行检查.
这是我的代码:
$string = <<<XML
<?xml version='1.0'?>
<test>
<testing>
<lol>hello</lol>
<lol>there</lol>
</testing>
</test>
XML;
$xml = simplexml_load_string($string);
echo "All of the XML:\n";
print_r $xml;
echo "\n\nJust the 'lol' array:";
print_r $xml->testing->lol;
Run Code Online (Sandbox Code Playgroud)
输出:
All of the XML:
SimpleXMLElement Object
(
[testing] => SimpleXMLElement Object
(
[lol] => Array
(
[0] => hello
[1] => there
)
)
)
Just the 'lol' array:
SimpleXMLElement Object
(
[0] => hello
)
Run Code Online (Sandbox Code Playgroud)
为什么它只输出[0]而不是整个数组?我不懂.
这是我的HttpClient请求:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.***.**/***/***_***.php");
String HTML = "";
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("from", contactName));
nameValuePairs.add(new BasicNameValuePair("msg", message));
nameValuePairs.add(new BasicNameValuePair("sent", time_sent));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HTML = "How?";
} catch (ClientProtocolException e) {} catch (IOException e) {}
Run Code Online (Sandbox Code Playgroud)
如何使用请求的源代码填充HTML字符串?
我正在尝试在后台创建一项服务,以便我可以运行一个循环,每 x 分钟请求一个页面。这是清单中我的服务:
<service android:name=".webToSMS" android:enabled="true" />
Run Code Online (Sandbox Code Playgroud)
这是我正在启动的服务(在主要活动中):
Intent intent = new Intent(this, webToSMS.class);
startService(intent);
Run Code Online (Sandbox Code Playgroud)
最后,这是我的服务类别:
public class webToSMS extends IntentService {
public webToSMS() {
super("webToSMS");
}
@Override
protected void onHandleIntent(Intent intent) {
Context context = getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在遵循 Android 的指南,这就是它告诉我要做的事情。我期待的是弹出一个祝酒词“Hello toast!” 当该服务运行时。最终,当这个工作正常时,我将放置一个循环,每 x 分钟请求一个页面。
我正在用Java创建一个2d平台游戏,出于某种原因,当玩家跳向平台时,它有时会卡住.这是问题的图像:

如你所见,我正在跳到平台的顶部,但它被卡住了.
这是我的坠落/跳跃的碰撞代码:
if (guy.getJumpState() == false) {
if (canExecuteMovement(0, 8)) {
...
onGround = false;
if (guy.getY() > this.getParent().getHeight() / 2 - 100) {
// if you are in the middle, move the platforms.
for (int i = 0; i < platformCount; i++) {
if (platform[i].getVisibility() == true) {
platform[i].setY(platform[i].getY() - 8);
}
}
} else {
// or just move the guy if not.
guy.moveY(8);
}
} else {
onGround = true;
}
} else {
if (canExecuteMovement(0, …Run Code Online (Sandbox Code Playgroud) 我在main.xml中有一个LinearLayout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/mainLayout" >
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我制作了另一个XML文件,称为item_box.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/item_bg"
android:gravity="right" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="20dp"
android:text="@string/item1"
android:textSize="30dp" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="20dp"
android:gravity="right"
android:text="@string/number1"
android:textColor="@color/number_bg"
android:textSize="30dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
基本上,我想从代码中(以编程方式)执行的操作是将几个item_box.xml添加到main.xml中。我该怎么做?
我试图遍历一个数组,但是遇到了这个问题。当我遍历此数组时:
{1,2,3,4}
Run Code Online (Sandbox Code Playgroud)
我遇到了这个问题:在开始的时候,我将得到1和4的组合,但是在中间的时候,我将得到4和1的组合。我怎样才能做到这一点,因此只能接受唯一的关系?不能像{1,4}和{4,1}这样。
我正在使用Java,对此有一些答案,但是它们使用的语言仅在其他语言中可用。
不幸的是,我无法解决这个问题。
这是遍历数组后的预期输出:
{1, 2}
{1, 3}
{1, 4}
{2, 3}
{2, 4}
{3, 4}
Run Code Online (Sandbox Code Playgroud)
但是,这是遍历数组时实际发生的事情:
{1, 1}
{1, 2}
{1, 3}
{1, 4}
{2, 1}
{2, 2}
{2, 3}
{2, 4}
{3, 1}
{3, 2}
{3, 3}
{3, 4}
{4, 1}
{4, 2}
{4, 3}
{4, 4}
Run Code Online (Sandbox Code Playgroud)
因此,这两个要求是该对必须是唯一的关系(不能有1,2和2,1),并且它们也不能相同。比较两个数字并查看它们是否相等,可以很容易地做到不一样,但是我对第一个要求有麻烦。