In the code that you sent me, you had error. Here is the updated code. The sections that I update, are commented with
//mepackage com.fox.monstermash;
import com.google.devtools.simple.runtime.components.Component;
import com.google.devtools.simple.runtime.components.HandlesEventDispatching;
import com.google.devtools.simple.runtime.components.android.Canvas;
import com.google.devtools.simple.runtime.components.android.Form;
import com.google.devtools.simple.runtime.components.android.ImageSprite;
import com.google.devtools.simple.runtime.components.android.Label;
import com.google.devtools.simple.runtime.events.EventDispatcher;
public class MonsterMash1Form extends Form implements HandlesEventDispatching
{
// Declare global variables here
Canvas gameCanvas;
ImageSprite Werewolf;
int score;
Label ScoreLbl;
void $define() {
// This sets the UI designed in the graphical editor to our Form's UI.
//me: don't need the following statement// setContentView(R.layout.main);
//me: moved ScoreLbl to top of screen score = 0;
ScoreLbl = new Label(this);
ScoreLbl.BackgroundColor(COLOR_WHITE);
ScoreLbl.Text(Integer.toString(score));
gameCanvas = new Canvas(this);
gameCanvas.BackgroundColor(COLOR_GREEN);
gameCanvas.BackgroundImage("screenmain.jpg");
gameCanvas.Height(600);
gameCanvas.Width(LENGTH_FILL_PARENT);
Werewolf = new ImageSprite(gameCanvas);
Werewolf.Picture("d.jpg"); //for my purpose
Werewolf.X(100.0d);
Werewolf.Y(100.0d);
// This method captures the initialization event of this Form, so we can do stuff when the
// screen first gets initialized.
EventDispatcher.registerEventForDelegation(this, "ScreenInitialization", "Initialize");
//me: added following. You need to register Touched event EventDispatcher.registerEventForDelegation(this, "ScreenInitialization", "Touched");
}
@Override
public boolean dispatchEvent(Component component, String id, String eventName, Object[] args) {
if (component.equals(this) && eventName.equals("Initialize")) {
screenInitialized();
return true;
}
//me: added following to capture touched event else if ( eventName.equals("Touched"))
{
if (component.equals(Werewolf))
{
doTouched((Float) args[0], (Float) args[1]);
return true;
}
return false;
}
return false;
}
//me: renamed the Touched method //me: you don't really need the 3rd argument// public void doTouched(float x, float y, boolean touchedsprite) {
public void doTouched(float x, float y) {
score = score + 1;
ScoreLbl.Text(Integer.toString(score));
}
private void screenInitialized() {
// This method is run when the screen is initialized, and reports a valid width/height.