| Home | My Account | Directories |
Implement onTouchEvent() to handle user touch on SurfaceView
Published on 2012-02-15 17:14:00
Modify from last article Sprite auto-run, implement onTouchEvent() to handle user touch on SurfaceView. When user touch on the screen(SurfaceView), it will call setX(x) and setY(y) of mySprite object to update its position.package com.MyGame;import android.content.Context;import android.graphics.BitmapFactory;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.PorterDuff.Mode;import android.util.AttributeSet;import android.view.MotionEvent;public class MyForegrou
Sprite auto-run
Published on 2012-02-12 10:33:00
In last article Introduce Sprite without movement. In this article, we are going to make it self move.Modify Sprite.java to make it self random move inside the canvas.package com.MyGame;import java.util.Random;import android.graphics.Bitmap;import android.graphics.Canvas;public class Sprite { private Bitmap bitmap; private int x; private int y; float bitmap_halfWidth, bitmap_halfHeight; Random random = new Random(); private int dirX; private int dirY; private int moveX; private int moveY; fina
Introduce Sprite
Published on 2012-02-09 15:02:00
Base on last post Create transparent foreground SurfaceView, the object on foreground was draw as a bitmap. We are going to implement a Sprite class here. Sprite object keep it's own status such as location(x, y) and bitmap, and also draw itself on canvas.Add class Sprite.javapackage com.MyGame;import android.graphics.Bitmap;import android.graphics.Canvas;public class Sprite {private Bitmap bitmap;private int x;private int y;float bitmap_halfWidth, bitmap_halfHeight;public Sprite(Bitmap bm, int