Saturday, January 25, 2014

Android realize people moving on the map


            
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; i for (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:
The reply was deleted at the moderator 2011-11-20 14:02:13

Reply:
The reply was deleted at the moderator 2011-11-20 14:23:09

Reply:
The reply was deleted at the moderator 2011-11-20 14:23:20

Reply:
The reply was deleted at the moderator 2011-11-21 09:11:22

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:
The reply was deleted on 2011-11-21 09:56:12 moderator

Reply:
See it
Reply:
Congratulations landlord ah, Oh
Reply:
The reply was deleted on 2011-11-21 09:59:49 moderator

Reply:
The reply was deleted at the moderator 2011-12-15 10:15:03

Reply:
Ah well apply their knowledge
Reply:
The reply was deleted at the moderator 2011-11-24 11:30:55

Reply:
The reply was deleted at the moderator 2011-11-21 10:00:42

Reply:
Looks really very little high.
Reply:
Next see how ah!
Reply:
First collection, free re-learn
Reply:
The reply was deleted at the moderator 2011-11-21 10:56:12

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:
The reply was deleted at the moderator 2011-11-21 16:46:04

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:
The reply was deleted at 2011-11-22 10:05:51 moderator

Reply:
The reply was deleted at 2011-11-22 10:27:07 moderator

Reply:
The reply was deleted at 2011-11-22 11:07:52 moderator

Reply:
The reply was deleted at 2011-11-22 13:16:06 moderator

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:
The reply was deleted at 2011-11-23 10:00:47 moderator

Reply:
The reply was deleted at 2011-11-23 10:02:54 moderator

Reply:
The reply was deleted at the moderator 2011-11-24 11:30:55

Reply:
The reply was deleted at 2011-11-23 09:18:30 moderator

Reply:
The reply was deleted at 2011-11-23 10:17:13 moderator

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:
The reply was deleted at 2011-11-23 13:02:43 moderator

Reply:
The reply was deleted at 2011-11-23 13:10:25 moderator

Reply:
The reply was deleted at 2011-11-23 13:34:38 ​​moderator

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:
The reply was deleted at the moderator 2011-11-24 09:27:12

Reply:
The reply was deleted at the moderator 2011-11-24 10:45:03

Reply:
The reply was deleted at the moderator 2011-11-24 10:45:03

Reply:
The reply was deleted at the moderator 2011-11-24 10:45:03

Reply:
Make a mark
Reply:
Oh, yes

Reply:
Good effort
Reply:
The reply was deleted at the moderator 2011-11-24 09:39:42

Reply:
The reply was deleted at the moderator 2011-11-24 12:59:44

Reply:
The reply was deleted at the moderator 2011-11-24 11:23:00

Reply:
The reply was deleted at the moderator 2011-11-24 13:13:36

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:
The reply was deleted at the moderator 2011-11-24 14:07:23

Reply:
The reply was deleted at the moderator 2011-11-24 14:13:49

Reply:
I just want the resource picture ah!
Reply:
Oh, well advanced, yet do not understand
Reply:
The reply was deleted at the moderator 2011-11-24 16:20:26

Reply:
Support,
Reply:
First collection, thank you
Reply:
The reply was deleted at 2011-11-25 09:02:16 moderator

Reply:
The reply was deleted at 2011-11-25 09:27:48 moderator

Reply:
The reply was deleted at 2011-11-25 10:20:22 moderator

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:
The reply was deleted on 2011-11-28 09:47:04 moderator

Reply:
The reply was deleted on 2011-11-28 09:55:41 moderator

Reply:
But also to support the
Reply:
The reply was deleted on 2011-11-28 09:56:51 moderator

Reply:
cited 78 floor b87936260 reply:
I just want resource picture ah!

E-mail to stay, resource to you, or to extract yourself next rpgmaker
Reply:
Evidently. . . Landlord cattle ah. . To learn from you
Reply:
The reply was deleted at the moderator 2011-11-29 10:01:06

Reply:
The reply was deleted at the moderator 2011-11-29 09:08:34

Reply:
The reply was deleted at the moderator 2011-11-29 09:13:02

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