How to create a scrolling background with libGDX - java

I'm trying to find a better way to create a scrolling background in android studio for a game I am making. I could just load the image twice and have them scroll side by side, but I am wondering if there is a better way to do it. The background needs to be moving at a constant rate, as the character never moves from the center of the screen. The movement of the background is completely independent from everything else.

Better way than
I could just load the image twice and have them scroll side by side
until they invented.
In this answer there is an example code.

Related

JavaFX scroll background with moving character

I'm making a game in scenebuilder and JavaFX, and I wanted to make the background scroll once the character got about half way through the screen. Could anyone give me an idea on how to go about doing this? Thank you so much!
Edit: I am able to get the picture to translate when the player moves, but the background just cuts off once the window moves. Is there a way for the window to have the whole background, but only display part of it, so when I translate the picture, it just moves on to the next part of the background?
There may be better ways to do this, but I made it to where once the player reaches a certain point by moving, the background will translate(setTranslateX method) along with the player. I also had to make the scenebuilder window I was working in big enough to encompass the whole background. This solved all my problems. Hope this helps anyone who may have a similar issue!

How to set Camera View as background with views over it?

So, I'm trying to make the background to one of my apps look "futuristic." I thought of an idea to make the screen look almost transparent yet have views over it. So, it would look something like this:
(source: rackspacecloud.com)
I'm thinking that I can use the camera to capture the background of the phone (without taking a picture, just having the real time view in the background) and then, if possible, place a semi-transparent slightly blurred ImageView over that. Finally, on top of that I can place the other views including the ImageButtons.
So, my question is how would I go about doing this? I have searched but haven't found anything relevant. It must be possible; its just how to do it? I don't expect you to give me all the code as an answer, just if you have any ideas that can help or links or code that can point me in the right direction, it would be greatly appreciated! Thanks!
It shouldn't be too hard to get started. There are samples located here that show you how to open the camera and draw the preview onto a SurfaceView. Since you want to overlay your other Views on top of the camera preview, just make sure that the SurfaceView that you are using for the camera preview is contained inside a FrameLayout (docs located here). The FrameLayout lets you insert child views and they are z-indexed using the order they are inserted. Therefore, if you insert your SurfaceView and then insert a Button of some kind it will be z-ordered in front of the SurfaceView and you can set its alpha value so that it can be more or less transparent. All that said, you will have to do some trial and error for how you want to position your views that are being rendered in front of the camera preview because a FrameLayout used on different screen sizes might position the Views differently. Also, I'd stay away from layering too many Views on top of one another because the compositor will have to figure out how to render all of it into a single window which could impact performance.

Andengine Parallax Background

Background:
I am making a 2D side-scroller.
When the player touches the screen, the player moves forward (the camera follows the player).
I cannot find an answer to this question although it seems rather straightforward.
Question:
How can I get my parallax background to scroll only when my player moves?
(example code would make things much easier for me)
I am using autoparallaxbackground but it seems that it simply just scrolls at the rates you pass in, with no regard to the camera. Moreover, I am not fully sure of the difference between autoparallaxbackground and parallaxbackground.
Any help is appreciated!
AutoParallaxBackground extends ParallaxBackground, adding one simple feature: automatically changing mParallaxValue with time. As you may imagine, if you don't need your background constantly moving, you may use ParallaxBackground as your base class, and then use setParallaxValue(final float pParallaxValue) to manually adjust the position.

How to "undraw" an image

I'm making a game in Java and I have it so that when the player presses the left arrow button, three images are drawn one after the other. But when the third image is drawn, you can still see the image drawn before it (I rotated the images to make it look more realistic). Is there anyway to "undraw" the images? I've done some research and haven't found anything specific.
No, you can't undraw an image. It sounds like the images aren't fully opaque.
Not to be an over-complication junkie, but how about using OpenGL to draw them on quads. That way you can hide, show, rotate, animate, accelerate etc so much easier. And it will all be tons faster than with Swing/AWT. JOGL library + NeHe Tutorials will quickly show you how to achieve this (really, you only need this and this). Or use Unity if you wanna do it even simpler and more portable.

Open webcam and set as background (question)

Best reader,
I'm stuck on one of my concepts.
I'm making a program which classroom children can measure themselves with.
This is what the program includes;
- 1 webcam (only used for a simple webcam view.)
- 2 phidgets (don't mind these.)
So, this was my plan. I'll draw a rectangle on the webcamview and make it repaint itself constantly.
When the repainting is stopped by one of the phidgets, the rectangle's value will be returned in centimeters or meters.
I've already written the code of the rectangle that's repainting itself and this was my result:
(It's a roundRectangle, the lines are kind of hard to see in this image, sorry about that.)
As you can see, the background is now simply black.
I want to set the background of this JFrame as a webcam view (if possible) and then draw the
rectangle over the webcam view instead of the black background.
I've already looked into jmf, fmj and such but am getting errors even after checking my webcam path and adding the needed jar libraries. So I want to try other options.
So;
- I simply want to open my webcam, use it as background (yes live stream, if possible in some way).
And then draw this rectangle over it.
I'm thus wondering if this is possible, or if there's other options for me to achieve this.
Hope you understand my situation, and please ask if anything's unclear.
EDIT:
I got my camera to open now trough java. The running camera is of type "Process".
This is where I got the code for my camera to open: http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/
I adjusted mine a little so it'll open my camera instead.
But now I'm wondering; is it possible to set a process as background of a JFrame?
Or can I somehow add the process to a JPanel and then add it to a JFrame?
I've tried several things without any succes.
My program as it is now, when I run it, opens the measuring frame and the camera view seperatly.
But the goal is to fuse them and make the repainting-rectangle paint over the camera view.
Help much appreciated!
I don't think it's a matter of setting a webcam stream as the background for your interface. More likely, you need to create a media player component, add it to your GUI, and then overlay your rectangles on top of that component.
As you probably know from searching for Java webcam solutions in Stack Overflow already, it's not easy, but hopefully the JMF Specs and API Guide will help you through it. The API guide is a PDF and has sections on receiving media streams, as well as sample code.

Categories