AutoParallaxBackground vertically in GLES2, AndEngine - android

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.

Related

How to make a Linear Compass in App Inventor 2

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.

Making an ImageView object in android move randomly on the screen

Fairly new at android dev, haven't got any code for this particular step yet so ill try give as much detail as possible. I'm trying to make an ImageView object move around the android view/activity, unlike java im not able to use the random generator to translate it onto an x and or y position on the frame, if anyone could point me on the right direction or more importantly have a good idea on how to do this, that'd be great.
There is a class in android called Random. And there is a function called nextInt() which can give you a random number. You can also calculate the width and height of your screen using DisplayMetrices so that you can keep the image inside the device's screen. And you can also move the ImageView. See this link.

Updating SurfaceView with multiple dirty rectangles

In the project I am working on I decided to use SurfaceView instead of a custom double buffered medium. It provides everything I need and it's already double buffered.
The problem is that it wont let me specify multiple dirty rectangles to redraw.
SurfaceView.lockCanvas(Rect) only allows single rectangle and without parameter it's pretty expensive to redraw whole thing. Another solution to call lockCanvas(Rect) for each Rect causes eye-bleeding blinking in the screen, obviously.
Do you have any solution giving the opportunity staying inside Android API field, if not do you have any external alternatives I can use?
If you know the dirty areas before you need to call lockCanvas (sounds like you might), you could calculate a "super rectangle" that locks an area that contains all of your rectangle. For example if your rectangles are (using l,r,t,b coordinates) [0,10,0,20] and [15,30,10,35], your super rectangle would be [0,30,0,35].

SurfaceView onDraw mimic of a decelerating user movement

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.

How to animate views?

I'm working on a game that in some ways is similar to Tetris (imagine a 2D array of colored squares that sometimes move around)
I am trying to animate the individual squares so they will smoothly slide down from coordinate to the next. Since I wanted to use Android's built-in tweening feature, the animation has to apply to the whole View (rather than parts of it). This doesn't work well for me because I only want some of the colored squares to slide down, and the rest of them to stay still.
The (theoretical) solution I came up with to resolve this is to make 2 Views, layered directly on top of each other. The top view is for animating squares when they need to move, and the bottom layer is for the static squares. The animation-layer is transparent until I am ready to animate something. I then simply turn on the colored square in the animation-layer, tween it to the new location, and turn it back off when done. In the same time span, the static-layer just turns squares on and off at the right time to make the whole thing look seamless to the end user.
The proposed solution is just a theory, since I haven't been able to make it work correctly yet. Since I have been having trouble, I was wondering if this is even the best way to solve the problem? Perhaps there is a more elegant solution that I am over looking? Anyone know of a better way?
If you just want to animate a single element check out the namespace android.view.animation.Animation. You can also use Drawable shapes and draw them directly. Finally, if you want a simulation then you will have to look into threading. Basically you will create a timer to update the canvas for you based on an interval. There are some other view canvases you can use as well like the GLView canvas.

Categories

Resources