This is the second blog. In this tutorial, We will write a small ball.
First, let's take a look at the class diagrams of the small ball class:
Mainly determine the coordinates of the ball: x, y. Radius of the ball: r. And the motion function of the ball and the draw () function on the screen.
Difficulty: move () function. We will simulate a physical environment to make the ball look elastic. For details about this part, I will answer it in the next article.
The code for Ball. java is given belo
keyboard trigger events (such as: OnKeyDown int keycode, keyevent Event)).
Here's an example.:
For example, when playing games, we often customize the view, we generally like and use the trigger in this view (Gameview) Trigger events and screen triggering events, but for example: onKeyDown (int keycode, keyevent event)), In general, when we press the keyboard directly triggered by the activity in the keyboard trigger event, how to let it directly t
(int keyCode, KeyEvent event )).
The following is an example.:For example, when playing games, we often customize views. We generally like and use the keyboard trigger events and screen trigger events in this view (GameView), but for example: onKeyDown (int keyCode, keyEvent). Generally, when we press the keyboard, the keyboard trigger event in the activity is directly triggered. How can we make it directly trigger the keyboard trigger event (
() self: getApp (): enterScene ("PlayScene") -- enter the game Interface end) cc. menu: create (playButton): move (display. cx, display. cy-200): addTo (self) endreturn MainScenePlayScene. lua
Local PlayScene = class ("PlayScene", cc. load ("mvc "). viewBase) local GameView = import (". gameView ") function PlayScene: onCreate () -- create game view and add it to stage self.
Tags: des Android blog HTTP Io ar Java file sp ================================= Problem description ========================== =Today, I encountered an error. Baidu failed to solve the problem. Maybe the search capability needs to be improved.Paste some code firstProtected void oncreate (bundle savedinstancestate) {log. V ("gamewindow", "oncreate"); super. oncreate (savedinstancestate); setcontentview (R. layout. gameview); // layoutinflater Inflater
Press the upper/lower key rectangle on the keyboard to move up and down;
The Handler object is instantiated and the handkeMessage method is rewritten to implement a message receiver. Then, the thread sends the update interface message through the sendMessage method. When the receiver receives the update interface message, it executes the invalidate method to update the screen display.
Package com. yarin. android. testOnView; import android. content. context; import android. graphics. canvas; imp
, 1 is the same, 2 is the scale 1/2, this way.Matrix Operations are divided into four types: translate, rotate, scale, and skew, each transformation provides the set, post, and pre operations in the Android API. Except for the translate operation, the center point can be specified for all the other three operations. Set is to directly set the value of the Matrix. Each time a set is set, the array of the entire Matrix is changed.Now we use setRotate to set the rotation angle, use creatBitmap to c
disappear, some will be more flexible, and so on... The specific design method will be detailed in the following articles. You can also think about how to design the game first.
3. This lesson mainly completes the construction of the Basic Framework: We use SurfaceView to implement the game (View is generally used for games that do not need to be refreshed all the time, such as wuziqi and even watching ).
SurfaceView implements dual buffering by default. Therefore, the efficiency is higher.
A s
How do you draw on the picture? Here has written a demo, for everyone to refer tofirst, take a look at the structure of the projectEngineering Structure:
Two, custom viewThis custom view implements the function of preserving the trajectory, as follows
Package Picturegame.view;
Import Android.content.Context;
Import Android.graphics.Bitmap;
Import Android.graphics.BitmapFactory;
Import Android.graphics.Canvas;
Import Android.graphics.Color;
Import Android.graphics.Paint;
Import And
This article describes the Android development of the multi-threading implementation of the use of custom control to draw a small ball and complete the ball automatic drop function method. Share to everyone for your reference, specific as follows:
1. Layout interface
2, the package of a drawn diagram of the class
Package www.csdn.net.tetris.domain;
Import Www.csdn.net.tetris.view.GameView;
public class Block {
private int x=20,y=20;
Public
reload these methods, and when there are keys bouncing or pressing, the key code is automatically transferred to the appropriate method to handle.The core of the game is the constant drawing and refresh of the interface, which we already know and need to draw using the OnDraw method. Let's examine how to refresh the interface. The Invalidate method is provided in Android to refresh the interface, noting that the Invalidate method cannot be called directly in the thread because it violates the s
Android Graphic demo
How to draw images? Here is a demo for your reference.1. Take a look at the engineering structure:
Ii. Custom view the custom view implements the tracking retention function. The Code is as follows:
Package picturegame. view; import android. content. context; import android. graphics. bitmap; import android. graphics. bitmapFactory; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. graphics. paint. style; imp
Write a homemade background image with Surfaceview, and you can move it, plus the Backgroundmanager class in the Android Aircraft War (a), you can use it directlyGameview Code:public class Gameview extends Surfaceview implements surfaceholder.callback,runnable{Private Surfaceholder Hd=null;Private Canvas Canvas=null;Private Backgroundmanager Backgroundmanager;Public Gameview (Context context) {Super (contex
Now we are teaching the second article. With the framework, we can freely draw what we want on the screen. The background is used.Background ComponentsThe characters, bullets, and genie are all used.Sprite genie Components
The gameactivity class is the main activity class of the game. It inherits the base class here. You only need to replace the interface with gameview.
Package COM. mocn. airbottle; import android. r; import android. OS. b
indicates transparency. The transparency range is 00-ff. The last six digits are color values. // The Layout_wight and Layout_height are set as match_parent (-1 indicates match_parent, respectively, -2 stands for wrap_content) LayoutParams lp = new LayoutParams (-1,-1); lp. setMargins (10, 10, 10, 10); // set the card spacing addView (lable, lp); setNum (0);} int num = 0; public int getNum () {return num;} public void setNum (int num) {this. num = num; // when cardMap [] []
Create a main clas
common approach to Android is to use handler to implement UI thread updates. In fact, you can use Asynctask.
Specific examples:
Activity:
public class Activity01 extends activity {private static final String TAG = "Mthread";
private static final int REFRESH = 0x000001;
Private Gameview Mgameview = null;
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
This.mgameview = new
Today I want to realize the function of returning to the last activity in view. Because while the view is contained in an activity, the object that is obtained directly in the view is not an activity but the view, and it is not possible to write the name of the activity directly. So I found this method and attached it!
Let's first assume that the view is defined in activity a. Assuming that the view class is called Gameview, then in a oncreat (), the
New Project UsingsurfaceviewCreate a new class Gameview inherit to Surfaceview and implement the callback interfaceAdd a constructor method, and make a copy of the callback three non-implemented methodsCreate a container contanier to host all view Public class Contanier {Private Listnull; Public Contanier () {Children = New arraylist} Public void Draw (canvas canvas) {Childrenview (canvas); for (Contanier C:children) {C.draw (canvas);}} Public void ch
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.