Porting a java game to android - java

I have a basic noob question which I'm sure many of you can easily answer.
I am finishing up a game I am making in java. It is a windowed game, and I am not using any flow layouts. In other words, I am placing the images and buttons myself using setbounds, etc. I want to port this game to android, where it will be full screen.
I have heard that I should use Eclipse or libgdx to do this. My question is, will my game still retain its dimensions on an android phone? Will it scale to a viewable size
or will I have to adjust everything on my game to make it fit?
I'm also wondering how difficult is it to port it.
Thanks for your help.

will my game still retain its dimensions on an android phone? Will it scale to a viewable size? Or will I have to adjust everything on my game to make it fit?
Yes. If you use a camera in libgdx (which you should!). It will scale everything to fit the screen, stretching it. But you can easily set it to keep aspect ratio and show black bars at the sides. For example this.
I'm wondering how difficult is it to port it.
The library is very easy to use, it depends on your current game design/implementation. But yeah, it must be very easy.

If you are not using libgdx at the moment it will be hard to port it to libgdx. May be a big part of your game has to be rewritten. But if you are allready using libgdx for the desktop version of your game you only have to handle the different input type (most times on android phones you use touch input instead of keyboard). If you are using libgdx but you are not using camera, you should definitly modify your game to use camera. By doing this you do not depend on screen aspect ration (One possible solution). Also you should then keep in mind, that on android the method pause() is called when call is incoming or homebutton is pressed and resume() is called when user returns to game. Hope this helps.

Related

Fullscreen Frame Borders in Java LWJGL

I want to make a game with Java and LWJGL. In many videogames you can see the black fields at the top and the bottom of the display, which is used to size the display in the resolution the game can work with.
I searched for this two days, but maybe I used wrong keywords.
So is there any possibility I can make this with LWJGL. Maybe a method I can use?

How can i create different directories to support diffrent resolutions for Android in LibGDX?

I have been trying to support multiple screen resolutions for Android, i have tried all the viewports but non of them fit my game well, my game is like Asteroids where the ship wraps around the world when it reaches the edge of the screen. if i use Fitviewport on some resolutions the ship wraps around before it reaches the edge of the screen and if use Fillviewport the ship goes out of the screen instead of wraping around, if i use Stretchviewport the game looks horrible the other viewports are not working well either, So i think the only solution for me would be to create diffrent assets for diffrent resolutions, now how do i go about doing that?
try using ExtendViewPort and provide the minimum and maximum viewports your app should support. The maximum size will limit how much the world is extended and the minimum how much shrink
I've never used LibGDX, but it sounds like your problem is with different aspect ratios, not different resolutions.
So if I were you, I'd try Fillviewport, and then I'd calculate everything manually to make sure to reset the location of the ship (and any other objects) to the other side when it collides with the edge of the screen.
This is not super easy, so this is why a game like PewPew will use a square frame for its asteroids-mode instead.

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 get similar tweenmax affect you see in flash using interpolation in android java?

I have an object that continuously follows the users touch coordinates. I would like to make it so the object has an easing effect.
by which i mean, the object has a start point and when the user touches the screen, said object would move to the users touch coordinates. which it already does but it jumps to the coordinates. i want a controlled transistion from point A to point B.
this easing or tween affect would need to happen on every frame if the user dragged or swipped their touch coordinates.
i have been reading about interpolation and animation affects for the android sdk but i dont really understand how to implement them on an object and not a view. or continuously as well.
any direction would be great. thank you!
I built a complete tweening engine for Java. It doesn't allocate anything dynamically so it's totally safe for Android (I made it primarily to develop games on Android).
http://code.google.com/p/java-universal-tween-engine/
Your tween would look like:
Tween.to(yourObject, Type.POSITION, 1000)
.target(touchX, touchY)
.ease(Quad.OUT)
.start(aManager);
I used a similar syntax as the TweenMax engine, so you shouldn't be lost too long :)

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