Wednesday, November 30, 2016

ViewPort problem with Starling

Following a tutorial with Starling, I fell in a little problem with the viewPort properties, where initial coordinates were wrong respectively with the top left corner of the screen. No matter which device I choose, Android or iOS (even in physical devices, not only in an emulator), the content still went bad, just like the image below:


To fix this issue, I just added width and height properties at the SWF directive in the main file:

[SWF(frameRate="60", backgroundColor="#000", width="480", height="800")]
public class Starling_walking_guy extends Sprite

That's all. the viewPort was fixed and the content now is centered.

UPDATE: So, it was necessary to add the two first lines in the Class constructor, I mean, Starling_walking_guy class:

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

Tuesday, November 22, 2016

XMLHttpRequest on iOS with a Phonegap application

It's supposed to be a normal job converting a Javascript/HTML into an iOS mobile application with Phonegap. But, I was wrong.

Inside the app, I used a very useful library called "LoadTemplate" (I couldn't find out the Github URL again) to load template files to my application (through Handlebars), and that worked for months on any browser and Android systems, but now it's necessary to put it on iOS, a simple job, and in fact, it was. The application ran from the first time using Xcode, but something went wrong: the template files didn't load.

No matter what iOS version I played it on the emulator, or what kind of permissions the folders are set at, it didn't work.

So, I traced the part of the library that made the load through the XMLHttpRequest object, and I found out a weird behavior.

The lines in particular are:
req.onreadystatechange = function(){
    if (req.readyState == 4 && req.status == 200){

In a simple verification in iOS, the property status is always set to 0, at least for me, so, I remove that property and everything returned to the normally.

Finally, the code stayed like this


    req.onreadystatechange = function(){

        if (req.readyState == 4){