I don't know how to explain this.
But take Android desktop as an example.
When you move your finger, you move the whole desktop, until a point that you're on the next desktop. So as you can see, if you move the screen, for about 51% to the right, when you leave your finger off the screen, it will go to the right screen, and if you just moved the screen 40ish percent, it will be back on the same screen.
How is this pattern called?
Some sort of "predicting" users movements.
Maybe you are talking about the Location Within pattern:
Problem:
You must describe the location within a series of screens which
contain alternate views, or which continue the display of a set of
content.
Solution:
When several screens of similar or continuous information are
presented with an organic access method, an indicator is usually
required so the user understands their position within the system.
Other sources might call such a thing "carousel" or "slideshow".
Updated answer:
After reading more carefully, "Location Within" might only reference the page position indicators that show which screen is currently in view. Perhaps just the Slideshow or Film Strip patterns describe more exactly what you mean.
As FoamyGuy pointed out in a comment, ViewPager is the way to implement "slideshows" in Android.
Additionally, ViewPagerIndicator provides flexible options to display the page position indicators ("Location Within" pattern)
Related
I am using LibGdx to develop a game. For Now I am not using scene2D. I am struck up in increasing the levels of the game as I do not have the scrolling screen.
I like to design a a scrolling screen as it is in many games which are level based (for ref, lets say Candy crush). Could you please point me a example on how to have such a scrolling screen to show a bigger area where I can show many levels.
Thanks is Advance !
Using the Scene2D function is not necessary for this and is more for GUI implementation and different screens. The Scroll pane really shines when creating reading content that does not fit your phone. I do advice to start learning Scene2D to create MenuScreens and UI though.
What Candy Crush "simply" does is having multiple backgrounds that are placed next to each other and tile seamlessly. They use buttons in the correct place for levels. By dragging a finger across the screen the camera will move in that direction. For the movement from one level to the next there is probably something like a spline in play.
It is important only to draw the background tiles and buttons that are actually visible on the screen if you have many. Since these have fixed positions and you know your camera area and position you can calculate what to draw and what not. Just drawing everything each frame is likely to slow down your fps.
You can do a search on:
Tilemaps, for you backgrounds but you probably want them in just one direction so a simple 1D array would suffice.
Dragging, to move your camera. Here I gave a basic explanations on how I do it.
Splines, are a bit tougher and you do not really need them. They could be used to animate or move something along a curve.
Thats all, expecting you know how to create something like a button (click a sprite).
I'd like to create a custom map. It should be or look like one picture, but according to the part of which the user clicks, it should move the user to a different location (i.e. start a different activity). I've seen it done in several games but I don't know how to do it myself.
The part of the picture should have non-geometrical borders (obviously it would be easily done with many square images). Sadly, I don't even know what term describes what I want to do so I wasn't able to find any helpful tutorials or discussed topics.
Example:
Picture: http://i236.photobucket.com/albums/ff40/iathen/mapEx.png
If the user touches the purple slide, (s)he should be leaded to activity_1
If the user touches the blue slide, (s)he should be leaded to activity_2
If the user touches the green slide, (s)he should be leaded to activity_3
In my experience there are 2 main (most used) ways to achieve this.
The first (my favorite):
Get the data from a PNG
You should write multiple layers to a canvas. These layers constitute your "zones" (blue, green, purple in the image). To obtain the data of these areas, you get it from PNGs (with transparencies off course) to write the canvas with whatever you want. You must store the values where there can be a tap from the user (non-transparent areas). Notice that this values can be scaled up/down depending on the map size, screen resolution, map dimensions, etc.
Once you've written the layers to the canvas you should check for a match of the user tap and the stored areas you have. You should take into consideration here the order in which the user tap is processed in your code. For instance, in your image, the purple layer is on top so it must be processed first, the blue as second, and the green as the last one. This way you can have an "island" inside a bigger area.
The second way:
Generate the boundaries programmaticaly
I think this solution is self-explanatory. The only I've faced with this variant is that when the surfaces boundaries get messy, it's really complicated to generate the proper equations.
EDIT:
Using the first approach you can employ multiple PNGs to load data or use a single PNG with data coded into the bytes (i.e. RGB values). It's up to you to decide which one to implement.
Hope it helps!
Since a touchscreen itself isn't very accurate, your collision detection for the buttons doesn't need to be either. It would be a waste of time to try to make a complicated collision detection algorithm to detect a touch within those weird shapes.
Since you are making a game, I assume you know how to handle custom touch events, as well as canvas (at least). There are many ways to do what you want, but in the specific example image you linked is kind of a special case.
You could create a giant bounding circle around the three blobs, and then check if the user touched within the bounds of the circle (ie check if the distance from the touch to the center of the circle is less than or equal to the radius). Once you determine that it is, you could check which section of the circle it falls into by splitting it up into 3 equal sections. Requires some math, but shouldn't be that complicated.
It wouldn't be a perfect solution, but it should be good enough. Although, you might have to change the buttons a little so they aren't so stretched out horizontally, otherwise a bounding circle wouldn't be ideal.
Personally, in my games I always have "nodes" that represent the visual elements of the game, such as buttons. Instead of using a large image like you are doing, I would create separate images for each button, and then check their collisions with touch events independently. That way I could have each button check with their own individual bounding circles, or, if absolutely necessary, I could even have custom algorithms for each individual button.
These aren't perfect solutions. If you do want a pixel-perfect solution, you'll need to implement some polygon collision detection algorithms
One thing to consider is screen size and ratio. The only constants you should use are for percentages.
I see that the latest version of GMail has a slider. Basically, I can slide an entry to reveal what's behind it. I have been needing to do the same thing. I have tried to use onTouch to track displacement, etc. But my approach is very jiggery and the actual scrolling lags quite a bit. Does anyone know how to accomplish what I seek with horizontal scrollView or such? Or better yet, how GMail is doing theirs?
An important aspect of mine is to have some snap action. So if the user has scrolled to greater than X, I am to continue sliding to the left for her, for example, until the front image reaches the left edge.
Or could I use a navigation drawer to accomplish this? I don't think so as yet, but maybe someone has done it. I have been working on this for about a week now, and all my attempts are not quite there.
There are a couple Dev Bytes that discusses how to implement this from scratch (see "DevBytes: Animating ListView Deletion" and "DevBytes: Animating ListView Deletion: Now on Gingerbread!"). Alternatively, you could look at SwipeListView.
I am writing a DAW-style app and need to implement the side-scrolling timeline common in such programs. In other words it should appear to the user as though they are scrolling through a very large bitmap, several of them actually for the different tracks, seamlessly. Obviously I will have memory issues if I do it with a single very large horizontally-scrolling View, but that needs to be the effect the user sees. Right now I have a custom View for each track and drawing the wave into its Canvas.
I have thought of constructing three Views, left, active and right, and simply swapping out new data when the left or right one is scrolled to in time to be ready for the next screenfull. I think something along these lines is going to be the final solution, but I am not sure what would be the best way to implement it. Should I run a service in the background that watches for and updates the offscreen views, would that be the best way to accomplish this? I haven't used services before. Or is there a more direct way of doing it, attaching some code to the view to execute automatically?
Any suggestions would be appreciated.
I'm fairly new to the Android platform and was wondering if I could get some advice for my current head scratcher:
I'm making an app which in one view will need an image, which can be scrolled on one axis, with a load of selectable points over the top of it. Each point needs to be positionable on the x and y (unlikely to change once the app is running, but I'll need to fine tune the positions whilst I'm developing it).
I'd like to be able to let the user select each point and have a graphic drawn on the point the user has selected or just draw a graphic on one/more points without user intervention.
I though for the selectable points I could extend the checkbox with a custom image for the selected state - does that sounds right, or is there a better way of doing this? Is there any thing I can read up on doing this, I can't seem to find anything on the net about replacing the default images?
I was going to use the absolute layout, but see that it's been depreciated and I can't find anything to replace it.
Can anyone give me some code or advice on where to read up on what I need to do?
Thank you in advance
This really feels like something you should be doing with the Canvas and 2D graphics, rather than trying to twist the widget framework to fit.