本文介绍了从螺纹的Andr​​oid射击意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个游戏,我测试,如果英雄(位图)触摸屏边缘的线程。

I have created a thread for a game where I am testing if hero (a bitmap) touches the edges of the screen.

螺纹部分:

protected void updatePhysics() {
mBallX += elapsed * mBallDX;
        mBallY += elapsed * mBallDY;

        if((mBallX <= 0 & mBallDX < 0) | (mBallX >= mCanvasWidth - mBall.getWidth() & mBallDX > 0) ) {
            mBallDX = -mBallDX;
            updateScore(1);

        }
    }

这是从一个教程。相反updateScore(1)我想比赛已经结束,并打开GAMEOVER活动。
我用这code其他活动,但在这里它的线程显示了一个错误:

This is from a tutorial. Instead of updateScore(1) I want the game to be over and open the GameOver activity.I am using this code in other activities but here in the thread it shows an error:

Intent intent_btn_gameover = new Intent(GameThread.java, GameOver.class);
startActivity(intent_btn_gameover);

的方法startActivity(意向)是未定义的类型GameThread 的,它不喜欢GameThread.java(构造意图(GameThread,类)未定义的)。我不知道该怎么设置为意向的第一个参数。

The method startActivity(Intent) is undefined for the type GameThread and it does not like GameThread.java (The constructor Intent(GameThread, Class) is undefined). I don't know what to set as the first parameter of the Intent.

感谢

修改

private Context gContext;

Intent intent_btn_nextlevels = new Intent(gContext, GameOver.class);
startActivity(intent_btn_nextlevels);

错误:的方法startActivity(意向)是未定义的类型GameThread

推荐答案

意向的构造函数的第一个参数是一个上下文。你必须通过在正在执行的线程的活动,例如:

The first parameter of Intent's constructor is a Context. You must pass the activity where the Thread is being executed, for instance:

Intent intent_btn_gameover = new Intent(NameOfActivity.this, GameOver.class);
startActivity(intent_btn_gameover);

如果线程不活动里面,你必须通过某种方式来执行它的活动的参考。

If the thread is not inside an activity, you must pass somehow a reference to the activity that executes it.

这篇关于从螺纹的Andr​​oid射击意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:31