android-canvas

ANDROID: How to eliminate lag and improve FPS in Android Canvas SurfaceView?

老子叫甜甜 提交于 2019-12-13 05:19:45
问题 I am a near beginner android programmer, and i have made a simple 2D spaceship game in surfaceView class where you can control the spacehip with your finger and you have dodge oncoming objects. However, now that i am using a lot of bitmaps my game seems to be lagging a bit. So i was wondering is there a way to destroy/garbage pictures after you use them, so they don't create so much lag. (because i think, the pictures are creating the lag) Please tell me another simple way to make my game

Live Wallpaper + bitmap + canvas

大城市里の小女人 提交于 2019-12-13 04:23:45
问题 Helo everyone! I have this live wallpaper in witch I try to show a bitmap trough a canvas (the drawable resource is a 400k 1900x1200 jpg). It force-closes and I don't get why (it's my first Android project). These are the "important" bits: wallEngine() { // CONSTRUCTOR <<<<<<<<<<<<<<<<<<< mStartTime = SystemClock.elapsedRealtime(); Log.v(Logcat, "Contructor ok"); } //====================================== INIT private final Runnable mDrawWall = new Runnable() { //=========== RUN public void

add touch event listener to android canvas

独自空忆成欢 提交于 2019-12-13 03:58:15
问题 I have a canvas object (c) , and I need to add a touch event listener so that whenever the canvas is touched, I can call a function. I haven't been able to find how to add it on so far, Here's what I have: c.setOnTouchListener(new onTouchListener(){onTouchEvent()}); and then the onTouchEvent method: public boolean onTouchEvent(MotionEvent e){ addBubble(); return false; } new to both java and android development, thanks for any help! If i'm not meant to add a touch listener to a canvas, then

PointF 90degrees from X

旧巷老猫 提交于 2019-12-13 03:48:41
问题 Yesterday I asked a question - Draw arrow according to path In that question I explained that I want to draw a arrow head in the direction of my onTouchEvent . I got a answer in the comments saying I should rotate the canvas. Last night I got a new idea and this is where this question comes in. I get the x position/coordinate in MotionEvent.ACTION_DOWN by calling event.getX(); inside my onTouchEvent . I would like to know if it is possible to get a point/coordinate 90 degrees from x ? Here is

Android ListView-like scrolling WITHOUT the ListView

守給你的承諾、 提交于 2019-12-13 03:22:52
问题 I've been Googling like crazy for a while now, and I simply can't find any answers to the question: is it possible to implement the Android List scrolling, without using an actual list UI? I'm trying to make a grid of rectangles such as the kind you would find in a typical game app respond to finger movement in the same way that it does using Android lists (bounce on the bounds, the 'flick' effect, etc), but all of the approaches I've found involve over-complicated solutions involving

Draw a line within a Fragment using Canvas in Android

怎甘沉沦 提交于 2019-12-13 02:39:35
问题 I am trying to draw a line with Canvas inside of a Fragment. After some research it appeared that I just had to extend the View class and override onDraw, then return an instance of my new View class where I would normally inflate a layout. However when I access the fragment on my device all I see is a white screen. Here is what I have so far: package com.example.testing; import android.app.Fragment; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color

How to draw on canvas greater than screen size and be able to scroll / pan horizontally and vertically in android?

牧云@^-^@ 提交于 2019-12-13 02:26:19
问题 I am looking for a real example with sample code on how to draw on canvas greater than screen size ( As of now I am drawing normally and not able to view outside screen size). More stress is on being able to scroll / pan the screen to view the whole canvas. If anymore info is required please comment. Update: Found my answer here Image in Canvas with touch events 回答1: My version is converted from Monodroid, but the implementation should look about the same. (I tried putting it back into java,

What's the best way to do collision detection?

妖精的绣舞 提交于 2019-12-13 00:52:22
问题 I have a need to define a polygon that would be the "legal" area, and allow a user to move a rectangle around within that polygon, preventing them from moving the rectangle anywhere where its points venture outside the polygon. The polygon is a fixed shape, so, I was thinking it may be easiest to import a PNG of that shape and pull the points in that way, somehow? But I'm still at a loss as to the math involved in checking the coordinates of the rectangle as the user drags it, and testing at

Draw multiple bitmap on a view in android

廉价感情. 提交于 2019-12-12 19:41:28
问题 I am trying to make a view in which i am having 6-7 different images. There is no issue in drwaing only one image on a view, but how to draw multiple images on that view. Here is my code- Bitmap img1= BitmapFactory.decodeResource(context.getResources(), R.drawable.football); And here is my onDraw() method- @Override protected void onDraw(Canvas canvas) { setBackgroundColor(Color.GREEN); float hgt=canvas.getHeight(); float wth=canvas.getWidth(); System.out.println("hgt and wt is "+hgt+" "+wth)

Finger paint get slow after changing background

不羁岁月 提交于 2019-12-12 16:42:32
问题 In my Paint App i used custom view, which is there in Finger paint API demo. The code like given here: public class MyView extends View { private static final float MINP = 0.25f; private static final float MAXP = 0.75f; Paint mPaint; Bitmap mBitmap; Canvas mCanvas; Path mPath; private Paint mBitmapPaint; int w, h; public MyView(Context c) { super(c); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFFFF0000); mPaint.setStyle(Paint.Style.STROKE);