Friday, February 3, 2012

[android-developers] How to create moving objects on screen that are clickable.

I have an app Ive been working on where I have moving onscreen objects
that are drawn and updated each frame to a canvas which is then drawn
to a view. The objects are kept in in a listArray and when a user
clicks on the screen its registered in the view and then passed
through to the class I use as my background loop that keeps track of
everything that needs to be drawn onscreen. I have a method in that
data class that parses through all the objects and compares the x,y
coordinates to those of the onscreen click and sometimes this works
and sometimes it doesnt. Right now I limit the amount of objects in
memory to about 80 and sometimes its possible that up to 30 or more
are onscreen at once. I also have a method that goes through the
objects in memory and changes a boolean value which tells the data
class whether or not the objects should be considered active or
clickable.

My problems:

As for the method that checks if the objects are clickable, for some
reason most of the objects are always set to active when in the logcat
the numbers indicate that they should not be.

Also the way that I am trying to register screen clicks is not
reliable. Sometimes its accurate and sometimes its not and sometimes
it doesnt work at all. When I debug and watch the x,y's they all match
up and the object is marked as active which means it my data class
should handle a click associated with that object but it only lines up
half the time.

So.....I was wondering how I could go about creating a class that
possibly extended or implemented the functionality of a button or view
so that it can individually handle clicks and have its graphical
representation drawn into a view.

I have tried this by extending ImageButton however When I tried
drawing the images to the canvas and then updated it in each frame the
objects would no longer move freely and were all drawn in the upper
right hand corner of the screen. That tells me that somewhere between
my data class and the view that I had some disconnect and
misunderstanding in the way to go about handling this.

So has anyone ever handled something like this? My project is already
complex enough and I dont want to go about using some game engine or
somthing just to accomplish one portion of my app. Everything else
works great except the way I am handling screen clicks to the objects.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment