Android 2D game engine with canvas capability - android

Im looking for Android 2D framework which allows me to create canvas layer on which I can draw simple shapes like rect, oval atc (raster graphics). The canvas have to PERSIST everything I draw on it.
I found many engines (libgdx, andengine ...) but if they have capability to draw shapes, its only for one screen update. Reason becouse I dont store drawn shapes to some kind of List is becouse in app, the drawing occurs every screen update so I just want to modify canvas and dont remember anything.
Thanks for every answer.

As far as I know, android doesn't support something like that. Android uses double-buffering which means 2 alternatives "screens" that alternate each other so if you draw on one the next would be on random state.
There are tricks you can use to achieve what you want like draw both screens and then stop drawing, but android doesn't support such behavior because when you get hold of a canvas it's not certain that it returned exactly as what you did last frame, it doesn't specify what could cause an error, but if you ask me it could be anything that pops up on screen.
You don't really need an engine to do that, you can use a SurfaceView and draw on it (it supports shapes like the ones you want)

Related

Android: draw figures on canvas

I m working on canvas. Here I just want to draw some geometric figures on canvas which may be resized according to the touch_move positions. By figures , I just meant triangle,rectangle,circle and some polygons. Is there a way to achieve this? . I haven't seen such apps which can draw these figures over canvas. So this seems to be complicated.. Thanks in advance
See this link.
If your application does not require a significant amount of processing or frame-rate speed (perhaps for a chess game, a snake game, or another slowly-animated application), then you should consider creating a custom View component and drawing with a Canvas in View.onDraw(). The most convenient aspect of doing so is that the Android framework will provide you with a pre-defined Canvas to which you will place your drawing calls.
I'm sure you can find some open-sourced out-of-the-box solutions for this if you tried a little.
If you actually want to learn something you should read the tutorials of per example;
-Custom Views
-OpenGL
After doing the tutorials, you'll have 2 ways to draw basic shapes, a triangle and a circle I believe, already done.

Using vector graphics on android

I'm currently attempting to make a simple 2D CAD-type viewer app for Android. Basically the input file contains a bunch of primitives (rectangles, lines, circles, octagons, that type of thing), and the goal is to draw these to the screen at whatever coordinates/sizes they offer.
My initial instinct is to use a Canvas to draw these to, using a quadtree or some similar structure to track which items will show up on the screen at any given time.
Does anyone have any recommendations here for a better way to implement this (my graphics programming experience is minimal, and hence I'm having problems even finding a starting point to Google from)?
Thanks in advance,
-Ross
That's a very broad question so my answer will only point at classes that you should be looking at.
Extend a surfaceView to be your cadView, that way you'll be all the calculation outside the main thread.
you'll still have to draw on the canvas.
from the canvas you can getWidth() and getHeight() and use those values for base comparison on your positions.
Canvas have some primitives drawings types like arc, circle, point.
Further you can use Path to draw full figures, line, filling, quadratic, etc.
for backgrounds you can create color drawables and draw it on the canvas.
and that's pretty much it.

Android View options - draw to a canvas directly or use views

I'm converting a project that I wrote in AIR a long time ago to native Android. In AIR, positioning views was fairly easy in x,y coordinate systems. With native Android though, I am trying to approach this in a correct way, but I'm unsure how to approach.
My view will consist of two circles in the background, with small objects within those circles that can roll around. There will be another view drawn on top of the circles to make it seem like there is glass over the circle, entrapping the small objects. The small objects are bound to the background circles.
I guess what I'm really asking is canvas drawing the best approach here, or is a view-based layout workable as well?
It sounds like your best option would be to use a SurfaceView. This is basically a hardware accelerated canvas. On of the benefits is that you can overlay standard widgets over top of it if you need to so you can mix and match custom and standard components. Here is a link to a website that walks you through getting a SurfaceView up and running

Open GL and Canvas which method is more suitable for making custome brushes in drawing application?

I want to make brushes displayed in below image for drawing application. Which is a suitable method - Open GL or Canvas & How can we implement it?
I'd say Canvas, as you'll want to modify an image. OpenGLES is good for displaying images, but does not (as far as I know) have methods for modifying its textures (unless you render to a texture that then render to screen with some modifications, which is not always so effective).
Using the Canvas you will have the methods for drawing your brush-strokes onto the Bitmap you're painting on, in GLES you would have to modify a texture (by using a canvas) and then upload that to the GPU again, before it could be rendered, and the rendering would most likely just consist of drawing a square with your texture on it (as the fillrate for most mobile GPUs are quite bad, you don't want to draw the strokes separately).
What I'm trying to say is; The most convenient way to let the user draw on an openGLES surface would be by creating a texture by drawing on a Canvas.
But, there might still be some gain in using GL for drawing, as the Canvas-operations can be performed off-screen, and you can push this data to a gl-renderer to (possibly) speed up the on-screen drawing.
However; if you are developing for Android 3.x+ you should take a look at RenderScript, (which I personally have never had a chance to use), but seems like it would be a good solution in this case.
Your best solution is going to be using native code. That's how Sketchbook does it. You could probably figure out how by browsing through the GIMP source code http://www.gimp.org/source . Out of Canvas vs OpenGL, Canvas would be the way to go.
It depends. if you want to edit the image statically, go with canvas. But if you want after brushing the screen, to have the ability to edit, scale, rotate, it would be easier with opengl.
An example with opengl: Store the motion the user do with touchs. create a class that store a motion and have fields for size, rotation etc. to draw this class, just make a path of the brush image selected following the stored motion.

