"Android Combat" Surfaceview draw various effects demo

Source: Internet
Author: User

1. Bolted bombs

public class Mysurface extends Surfaceview implements Callback, Runnable {surfaceholder Holder;boolean goOn = True;int w;i NT H; Bitmap bitmap;int x;int y;int bx;int By;boolean down = true;boolean right = True;int p = 30;public mysurface (Context Conte XT, int wi, int hi) {super (context);//TODO auto-generated Constructor Stubholder = Getholder (); Holder.addcallback (this); Setfocusable (True); Setfocusableintouchmode (true); w = wi;h = Hi; Bitmap Obitmap = Bitmapfactory.decoderesource (Getresources (), r.drawable.b1); Bitmap = Bitmap.createscaledbitmap ( Obitmap, 260, $, false); bx = Bitmap.getwidth (); by = Bitmap.getheight (); Thread t = new thread (this);} @Overridepublic void surfacecreated (Surfaceholder holder) {//TODO auto-generated method Stubthread t = new Thread (this); t . Start ();  @Overridepublic void Surfacechanged (surfaceholder holder, int format, int width,int height) {//TODO auto-generated method stub} @Overridepublic void Surfacedestroyed (Surfaceholder holder) {//TODO auto-generated method StuBgoon = false;} @Overridepublic void Run () {//TODO auto-generated method Stubwhile (goOn) {mydraw (); try {if (Y < h-by && Dow N) {y + = p;} else {down = false;if (x < W-BX && right) {x + = p;} else {right = False;if (Y > 0 && !down) {y-= p;} else {if (x > 0 &&!right) {x = P;} else {down = True;right = True;}}}} Thread.Sleep (10);} catch (Interruptedexception e) {//TODO auto-generated catch Blocke.printstacktrace ();}}} Canvas canvas;private void Mydraw () {//TODO auto-generated Method Stubcanvas = Holder.lockcanvas (); if (canvas! = null) {P Aint paint = new paint ();p aint.setxfermode (New Porterduffxfermode (mode.clear)); Canvas.drawpaint (paint); Paint.setxfermode (New Porterduffxfermode (MODE.SRC)); Canvas.drawcolor (Color.gray); try {if (canvas! = null) { Canvas.drawbitmap (bitmap, x, y, null);}} finally {if (canvas! = null) {holder.unlockcanvasandpost (canvas);}}}}



"Android Combat" Surfaceview draw various effects demo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.