Android Graphics Library
2021年3月1日Android Graphics Library
link: https://bytlly.com/1tzyt4
For the RectF object, we use RectF s set(float left, float top, float right, float bottom) to specify its bounds with the current balls position.. The touch screen can generate events such as touch-down, touch-up and touch-drag.. We need to invoke View setFocusableInTouchMode(true) to enable touch inputs We maintain the bounds ( xMin, xMax, yMin, and yMax ) as int instance variables with package access.. The drawOval() method takes two arguments - a RectF (rectangle in float) object which specifies the bounds of the circle, and a Paint object carrying the paint properties such as the color and the style.. Android Graphics Library Update The PositionAfter a small delay (via Thread sleep() to suspend the current thread), we invoke View s invalidate() to inform the Android graphics sub-system to re-draw the view.. Take note that to enable key inputs, we need to set the View to be focusable, and request for the focus.. If collision occurs, we adjust the position and speed of the ball accordingly We set the bounding box width and height according to the View s weight and height.. The method moveWithCollisionDetection() moves the ball (according to its speed), and adjusts the position and speed of the ball if collision occurs.. We choose float for these variables as it may involve in mathematically operations.. Android Graphics Library Update The PositionWe then call the update() helper method to update the position of the ball, considering possible collision with the bounding box.. The method draw() renders this shape via Canvas drawOval() method It has a update() method, which takes the ball as argument, and update the balls position and speed in the buffer.. For the Paint object, we construct an instance with default settings, and set the drawing color via Paint s setColor().. It constructs a Box, a Ball, a StatusMessage in its constructor The onKeyUp() process the key inputs and changes the Ball s parameters such as speed and radius.. In the onDraw(), we use Canvas s drawText() to draw the status message We use Paint s setTypeFace(), setTextSize() and setColor() to set the font face, size and color for the text. 5ebbf469cd
コメント