Beginner Android, and make an example of people sharing the beginner, expert advice
Code package has been uploaded to my download resources http://download.csdn.net/detail/suolong123/3815059

package com.marssoft.graphicstest;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.view.KeyEvent;
import android.view.View;
public class TestView extends View {
public static final short DIRECTION_UP = 19;
public static final short DIRECTION_DOWN = 20;
public static final short DIRECTION_LEFT = 21;
public static final short DIRECTION_RIGHT = 22;
private int width;
private int height;
private Activity act = null;
private Bitmap map = null;
private Bitmap z [] = new Bitmap [2];
private Bitmap rm [] [] = new Bitmap [4] [4];
private Paint mPaint = new Paint ();
private Bitmap mzip = null;
private int rx = 0, ry = 0;
private int moveDirection = 0; / / movement direction
private int dirction = DIRECTION_DOWN; / / currently facing
private int move_p = 0; / / move the animation
public TestView (Context context) {
super (context);
act = (Activity) context;
width = act.getWindowManager () getDefaultDisplay () getWidth ();..
height = act.getWindowManager () getDefaultDisplay () getHeight ();..
z [0] = new BitmapDrawable getBitmap () (this.getContext () getResources () openRawResource (R.drawable.m0)..);.
z [1] = new BitmapDrawable (this.getContext () getResources () openRawResource (R.drawable.m0)..) getBitmap ();.
/ / HandlerThread thread = new HandlerThread ("chonghua");
/ / Thread.start ();
/ / Repaint r = new Repaint (thread.getLooper ());
new Thread (new Repaint ()) start ();.
createImage ();
setFocusable (true); / / set the control focus
}
@ Override
public boolean onKeyDown (int keyCode, KeyEvent event) {
/ / Keyboard Press
System.out.println ("key operation:" + keyCode);
moveDirection = keyCode;
dirction = keyCode;
return super.onKeyDown (keyCode, event);
}
@ Override
public boolean onKeyUp (int keyCode, KeyEvent event) {
moveDirection = 0;
move_p = 0;
return super.onKeyUp (keyCode, event);
}
/ **
* Create a map.
* /
public void createImage () {
map = Bitmap.createBitmap (width, height, Config.ARGB_8888); / / create a consistent image to the screen size
Canvas canvas = new Canvas (map); / / get the drawing object
canvas.drawColor (Color.WHITE); / / set the background color to white
int r = height/32;
int c = width/32;
Paint p = new Paint ();
for (short i = 0; ifor (short f = 0; f canvas.drawBitmap (z [0], f * 32, i * 32, p);
}
}
mzip = new BitmapDrawable getBitmap () (this.getContext () getResources () openRawResource (R.drawable.r01)..);. / / get character
/ / Decomposition action figures
System.out.println ("start cutting plans");
for (short i = 0; i <4; i + +) {
for (short f = 0; f <4; f + +) {
rm [i] [f] = Bitmap.createBitmap (mzip, f * 32, i * 48, 32, 48);
}
}
}
@ Override
protected void onDraw (Canvas canvas) {
/ / TODO Auto-generated method stub
super.onDraw (canvas);
if (map! = null) {
canvas.drawBitmap (map, 0,0, mPaint);
short sd = 0;
if (dirction == DIRECTION_UP) {
sd = 3;
} Else if (dirction == DIRECTION_LEFT) {
sd = 1;
} Else if (dirction == DIRECTION_RIGHT) {
sd = 2;
} Else if (dirction == DIRECTION_DOWN) {
sd = 0;
}
canvas.drawBitmap (rm [sd] [move_p], rx, ry, mPaint);
}
System.out.println ("It is said that the call to onDraw function");
}
/ **
* Mobile villain.
* @ Param direction direction
* /
public void move (int direction) {
}
private class Repaint implements Runnable {
public void run () {
while (true) {
if (moveDirection == DIRECTION_UP) {
ry-= 5;
} Else if (moveDirection == DIRECTION_DOWN) {
ry + = 5;
} Else if (moveDirection == DIRECTION_LEFT) {
rx-= 5;
} Else if (moveDirection == DIRECTION_RIGHT) {
rx + = 5;
}
System.out.println (rx + "-" + ry);
if (moveDirection! = 0) {
move_p + +;
if (move_p == 4) {
move_p = 0;
}
}
/ / Refresh
postInvalidate ();
try {
Thread.sleep (50);
} Catch (InterruptedException e) {
e.printStackTrace ();
}
}
}
}
}
Reply:
3 Resources wow your good points but still support it
Reply:
Reply:
Reply:
Reply:
Reply:
Have time to study it.
Reply:
Support
Reply:
Thank you for sharing
Reply:
Do not understand ah ah ah ah
Reply:
Support it
Reply:
3 Resources wow your good points but still support it
Reply:
This is not clear. Bangniding onwards.
Reply:
Oh, yes
Reply:
Reply:
See it
Reply:
Congratulations landlord ah, Oh
Reply:
Reply:
Reply:
Ah well apply their knowledge
Reply:
Reply:
Reply:
Looks really very little high.
Reply:
Next see how ah!
Reply:
First collection, free re-learn
Reply:
Reply:
Thanks for sharing it in the learning
Reply:
Support, this good
Reply:
Good thing is expensive
Reply:
hao good ah thank you
Reply:
It is recommended? CSDN the android version is really a bit. . . . . .
Reply:
Thank you just started learning
Reply:
Reply:
I came to the top 30 floors. . . . Hey. . .
Reply:
So cool ~ ~
Reply:
The cattle
Reply:
Support, refueling
Reply:
Have time to study it.
Reply:
Halo. In fact, we are all mixed points. . . .
Reply:
Reply:
Reply:
Reply:
Reply:
Support what
Reply:
Prepare to be a mobile version rpgmaker it
Reply:
Support the landlord
Reply:
run
Reply:
Today I got a 5 points stuff I went down!
Reply:
Reply:
Reply:
Reply:
Reply:
Reply:
3 points. . . NND.
Reply:
About the character is based on the curve of what motion pictures, any request under code sharing, recently engaged in this stuff thank you
Reply:
Reply:
Reply:
Reply:
Research
Reply:
A bit expensive, but thank you for sharing
Reply:
Learn under the first, thank you.
Reply:
Support ah Support
Reply:
Thank you for sharing. Feeling something good
Reply:
Like a good
Reply:
Reply:
Reply:
Reply:
Reply:
Make a mark
Reply:
Oh, yes
Reply:
Good effort
Reply:
Reply:
Reply:
Reply:
Reply:
Top that, yes. But there are point defects, that is, since the View inside the defined start a thread has been running, even if you have to withdraw the entire Apk, that thread is still running. You can define a Boolean variable to determine what and under what circumstances launched thread.
Reply:
Reply:
Reply:
I just want the resource picture ah!
Reply:
Oh, well advanced, yet do not understand
Reply:
Reply:
Support,
Reply:
First collection, thank you
Reply:
Reply:
Reply:
Reply:
android is not difficult to learn ah also want to research studies
Reply:
Introduced the idea of writing a simple article fighter plane shooting game, which also includes a button control, motion control, collision detection, basically text and simple pseudo-code, it is easy to understand. Interested in this regard can be look: Portal
Reply:
Reply:
Reply:
But also to support the
Reply:
Reply:
E-mail to stay, resource to you, or to extract yourself next rpgmaker
Reply:
Evidently. . . Landlord cattle ah. . To learn from you
Reply:
Reply:
Reply:
Reply:
3 Resources wow your good points but still support a
Reply:
You've been watching the reaction of expensive, not help it, I want to download something, but others must be integral to download, but not the original, want not low. No points very painful ah ......
So forgive me, the wait will release an upgraded version does not require integration
Reply:
Well ... received ...
Reply:
- Expect free integral version.
- This should be used in the game more now!
No comments:
Post a Comment