how to start Activty randomly in Android - android

i want to implement simple game. In game there are only three pictures which will displayed to gesture on it. but i need to start game each time with different pictures.
Means if first time i play the game. it will show 2nd image to draw, then 1st to draw to draw, then third to draw. Game End
if i play game 2nd time. order of images should be changed.
Any guide ...
Thanks

In onCreate, load your three images into an ArrayList and then call Collections.shuffle(imageList). Then use the first image in the array. If you don't want to do all the work of loading the images, use an ArrayList of the image resource IDs.

Related

How to create several translate animation sequentially in android?

I' m new in anroid programming and i want to create sequential translate animations. I have ten images, what i want is as follows:
I choose image randomly and create translate animation for this image. Also, same image can exist more than one times on the screen and these translate animations shouldn' t wait other animations end. In other words, more than one animations should exist on screen at the same time.
I fight with this on two days and still I could not do what I wanted. If you give an idea or a piece of codes, i will be gratefull.
Thanks in advance.

android block map generation through text file

(Just to be clear I'm asking for guideance not for someone to program this whole thing(unless they want to XD))
Hi, I'm currently trying to make a game for android in which you can build a map out of blocks(there are several types but we'll just use walls here).
The map is going to be 100x20 blocks, in which the players can put any of the blocks available inside in any order, and it's going to be stored as a text file "Let's call it "mapFile""(this part I've already solved) in which 0's would be nothing and 1's would be walls.
Now, the problem is that when you start playing the map, the game will have to load all the blocks to make the obstacles, but I want it to do it in a specific way (mainly to make the game go smoother and doesn't have to check 2000 blocks every update):
-make groups of blocks(lines, squares, rectangles) as 1 obstacle so there os only 1 collision detection in a large amount of blocks(the difficult part is to divide a complex shape in the best way)
-divide the map into 5x5 chunks so it doesn't have to check every obstacle in order to see if it should be drawn(it would just draw the chunk in which the player is in and the ones surrounding it)
The output from this should be a 4 levels array(or something similar):
Array[Ychunk][Xchunk][obstacle][x,y,xBlocks,yBlocks,type]
(Type is just the num of the block in the map(in this case it's 1 because it's the number for wall in my app)
For now the game has:
-An array with all the obstacles info (x,y,xBlocks,yBlocks,type)
-Only updates obstacles if they are a small distance from the player(still has to check them all)
-Only draws obstacles that are inside the window(also has to check them all)
Firstly, You don't need an array with all the map info, what you need is a 2D array of tiles. The tile object will contain all the info like the image, isSolid, etc.
Secondly, You will always have the player visible, so that acts as your anchor, Only show the tiles around your player and render that to the screen. Its makes no sense to render the tiles that will not be rendered on the screen e.g., If the player is at the center and the screen renders 5x5 tiles then +/- 2 tiles of the player tile. Same goes for checking if the tile is visible No, need to check all
Lastly, Again you don't need to check the player collision with all the obstacles, only need to check collision with the tile that the player is going to move on.
Hope it helps.

How to draw or render two objects/textures on same layer libgdx(android)

I am developing a game where I want to show two objects in same layer but what is happening right now that the one which I'm writing first in render method is being shown behind the other objects.The object which I have drawn at the last in render method appears above all while rendering on screen.Please provide some code or suggestion to keep objects in same layer.For example :
batch.draw(object1,object1.x,object2.y);
batch.draw(object2,object2.x,object2.y);
As of now object 2 is being drawn above object.I want them in same layer. Object1 and Object2 are textures.
As you can see in above image,white eggs falling are appearing behind the man catching those eggs
Thank you
You will always have to render one image above another one. As you already found out, the ones that come first in your render-loop will be drawn behind the ones that come later.
If you would like to stick with rendering Textures directly, you will have to sort the drawing order somehow.
One other way is to use scene2D... Scene2D offers the Stage class, which lets you add your images to it. The same way here, the items added first will be drawn first and the others will be drawn above.
Luckily, you can change the order within scene2d quickly by changing the z-value of each item. Items with higher z-value will be drawn in front of others. This way it's way easier to reorder how you draw stuff.
As it seems in your picture, you are trying to collect eggs within the basket, so you will have to split your chicken and basket into two different images. The chicken will be drawn first (after the background of course) and then the eggs. Coming last in the draw order you need to render your basket. This way the eggs will be falling down in front of the chicken, but will be rendered behind hte basket, so it looks like they are landing into it.
Hope that helps...

GoogleMaps GroundOverlay blinks my images

I'm using GoogleMaps in my Android app, and I want to display an animated radar image on the map.
I have an array of 6 Bitmaps. When the user hits play, the map loops through displaying each of those images on the map.
This is working, but when transitioning between the images, if I don't call GoogleMap.clear(), the images just get continually stacked on top of each other.
If I do call GoogleMap.clear(), I get a horrible blink. I want one image to remain on the map until the next one is displayed.
Is there a good way to do this?
Is there maybe a double-buffering option for GoogleMaps?
Oh, actually, what I ended up doing was extending the GoogleMap class and overriding the onDraw function to my liking.

Using ananimation at a random location on custom view

Hi, In my app, I'm trying to make an explosion animation occur, wherever an enemy is destroyed on my custom view. What is the best way to accomplish this, because I know you can't draw an imageView onto a canvas using onDraw? How do I get the animation to play at the location of the enemy?
You could first create a list of exploding and show them one after the other using a thread and handler. For example, if you created 10 images, namely explosion-1.png, explosion-2.png...explosion-10.png then, using canvas.drawBitmap, you could make them appear one after the other until the sequence finishes using a loop.

Categories

Resources