SurfaceView onDraw mimic of a decelerating user movement - android

I implemented a custom android SurfaceView class which draw (onDraw method) something often bigger than the available device width and height. When the user toutch the screen and move it's finger I need to implement a kind of picture movement with a speed and direction matching the speed and direction given by the user. That part I'm able to do it within onTouchEvent method. But here is my question: now I also want the speed to decelerate progressivly. I think this probably have to be coded with DecelerateInterpolator... Is there some samples or demos somewhere involving a SurfaceView, onTouchEvent and DecelerateInterpolator... ?

I was thinking of a too complicated way to address the problem. Finally found a way to solve my problem here: Smooth scrolling in Android The OnGestureListener simplify all gestures management.

Related

Android Game object scrolling

I want to create some kind of a tower defense map using a background image which is fourth as large as the screen of the device (twice horizontal, twice vertical).
my question is, how can I do this best. I'm new to Android, just got some Java basics , and want ti try out some stuff.
I want the user to scroll over the entire map using their finger and want him to zoom in via 2 finger pinch, and of course the objects (towers, sprites) should stay were they are.
I've been searching for hours for now and only found answers like " use Scrollview". I just want a food for thought to get in the right way, maybe with some examples.
You can use ImageView and set appropriate onTouchListener where you will detect pinch-to-zoom gesture using GestureDetector and change view coordinates when user drags the finger.

AutoParallaxBackground vertically in GLES2, AndEngine

How do I move an AutoParallaxBackground vertically in andengine? This is such a simple problem, but I can't find a solution to it!
I use GLES2, and I use the code that code in the example that comes with AndEngine http://code.google.com/p/andengineexamples/source/browse/src/org/anddev/andengine/examples/AutoParallaxBackgroundExample.java.
The thing is that you can't change or add vertical speed anywhere since there is no class created for the AutoParallaxBackground - it is only the parameters in the main class that you can change.
I believe there is no easy way to do that. You will have to modify it to suit your needs, which should be easy enough.
Edit: For some reason, this question popped up in my feed again, so I looked into the matter a bit more. I believe the key to make this work is to change the method onDraw of ParallaxEntity. There is a call to OpenGL's glTranslatef method which has only one of the three parameters (x, y, z) filled in, so the obvious solution would be to provide the second parameter as well.
you can set the game in landscape mode and rotate your image in such a way that it will feel like background is scrolling vertically.
otherwise use a image and set a physicalHandler to set it velocity in vertical direction and reset it to it initial position.

In game scrolling and zooming

I'm in the process of developing an android game. I have an activity that has a custom class that extends the view and where everything is drawn. Everything works fine and I have implemented a way to draw levels and it looks good.
The problem that I have is that the levels are clearly too big for just 1 screen and re-designing them is not an option as it affects the user experience. The only solution that I see is making the screen scrollable so that you can move around the rendered stuff and zooming. What I'm looking for is double tapping anywhere to zoom in and out and scrolling to move around the map.
What I need help with is how to do this. I know how to detect that the user has scrolled or double tapped but I don't know what I should do to actually zoom in and out and scroll (if a scroll is detected).
I have been looking around and saw some very simple tutorials but all of them deal with zooming in/out of an image which is not what I need. My level is rendered using many different bitmaps so I know I need to redraw all of them when updating the screen (zoom or scroll).
Is my case the same as having a single image. When it comes to scrolling I think what need to be done is calculating how much the screen is "moved" then update the and redraw the view bitmaps with the new scaled coordinates, is this correct? What about zooming?
Any help would be much appreciated. Thanks
Zooming should be easy once you have detected where you are currently at (zoom level i.e.)
image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2)-zoomControler, (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
Something like that should help you zoom out/in on the image. When the zoom levels cross a certain level, you can consider swapping out an image that is more detailed that the one you are currently rendering.

Drawing a gameboard like checkers in Android

I want to design a gameboard such as Checkers (but with the possibility of having different board tiles.
Now, OO logic and reason tell me I should have a 'tile' class which I can draw, and I draw x by y number of these on one canvas.
My question is what is the best performant way to draw such a board?
Is it reasonable to do it the way I mentioned above and re-draw on changes?
Is it better to have an image as my background and 'simulate' a board by snapping to where the tile would be?
Thanks!
I think you might benefit from checking out the snake game code for android. It has a very straight forward way of using tiles to make a game area.

Android - Detect Path of Complex Drag

I am recently getting into Android programming and want to make a simple game using 2D canvas drawing. I have checked out the Lunar Lander example and read up on some gestures, but it looks like I can only detect if a gesture occurred. I am looking to do a little more complicated detection on a swipe:
I want to make a simple game where a user can drag their finger through one or more objects on the screen and I want to be able to detect the objects that they went over in their path. They may start going vertically, then horizontally, then vertically again, such that at the end of a contiguous swipe they have selected 4 elements.
1) Are there APIs that expose the functionality of getting the full path of a swipe like this?
2) Since I am drawing on a Canvas, I don't think I will be able to access things like "onMouseOver" for the items in my game. I will have to instead detect if the swipe was within the bounding box of my sprites. Am I thinking about this correctly?
If I have overlooked an obvious post, I apologize. Thank you in advance!
I decided to implement the
public boolean onTouchEvent(MotionEvent event)
handler in my code for my game. Instead of getting the full path, I do a check to see which tile the user is over each time the onTouchEvent fires. I previously thought this event fired only once on the first touch, but it fires as long as you are moving along the surface of the screen, even if you haven't retouched.

Categories

Resources