I'm having an issue with libGDX's otherwise great scene2d ui library when running my app in landscape mode. My program works as expected in both the android simulator and the desktop environment, but when I run it on the iOS simulator or a real device, the main menu is drawn as if the phone were still in the portrait orientation, and the just cropped to fit in a landscape view. At first, I assumed I had just screwed up, as I'm still learning the api, but the app works just as expected on android. I have configured my game to run in landscape mode on both iOS and android.
On the android simulator, the menu works as expected. The simulator is in landscape orientation, and properly displays the menu.
On iOS, the menu is off center and unclickable.
I pretty sure that the problem has to do with landscape mode, because everything works fine in portrait orientation. Here's my code for the MainMenuScreen, which extends a ScreenAdapter.
package bakpakin.techgame;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.*;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
/**
* Created by Calvin on 9/25/14.
*/
public class MainMenuScreen extends ScreenAdapter {
private TechGame game;
private Stage stage;
private Skin skin;
private Table table;
public MainMenuScreen(TechGame game) {
this.game = game;
}
#Override
public void show() {
this.stage = new Stage();
this.skin = new Skin();
skin.add("default", Assets.superScript48);
skin.add("title", Assets.superScript128);
TextButtonStyle textButtonStyle = new TextButtonStyle();
textButtonStyle.font = skin.getFont("default");
textButtonStyle.pressedOffsetY = 4;
skin.add("default", textButtonStyle);
Label.LabelStyle labelStyle = new Label.LabelStyle();
labelStyle.font = skin.getFont("title");
labelStyle.fontColor = Color.CYAN;
skin.add("default", labelStyle);
// Create a table that fills the screen. Everything else will go inside this table.
table = new Table();
table.setFillParent(true);
stage.addActor(table);
final TextButton play = new TextButton("Play", skin);
final TextButton about = new TextButton("About", skin);
final TextButton quit = new TextButton("Quit", skin);
play.addListener(new ChangeListener() {
#Override
public void changed(ChangeEvent event, Actor actor) {
Assets.button1Sound.play(1, 1, 0);
}
});
about.addListener(new ChangeListener() {
#Override
public void changed(ChangeEvent event, Actor actor) {
Assets.button1Sound.play(1, 1, 0);
}
});
quit.addListener(new ChangeListener() {
#Override
public void changed(ChangeEvent event, Actor actor) {
Assets.button1Sound.play(1, 1, 0);
Gdx.app.exit();
}
});
final Label title = new Label("My Game", skin);
VerticalGroup vg = new VerticalGroup();
vg.pad(60);
table.add(title);
table.row();
table.add(vg);
vg.addActor(play);
vg.addActor(about);
vg.addActor(quit);
Gdx.input.setInputProcessor(stage);
}
#Override
public void render(float delta) {
GL20 gl = Gdx.gl;
gl.glClearColor(0, 0, 0, 1);
gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
stage.act(delta);
stage.draw();
}
#Override
public void dispose() {
stage.dispose();
skin.dispose();
}
}
IOS 7 or 8? I heard there are some iOS 8 rendering issues
Apparently this is fixed in the latest snapshot (see github.com/libgdx/libgdx/issues/2386). With a new stable release promised real-soon-now, I'm sure the fix will be folded in if you're not brave enough to run snapshot builds
Related
I'm trying to implement Unity Ads on my game that I'm planning on deploying on iOS, but for some reason they are only appearing in the editor (where it says "Everything Seems to be Working!") but every time I build to my iPhone 5s, the ads don't pop up.
Here is my script (to activate it I just attached it to a game-object in my scene):
static int loadCount = 0;
void Start()
{
if (loadCount % 3 == 0) // only show ad every third time
{
ShowAd ();
}
loadCount++;
}
public void ShowAd()
{
if (Advertisement.IsReady())
{
Advertisement.Show();
}
}
Any help is appreciated!
I recently received a support ticket that some of our web app's functionality is crashing safari on the iPad. This functionality had no problems prior to the latest iOS 7.0.6 update. We have a few GWT ValueListBoxes that change the DOM when their values are changed. Prior to making the changes, we present the user with a Window.confirm() message to inform them of the effects the changes will have and ask whether or not they would still like to proceed. Since the update, the confirm choices do nothing and Safari crashes. This is only happening on the iPad. The functionality works fine on the desktop browsers (IE, Chrome, Firefox, Safari and the Chrome mobile emulator), but crashes safari on the iPad. Is anyone else having this issue?
Here's a screenshot of the crash:
And here's a sample of the code:
this._view.isPrimaryFoodGen().addValueChangeHandler(new ValueChangeHandler<Boolean>()
{
#Override
public void onValueChange(final ValueChangeEvent<Boolean> event)
{
#SuppressWarnings("unchecked")
ValueListBoxWithOldValue<Boolean> vlb = (ValueListBoxWithOldValue<Boolean>)event.getSource();
if (confirmQuestionChange() ){
changeGroupAndQuestions(CONSTANTS.PRIMARY_FOOD, event.getValue());
}
else {
vlb.setValue(vlb.getOldValue());
}
}
});
public boolean confirmQuestionChange()
{
if (!this._view.isImageCriteriaQuestionsVisible())
{ //questions aren't currently visible
return true;
}
boolean confirmed = Window.confirm("Changing this response will delete image data already collected. Do you wish to proceed?");
return confirmed;
}
Any help on a solution for preventing the crash on the iPad would be greatly appreciated. I have tried focusing on another element prior to calling Window.confirm() in hopes that the overlay and the ValueListBox choices would be removed to stop any JS conflicts, but it hasn't worked.
Am I at the mercy of Apple until the next update fixes this?
Or is there a viable solution?
OK, so it turns out that since I couldn't find a fix to continue using Window.confirm(), I had to implement a solution by changing the onValueChange() and confirmQuestionChange() methods to use a manually created DialogBox instead of Window.confirm(). It isn't the optimal solution, but Safari does not crash on the iPad anymore and users can get their work done. Here are the code changes:
this._view.isPrimaryFoodGen().addValueChangeHandler(new ValueChangeHandler<Boolean>()
{
#Override
public void onValueChange(final ValueChangeEvent<Boolean> event)
{
confirmQuestionChange(CONSTANTS.PRIMARY_FOOD, event);
}
});
public void confirmQuestionChange(final String question, ValueChangeEvent<Boolean> event)
{
final ValueListBoxWithOldValue<Boolean> vlb = (ValueListBoxWithOldValue<Boolean>)event.getSource();
if (!this._view.isImageCriteriaQuestionsVisible()) //questions aren't currently visible, can change them no problem
{
changeGroupAndQuestions(question, vlb.getValue());
}
else{
//the following fix was put in place for issues with Safari on the iPad OPS-76
final DialogBox dialogBox = new DialogBox();
dialogBox.setHTML("<center>Changing this response will delete<br />image data already collected.<br />Do you wish to proceed?</center>");
dialogBox.setAnimationEnabled(true);
Button yesButton = new Button("YES");
Button noButton = new Button("NO");
HorizontalPanel dialogHPanel = new HorizontalPanel();
dialogHPanel.setWidth("100%");
dialogHPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
dialogHPanel.add(noButton);
dialogHPanel.add(yesButton);
noButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
vlb.setValue(vlb.getOldValue());
dialogBox.hide();
}
});
yesButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
changeGroupAndQuestions(question, vlb.getValue());
dialogBox.hide();
}
});
// Set the contents of the Widget
dialogBox.setWidget(dialogHPanel);
dialogBox.setPopupPosition(180, 425);
dialogBox.show();
}
}
Here's a screenshot:
As you can see, the ValueListBox options close before the DialogBox appears and the screen no longer locks.
This is the code i m running in my blackberry bold 9900 simulator but the BrowserField just shows the blank white screen and nothing. Is there any problem with my simulator or some setting needs to be done in it. Thanks in advance for help.
public class StartUp extends UiApplication
{
public static void main(String[])
{
StartUp start=new StartUp();
start.enterEventDispatcher();
}
public StartUp()
{
MainScreen screen = new MainScreen();
BrowserField browserField = new BrowserField();;
screen.add(browserField);
pushScreen(screen);
browserField.requestContent("http://www.google.com/news");
}
}
Verify if you have a network connection in your simulator, see this development guide article.
I want to do application which will not change UI even if screen is changed to portrait or landscape direction. How to do that?
I have made a static method in one of my library classes:
public static void disableOrientationChange()
{
// force app to use only portrait mode
int directions = Display.DIRECTION_NORTH;
UiEngineInstance engineInstance = Ui.getUiEngineInstance();
if (engineInstance != null)
{
engineInstance.setAcceptableDirections(directions);
}
}
The trick is that this code only works for screens created after running it. So you must run the code BEFORE you show your first screen.
I call this method from my Application.main(String args) method, just before the call to enterEventDispatcher().
public static void main(String[] args)
{
MyApp app = new MyApp();
/*
* BlackBerry OS 5.0.0
* Disable screen orientation changes
*/
ScreenUtils.disableOrientationChange();
// enters the event processing loop thread if required
if (!app.isHandlingEvents())
{
app.enterEventDispatcher();
}
}
you can use this code to set the orientation to portrait. After that even if the device is held in landscape, the orientation wont change.
Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);
I need to display a splash screen when I app instantiate, I wrote a class for splashScreen based on blackberry develpers knowlwdebase (link).
And its invoked from my following class.My problem is the splashscreen appears only after a deley,How can I solve it,If any one have idea Please help me,Thanks
class Test extends MainScreen{
Test(){
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run() {
UiApplication app=(UiApplication)getApplication();
Bitmap image = Bitmap.getBitmapResource("splah.png");
ListView listView = new ListView();
new SplashScreen(app, listView );
}
}
Try synchronized (UiApplication.getEventLock()). It is faster than invokeLater.
Test(){
synchronized (UiApplication.getEventLock()) {
UiApplication app=(UiApplication)getApplication();
Bitmap image = Bitmap.getBitmapResource("splah.png");
ListView listView = new ListView();
new SplashScreen(app, listView );
}
}