Drawing curved lines in AndEngine - android

I am new to AndEngine and very happy that it's very easy and exciting thing to do. Unfortunately I am unable to draw a curved line in AndEngine.
Actually my scenario is that I have an animated sprite say Object. I want to move this object on a Line with the points given onToucing and dragging it. Now the problem is that I can't find any method to draw a line on points in a way that it does not produce corners. I want a smooth line with no corners.
Suppose I touch the object and drag it on the screen with the points of a square type region. But I don't want the corners in it. I want curves. Previously I am doing this by using quadTo(..) function of android to do this. All I want is a complete alternative to quadto function in AndEngine but with same functionality.

You have to stitch together the curved line from many many small straight lines.
Moving an object along a line is a very different task though. You'd want to have a look at CubicBezierMoveModifier and QuadraticBezierMoveModifier for those.
Maybe you can actually use the code in those modifiers to create your 'smooth' line.

Related

Draw nice curved path along points

How do I draw a path along some defined points in a way so that the path is nicely curved and not necessary exactly touching the defined points, except the end points where the line must be ending at the exact points? I have tried with quadTo, but that gives me jagged connections between the quadTo end/start in some situations.
To illustrate what I want I have attached this example image:
Thank you
Søren

Motion to draw numbers on android

im new to this android things. And i have to develop an application that can help an autism to learn numbers. I have a few ideas and I've been trying to learn and implement the code. But it's failed. The question is how can i apply the motion code or sprite to draw a numbers or letter? For example like this, i wanna make the penguin move through the line and draw a number nine.
There is example from mybringback.com which is the image move to draw a rectangle. How can i implement it to draw a number? Im sorry if i asking too much, i just trying to get some ideas.
I think that you should first build an utility program, in order to create the "path vector".
What I mean by path vector is simply a vector of Points (where a point has x value, and y value). And your utility should let you draw whatever you want, with a simple pen. You should draw on surface and store points when mouse is down, and ignore points when mouse is up.
Then, in the main program, you will just have to read at the path of your number/letter.
I've tried to implement something like this for the Sugar OLPC platform, without serializing path into files : I was able to draw, and to view the animation. And I used the process I've just described you.
Hope it can help you.
P.S : I used the word mouse, but you guessed that I talk about finger ...
There are various ways to achieve animation effects. One approach that is quite versatile involves creating a custom View or SurfaceView in which you Override the onDraw method. Various tutorials can be found on this; the official Android discussion of it is here:
http://developer.android.com/guide/topics/graphics/2d-graphics.html#on-view
Your implementation will look something like this:
// Find elapsed time since previous draw
// Compute new position of drawable/bitmap along figure
// Draw bitmap in appropriate location
// Add line to buffer containing segments of curve drawn so far
// Render all segments in curve buffer
// Take some action to call for the rendering of the next frame (this may be done in another thread)
Obviously a simplification. For a very simplistic tutorial, see here:
http://www.techrepublic.com/blog/software-engineer/bouncing-a-ball-on-androids-canvas/1733/
Note that different implementations of this technique will require different levels of involvement by you; for example, if you use a SurfaceView, you are in charge of calling the onDraw method, whereas subclassing the normal View lets you leave Android in charge of redrawing (at the expense of limiting your ability to draw on a different thread). In this respect, Google remains your friend =]

Android - Puzzle Piece

I'm trying to create a jigsaw puzzle app for Android. I am fairly far into the coding, and I am kind of stuck with one issue.
I need a way to change a Bitmap into a bunch of puzzle pieces. My current code simply cuts the image into rectangles, and it works pretty well, but now I need a way to create more complex piece shapes.
I had a couple of ideas:
Use a separate bitmap file that contains only black and white pixels, and use that to cut up the picture. I thought this was a pretty good plan, until I went to code it. I really had no idea how to do it.
Use a Path object to create the border. This would probably work, except I'm not sure how to keep track of the sides so that the pieces connect with each other.
Any ideas? I'm open to any suggestions.
You can use Path and/or Region to set a clip for your Canvas when drawing a Bitmap.
Take a look at this example. Here are some ways of clipping your drawing to any shape.
You could try making squares or rectangles fitted inside complex figures that can still be pieced toguether, when there's a match, the full rectangle covers the space. Imagine it like a 9 patch, when two sides match, you show the border rectangle.
This is not a explicit solution but I wonder if it would be possible to use bezier curves or paths to create lines along x and y , in conjunction with a parameter(fed with random value) to control the amount of deviation from a straight line and how much in a given distance ie; pixels/ per inch - this would be to create tongues on the pieces. Then use Region to extract the resulting shape at a given side of an intersection. Have the shape object get its center xy coordinate at instantiation and make it so that piece cannot be set if its current coordinate does not match the one it had when it was created.

Slowly Draw A Line In Android

I have a Line class composed of two Points of two ints each that I draw with a wrapper over Canvas.drawLine().
Easy so far.
I want to have that Line drawn slowly from one Point to the other. My best guess is to make a function that will dice up my Line into an list of Lines, starting from the first Point with each subsequent Line getting longer and longer till it reaches from one Point to the other. Then, I will have a Canvas.drawLine wrapper that will take that array of Lines, and iterate over them, drawing each one with a pause of some sort in between them, giving the appearance of the line "growing".
Is there something in the android libraries that already does this and/or would this be better solved some other way?
Edit: This is android 2.1
Android has libraries for creating animations. Look into tweened animations and the AnimationDrawable class.
Or maybe you can have one line with a fixed starting point and on each draw the end point increments . I believe this approach has better performance .

How to implement a DrawLine function ?

Question : Is there any better way to implement a function that draws line on the screen other than drawing circles on the input points ?
Details : I am trying to write a function which basically will draw a line.However the line will not be a regular colored line. This line will let user to copy pixels from one image to another trough that line , you can think It like "history brush" or "stamp" on Photoshop . My first thought was just get the points and draw circles on each point. Which is working but not smooth and have some bugs. The first problem is it is not working if user sweep his finger too fast. I thought it would solve problem if i can fill the dots between two points and then draw the line which is kind of work but this time drawing gets very slow. One other problem is that it never looks smooth.
Bresenham's line algorithm
Isn't the BitmapShader what you're looking for?

Categories

Resources