I have some C# experience, but im completly new to java. So i have some questions for someone with more experience.
I would like to draw a simple game board of for example 10x10 grey boxes. So i figured a 2d array might be useful:
int gameBoard[][] = new int[10][10];
For each board i would like to draw a grey rectangle, and place it it some control to be rendered on the device.
I suppose this can be done with an instance of Paint and Canvas
And this is where im stuck at the moment. What controls are best suited for this? Any help is much appreciated.
Take a look at this link, it explains very clearly the differences between canvas, paint and bitmap and finishes with an example of an app that draws a colored rectangle and displays it in an ImageView. Hope it can be useful.
Better use GridView or TableView for the box structure. Further , if you will wand something to crawl over boxes, it will be another activity on the deskboard one. There you'll maybe use bitmaps. THis way you will save heaps of time.
I would probably go with the TableLayout, which I guess is what Gangnus meant with TableView
There is a tutorial for TableLayout here:
http://developer.android.com/resources/tutorials/views/hello-tablelayout.html
In your case you would put 10 views in each of 10 rows. You can chose to create them in the xml file or from the java file.
Related
For reference the effect I'm going for is this:
I'm working in Processing 3, NOT p5.js.
I've looked around processing forums, but i can't find anything that works in the current version or doesn't use PGraphics and a mask which from what I've read can be expensive to use.
My current ideas and implementations have resulted to drawing shapes around the player and filling the gaps in with a circles with no fill that has a large stroke weight.
Does anyone know of any methods to easily and inexpensively draw a black background over everything except a small circular area?
If this is the wrong place to ask this question just send me on my way I guess, but please be nice. Thank you:)
You could create an image (or PGraphics) that consists of mostly black, with a transparent circle in it. This is called image masking or alpha compositing. Doing a Google image search for "alpha composite" returns a bunch of the images I'm talking about.
Anyway, after you have the image, it's just a matter of drawing it on top of your scene wherever the player is. You might also use the PImage#mask() function. More info can be found in the reference.
I need to create a chart like this picture bellow in Android.
and I am already aware of MPAndroidChart and AndroidHelloCharts libraries. but none of them are capable of drawing such thing.
do you know any way to create a chart like this?
please explain and at least suggest me some tutorials or articles that are related to what I am about to do.
thank you
Its actually pretty simple to create your own bar chart.
First you need to use drawRect to draw a rectangle.
And then drawText to draw text below the rectangle.
You may have noticed that both methods take a paint object as the parameter , you can think of the paint object like a brush. So you set the color to the brush and draw different elements.
I have written about it
here
I have already coded a game which is played on a 2D grid. Now I just need to make a GUI to display it.
Each cell in my grid has an attribute that goes along with an image. For instance, if cell (0, 0) is water, I want to display an image of water in that pixel. I have already made images for each attribute (e.g. image of a character, water, land, etc.). I just don't know how to make the GUI.
It's a simple 2d map where each pixel (cell) is a specific texture/character/item. I also would like the character to move around, that is it.
Any resources or help would be appreciated. I've tried searching for a tutorial but they all seem so complicated and use Color to fill in their map instead of images.
Thanks.
Here's a 2D platformer that makes use of a simple thread, drawing, gamestates, etc. Although you might not need the full extent of everything it has, you might find interest in the main thread logic, etc. I believe he has a link to the source code in the comments. YouTube
I've been looking around for a simple way to put graphic on the screen in android for a while now and I'm really confused.
I've a simple game written in java with swing for graphics and that's all I really need as the graphics doesn't really matter in this project.
Now we want to rewrite it so it works on devices with android and honestly I can't find a simple way to just put a image on the screen.
I'd love to avoid using complex game engine because I just don't need it. All I want is a possibility to draw an image (or 50 images) on x,y given by me and refreshing a screen every 100 milliseconds and I thought I'd be the first thing I'd learn in any android tutorial but well... it's not. Of course I know how to draw an Image with .xml but I need something more automatic - for dozens of images changing all the time.
So what is the best to do this? Isn't there really any way to do it with just some android built in function? If not what engine should I use just for the simplest things I mentioned?
A simple but not necessarily very clean way to do this would be to create an xml layout that is just an empty RelativeLayout.
Then you could create your images like this:
ImageView image = new ImageView(this);
image.setLayoutParams(new RelativeLayout.LayoutParams(IMAGE_WIDTH,IMAGE_HEIGHT));
//Other setup code for your image goes here
myRelativeLayout.addView(image);
This should give you an image of the specified width and height that sits at the origin.
Then you could move the image into position like this:
image.setX(IMAGE_X_POS);
image.setY(IMAGE_Y_POS);
When to do the moving is up to you as it will depend on when you know the positions that need to be moved to.
I am starting to develop an android trading card game, I have love to ask a couple of questions and recieve some feedback from more experienced developers, lets get on with my questions.
1 - How can I create a board where I can lay cards down? like really I have no idea... maybe fill a simple 'xml layout' with a background image that already has the fields where the cards should be.
2 - How can I implement a way for the cards to listen for like drag from my hand and drop in the field.
Even if I will draw the frames already inside a background image, how would the cards sit exactly in these frames?
Tips? ideas? anything that comes in mind will really help me!
1- You can use some ImageView/ImageButtons to show the cards. Using a relative layout you can show the cards in the position you want (even overlapping)...
2- For the movement, you can drag the image to a zone that you define. This post can help you with that: how to drag an image by touching in android?
Hope it helps ;)