Help with making objects touchable on Android using canvas - android

I'm trying to create a simple Pegs game. I have drawn the 15-hole board using canvas. I have been programming a while, but games are new to me and I'm stuck on what to do when it comes to handling the pegs. I want to only use the touch screen, but it seems like it is really difficult to touch the pegs and actually select them individually. I plan on just drawing everything programmatically. What is best way on handling this? Using buttons as place holders and changing the button image? Any help would be greatly appreciated.

To be very brief, you have to keep track of the things you draw on the canvas.
I wrote some tutorials for making and moving selectable shapes on the canvas. They should help a lot.
On android it might be a little different than using mousedown, but it should give you a very good starting place.

I don't know if this will help, but you might want to write your own onTouch()function. Check it out

Related

How to create complex moving/touchable animations in Android Studio?

Does someone know how to do complex animations in Android Stuido such as Select-Seats-Payment Animation?
I know there is Open GL for creating Spirtes and so on but do you actually do this kind of complex animations with Open Gl? And also wouldn't that be laggy?
Any hints would be very appreciated! Thanks in advance!
I guess you want to create the flight zoom and rotate animation.You don't need to go to OpenGl level. You just need to learn canvas. All the seats and the flight itself is simply plain design. So no need for bitmaps/images to create them. Create all seats by drawing them and treat them as like separate objects and give them their own properties like click listeners(Clicks should be handled by onTouch() function of the customView). But it takes lots of practice in canvas API of Android.

How to drawing bezier curve with animation in Android using cubicTo?

I've been searching for simple example and solution in stackoverflow, but I couldn't find one. So, I'll ask a new one and my apologies if this question have been asked before.
First, I want to make an apps that draw a Japanese Kanji Stroke using bezier curve, I already have 1 starting point, with 3 curves, for example :
M(11,54.25)
c(3.19,0.62) (6.25,0.75) (9.73,0.5)
c(20.64,-1.5) (50.39,-5.12) (68.58,-5.24)
c(3.6,-0.02) (5.77,0.24) (7.57,0.49)
What I have been found during searching in internet is, it looks like I could use Path.cubicTo() and use canvas as to draw it (using canvas.drawPath()).
And also, I want the canvas to draw it using animation at given frame rate or speed.
Anyone could give me a simple example or maybe some clue or anything that I can work with ?
Thanks !
You can find great example here:
http://www.jayway.com/2012/08/29/creating-custom-android-views-part-3-animating-your-custom-views-smoothly/
The sources are also there so it's very easy.
Your approach is good- you basically use Path.cubicTo in your View's onDraw and invalidate views while changing input coordinates. You can do it in another thread or create ValueAnimator and invalidate view in AnimatorUpdateListener.

Android Canvas inside of each row of listview without lag

I realize this is a highly custom implementation, but im porting a app over from IOS to Android that has these photos in a listview that the user needs to be able to fluidly whipe off in one fluid motion. The only thing I could find on github anywhere close to this was this: https://github.com/winsontan520/Android-WScratchView/tree/branch_image_overlay
but,this uses a surfaceview and when implemented in my listview its EXTREMLY laggy. I did a bit more research looking for something along the lines of a photoshop eraser and came across some stuff using canvas to accomplish something similar with a single drawing area , but im not quite sure if what I want to do is possible in Android and if spending the next day or two learning canvas would be a worthwhile investment or if im barking up the wrong tree. Is this the way to go to accomplish my goal?
SurfaceView is actually a Canvas implementation that has some native improvements like duble buffering, vsync and such. But using it in a ListView is an overkill.
I say take your chance with a custom view. Just override the onDraw(Canvas canvas) and draw whatever you want. Learning canvas is pretty easy if you have some basic graphics knowledge.
As an another implementation idea, If you don't need all of your Views inside the ListView interacable when scrolling, you can use static images in ListView and when user touched one of them you replace static image with SurfaceView and go on. This way you only need one SurfaceView.
Also did you used the ViewHolder pattern ( http://developer.android.com/training/improving-layouts/smooth-scrolling.html ) when implementing the ListView? Might help with the performance but I'm not sure if it can be implementable in your case.

What is the best approach for drawing and animating images on Android

Im experienced iOS dev but new to Android dev and asking some newbie questions here...
I have to make a app where I have a background image and I then place some other images on top of that, and also onto those images I have to place different "glow" images that flicker (opacity on/off), and I need good control on positioning all those images. Now there is not some high performance goal here, and its not many objects, its not really a game.
What is the best approach for this? Can I use ImageView's for this or will it be better to use a Surface and custom draw in a thread?
And please, what ever you suggest, can you give a link to a good tutorial on the approach (ImageView or custom draw), I need all the help I can on this project with its crazy deadline.
Thank you
Søren
In my experience:
if its mostly static you should stick to XML and stuff like ImageViews etc
if its simple animations, the predefined android classes are fine and somewhat easy to use
if you want real custom then drawing with canvas is the way to go
You can extend View and override the onDraw method or create a SurfaceView which has better performance but is not that easy to use.
(sorry i dont have any tutorial links)

How to draw letters by dragging finger onScreen

I am new to Android..Please anybody help me..I am working on application for kids..I want to make the user to draw above the text like A,B,C ..At the same time I want to make the user can only draw above the letters not outside of those letters..And while drawing I want to give the different colors..I have searched a lot but i didn't get exactly what I want..
If you are new to Android I suggest you learn the basics first (web tutorials or books). If you are new to Java you should also have a look at this. Once you are starting to get the hang of both, you can move on to creating an application like this (which sounds tricky).
Just to get you started, I'd advice you to have a look at the SurfaceView class, which will allow you to render to the screen.
PS: Just a reminder, this site is for program specific questions, not vague questions. :)

Categories

Resources