I'm trying to learn App Inventor 2, by implementing the tutorials and redo some in another way. I'm currently trying to make a compass similar to this, but instead of the classic rotating disk, I want to have a linear display, something like this.
Should the code blocks used in the rotating compass be altered in a way, to have the linear compass effect? By simply changing the displaying image does not work.
I'm currently using this block combination:
"when OrientationSensor1.OrientationChanged
do set Compass.Heading to get azimuth +180 (to get N always)"
Can someone give me a clue on how to implement a working linear compass in app Inventor 2, if it is possible? Thank you all in advance for your answers.
You can draw one yourself using the canvas.
Check this example how to render it, it draws the North mark only, but you can extend it easily to draw all other marks...
Before use I would try if this approach (redrawing the old position of marks) is not slower of faster than clearing the whole canvas (might perform faster).
Good luck.
Related
I'm trying to make an app where I can show some statistics.
I have some data that I collect from an STM microcontroller each 5 minutes, and with those data, i want to be able to draw a curve with this data, something like this :
https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQ56Bh-zxV5SZ0OYfaO0sLlxYCuZG0PbDtRR95opMtU80SPDx2r
So, what element in android can allow me to do so and how should i process the data i have ? I thought about using canvas, and making point then drawing the curve using those points, is that a valid method ?
And thanks
You can implement your own CustomView, which allows you to draw, like in a canvas. You can draw lines, curves and charts, but you must implement it manually, by extending and overriding View class method. But it isn't hard. The abilities of the CustomView is wide, you can even use it for simple games. So check this tutorial, if you want to know more.
But if you haven't time for it, you can use libraries, that do all work for you, just like this.
find some components to try in the Graphics section https://android-arsenal.com/free
william chart looks really cool!
I need to draw a tournament bracket in Android. I already calculated the positions for all games (i.e. an (x,y) tuple that defines where to place teams in a spreadsheet-like structure). However, I don't know the preferred way of drawing the bracket. I found an example that shows what I need:Example
My first idea was to programmatically create and fill a TableLayout. However, borders are not really supported and a lot of TextViews are needed to fill the space between games. So I am not sure if this is the best way to do it.
Does anyone have better suggestions or maybe even an example of something similar?
I'd suggest custom drawing using Canvas. That way you can draw wherever it makes sense and probably even support zooming without too much work.
The background of my game is going to be scrolling. Instead of making it scroll by moving all the objects in relation to my main character, I want to just move the camera to follow him.
I could do that with g.translate(x,y) in java but what is the equivalent in Android?
Also, if you want let me know your thoughts about if moving the camera is the best choice. Why does everyone just make the background move, and not the camera?
Thanks!
I could do that with g.translate(x,y) in java but not sure how in Android.
The equivalent would be c.translate(xPos,yPos), where c is of type Canvas.
Also, if you want let me know your thoughts about if moving the camera is the best choice. Why does everyone just make the background move, and not the camera?
Probably because they are unaware they can apply matrix transformations to drawing operations.
I have some game pawns on a screen inside of a RelativeLayout. When the user clicks the pawn I would like then to be able to drag it under there finger. I have the MotionEvent captured but can't seem to find how to adjust the orion of the pawn.
I've seen posts saying to adjust the margin but that seems questionable. I still want to do hit tests for the pawns after they've been moved and don't understand how to work with the margins in that case.
thanks!
I would recommend not using a Relative Layout at all.
A Canvas is a much better option
Or if you really want to use a layout, possibly an AbsoluteLayout is a better option
Using a layout for a game may prove unsatisfactory as you proceed. I can recommend using the free and open source game engine AndeEngine for making 2D games. The problems you have with collision detection and x,y positioning are trivially easy to implement with it. I've made 2 games and a visualization view within an app with is so far.
Check it out here:http://www.andengine.org/
You can download the demo app to your android device and see its out-of-the-box capabilities. (They include Sprites, sound, animation and more.)
This one game I made with it.
https://market.android.com/details?id=com.plonzogame&hl=en
I'm trying to create a simple Pegs game. I have drawn the 15-hole board using canvas. I have been programming a while, but games are new to me and I'm stuck on what to do when it comes to handling the pegs. I want to only use the touch screen, but it seems like it is really difficult to touch the pegs and actually select them individually. I plan on just drawing everything programmatically. What is best way on handling this? Using buttons as place holders and changing the button image? Any help would be greatly appreciated.
To be very brief, you have to keep track of the things you draw on the canvas.
I wrote some tutorials for making and moving selectable shapes on the canvas. They should help a lot.
On android it might be a little different than using mousedown, but it should give you a very good starting place.
I don't know if this will help, but you might want to write your own onTouch()function. Check it out