Hmmm... nothing stands out as wrong. What exactly is the problem?
Some things I notice:

Originally Posted by
ellyna
Code:
for (int i = 0; i <= contaTocco; i++) {
That looks like it should be "<", not "<=" (which would also mean you can remove the enclosing "if").

Originally Posted by
ellyna
Code:
graphics.drawRegion(new_bg, maskX[i], maskY[i], 50, 50, Sprite.TRANS_NONE, maskX[i], maskY[i], Graphics.TOP | Graphics.LEFT);
Watch out that the x,y,w,h don't cause you to draw off the edge of the image, or you'll get an IllegalArgumentException.
Oh, I'd suggest you use Canvas, not GameCanvas, it's less problematic.
I thought I'd try too, because it looks quite cool
I came up with this:
PHP Code:
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.midlet.*;
public class Dusty extends MIDlet {
private Displayable d;
public void startApp() {
if (d == null) {
try {
Image img = Image.createImage("/Dusty.jpg");
d = new DustCanvas(img);
} catch (Exception e) {
Form f = new Form("Error");
f.append(e.toString());
d = f;
}
}
Display.getDisplay(this).setCurrent(d);
}
public void pauseApp() {
// empty
}
public void destroyApp(boolean must) {
// empty
}
private static class DustCanvas extends Canvas {
private static final int SIZE = 25;
private int width;
private int height;
private Image background;
private Image foreground;
public DustCanvas(Image bg) {
background = bg;
width = bg.getWidth();
height = bg.getHeight();
foreground = Image.createImage(width, height);
Graphics g = foreground.getGraphics();
g.drawImage(bg, 0, 0, Graphics.LEFT | Graphics.TOP);
// paint "dust" on top of foreground - this is not an optimal implementation!
int[] dust = new int[] { 0xc0808080 };
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
g.drawRGB(dust, 0, 1, x, y, 1, 1, true);
}
}
}
protected void paint(Graphics g) {
g.drawImage(foreground, 0, 0, Graphics.LEFT | Graphics.TOP);
}
protected void pointerPressed(int x, int y) {
Graphics g = foreground.getGraphics();
int px = x - SIZE;
int py = y - SIZE;
int w = SIZE * 2;
int h = SIZE * 2;
if (px < 0) {
w += px;
px = 0;
}
if (py < 0) {
h += py;
py = 0;
}
if (px + w > width) {
w = width - px;
}
if (py + h > height) {
h = height - py;
}
g.drawRegion(background, px, py, w, h, Sprite.TRANS_NONE, px, py, Graphics.LEFT | Graphics.TOP);
repaint();
}
protected void pointerDragged(int x, int y) {
pointerPressed(x, y);
}
}
}
This breaks too, if the image is smaller than the screen and you touch the screen much outside the area of the image, but otherwise it works OK. It doesn't look much different to your code.
Graham.