Android: Canvas vs OpenGL

I have a drawing app where the user can draw lines with their finger, adjust the color, thickness, etc. As the user is drawing, I am converting the massed X/Y points from MotionEvent into SVG Paths, as well as creating Android Path's and then drawing the Android Path's to the screen via a Canvas, and committing the SVG Path's to the app's database.
I am following the model used in FingerPaint, in that the 'in progress' lines are drawn on the fly by repeated calls to invalidate() (and thus, onDraw()), and once the line is complete and a new line is started, the previous line(s) are drawn in onDraw() from the underlying Canvas Bitmap, with in progress lines again generating repeated re-draws.
This works fine in this application - until you start rotating the underlying Bitmap to compensate for device rotation, supporting the ability to 'zoom in' on the drawing surface and thus having to scale the underlying Bitmap, etc. So for example, with the device rotated and the drawing scaled in, when the user is drawing, we need to scale AND rotate our Bitmap in onDraw(), and this is absolutely crawling.
I've looked at a SurfaceView, but as this still uses the same Canvas mechanism, I'm not sure I'll see noticeable improvement... so my thoughts turn to OpenGL. I have read somewhere that OpenGL can do rotations and scaling essentially 'for free', and even seen rumors (third comment) that Canvas may be disappearing in future versions.
Essentially, I am a little stuck between the Canvas and OpenGL solutions... I have a 2D drawing app that seems to fit the Canvas model perfectly when in one state, as there are not constant re-draws going on like a game (for instance when the user is not drawing I don't need any re-drawing), but when the user IS drawing, I need the maximum performance necessary to do some increasingly complex things with the surface...
Would welcome any thoughts, pointers and suggestions.
OpenGL would be able to handle the rotations and scaling easily.
Honestly, you would probably need to learn a lot of OpenGL to do this, specifically related to the topics of:
Geometry
Lighting (or just disabling it)
Picking (selecting geometry to draw on it)
Pixel Maps
Texture Mapping
Mipmapping
Also, learning OpenGL for this might be overkill, and you would have to be pretty good at it to make it efficient.
Instead, I would recommend using the graphic components of a game library built on top of openGL, such as:
Cocos2d
libgdx
any of the engines listed here
Well, this question was asked 6 years ago. Maybe Android 4.0 has not come up?
Actually, after Android 4.0 the Canvas at android.view.View is a hardware accelerated canvas, which means it is implementd by OpenGL, so you do not need to use another way for performance.
You can see the https://github.com/ChillingVan/android-openGL-canvas/blob/master/canvasglsample/src/main/java/com/chillingvan/canvasglsample/comparePerformance/ComparePerformanceActivity.java to compare the performance of normal canvas in view with GLSurfaceView.
You are right that SurfaceView uses Canvas underneath the hood. The main difference is that SurfaceView uses another thread to do the actual drawing, which generally improves performance. It sounds like it would not help you a great deal, though.
You are correct that OpenGL can do rotations very quickly, so if you need more performance that is the way to go. You should probably use GLSurfaceView. The main drawback with using OpenGL is that it is a real pain to do text. Basically you have to (okay, don't have to, but seems to be the best option) render bitmaps of text.

Categories

Resources