No text in Game View?

266 views
Skip to first unread message

Paul Goodings

unread,
Aug 31, 2021, 8:38:03 AM8/31/21
to DroidScript
First, I must say thanks for the fantastic app.  It's a long time since I did any programming and I am enjoying the challenge! 

I found the Dino game tutorial very helpful. One thing I am puzzled about is that the gfx.CreateText function is producing an error message. I have checked the syntax carefully but I cannot get it working. Tried creating a standalone programme to display text, but no luck. Any help will be greatly appreciated 

Alan Hendry

unread,
Sep 3, 2021, 11:12:19 AM9/3/21
to DroidScript
Hi,

What error are you getting? Can you post some code here?


There are two font files, (Desyrel.png and Desyrel.xml) that must be saved in the same folder as the images.
  
  txt = gfx.CreateText( score.toString(), 0.1, "Img/Desyrel.xml" )

  gfx.AddText( txt, 0, 0 )   

Regards, ah

Paul Goodings

unread,
Sep 4, 2021, 4:50:40 AM9/4/21
to DroidScript
Hi Alan, thanks for your response. 
Now I know you've got it working I can focus on finding what I am I doing wrong!

I will check the Dino game as you suggest and I will try and create a bit of code to demonstrate the problem and post it asap. I have got the 2 font files in the IMG folder so I guess the problem is elsewhere.  An unrelated issue is that I cannot find the "replay.png" file in the tutorial assets ftp site.

Thanks again.

Regards,
Paul

Paul Goodings

unread,
Sep 5, 2021, 9:13:32 AM9/5/21
to DroidScript
Hi Alan, below is a short bit of code I hope demonstrates the text problem. If I run it I get the error message "Script error: Cannot read properties of undefined (reading "parent"). Source: file:///android_asset/Libs/Pixi.js Line: 1591"

If I remove the AddText and SetText commands I get the simple background. I am a bit puzzled by the use of semicolons on text-related commands. I have a suspicion it has something to do with the font files.

Any idea where I am going wrong? Thanks, Paul

cfg.Game
cfg.Landscape

var word="hi"

function OnLoad()
{
 bkgnd = gfx.CreateBackground( "/Sys/Img/Sky.jpg" )
 txt = gfx.CreateText( word, 0.1, "Img/Desyrel.xml" );
}

function OnReady()
{
gfx.AddBackground( bkgnd )
gfx.AddText(txt,0,0);
    
//    txt.SetText(words);

gfx.Play()
}
{
txt.SetText(word)

Alan Hendry

unread,
Sep 8, 2021, 5:13:56 AM9/8/21
to DroidScript
Hi, 
Also see sample (rocket icon in top right) for Game Flappy.
Not sure what you mean about semicolons in text.
What gave you the name replay.png?
Your code fragment seems to have functions onload and onready, and txt.SetText outside of any function.
Regards, ah

Alan Hendry

unread,
Sep 8, 2021, 5:28:16 AM9/8/21
to DroidScript
Ok,
Part 2 of the flappy bird tutorial refers to replay.png
But 
Doesn't have it
It should be in the sample for Game Flappy.
Regards,  ah

Paul Goodings

unread,
Sep 9, 2021, 10:14:34 AM9/9/21
to DroidScript
Thanks for taking the time to reply, Alan. 
Yes the file "replay.png" appears in the final version of the Dino game at the end of the Part 2 tutorial. I have searched high and low but cannot find it. I don't see it in Game Flappy.

Semicolons only appear at the end of some text-related methods eg txt = gfx.CreateText( score.toString(), 0.1, "Img/Desyrel.xml); but not at the end of SetText. They are not used in other GV methods.

Sorry about the code sample - transposition error! Update below. Maybe I have misunderstood the structure of a GV programme?  If I run it I get the error message "Script error: Cannot read properties of undefined (reading "parent"). Source: file:///android_asset/Libs/Pixi.js Line: 1591"

Regards, Paul

cfg.Game
cfg.Landscape

var word="hi"

function OnLoad()
{
 bkgnd = gfx.CreateBackground( "/Sys/Img/Sky.jpg" )
 txt = gfx.CreateText( word, 0.1, "Img/Desyrel.xml" );
}

function OnReady()
{
gfx.AddBackground( bkgnd )
gfx.AddText(txt,0,0);

gfx.Play()
}

function OnAnimate( time, timeDiff)
{
txt.SetText(word)

Alan Hendry

unread,
Sep 10, 2021, 4:21:46 PM9/10/21
to DroidScript
Hi,

Javascript syntax doesn't (usually) NEED semi-colons at the end of statements but it makes it clearer.

From the Flappy Dino Tutorial page 4 -
OnLoad() – This is the first thing will run when the game is
launched, this is where graphical objects, sounds,
backgrounds and physics should be created.
OnReady() – This is executed when OnLoad() function has
finished running. Here the graphical objects, backgrounds,
sounds etc. are added to the GameView with their
appropriate settings. Once everything has been set up, calling
the ‘gfx.Play()’ function will start the game running.
OnAnimate() – This function is repeatedly called, around 60
times per second. This is where you update the position of
backgrounds and graphical objects.

As far as I'm aware, /Sys/Img/Sky.jpg is on all devices (may be worth checking).
The two Desyrel files need to be in the Img folder within your project/app 
(click the Assets icon, 3rd from the left on the bottom row, or under the pencil on the IDE).

If you go to http://androidscript.org/tutorials/GameView/ then download the SPK,
and load to DS (or unzip it) you will find replay.png.

If you use debug (little beetle icon in the bottom row) you may get better messages 
(or if you are using a PC with the IDE then see the debug window on the right).
To narrow down a bug you can comment out lines and/or insert alerts.
// txt.SetText(word)
alert(word)
Regards, ah

Paul Goodings

unread,
Sep 12, 2021, 10:36:53 AM9/12/21
to DroidScript
Hi Alan,
Your reply was very helpful and enabled me to find the SDK and elusive PNG file.
For the first time I managed to run the final version of the game - and see text on the screen! I have run the first version but when I copied and pasted the final code it produced an error.

Interestingly, the SDK often crashes and the error code is the same as the one I was getting with my test programme. Which suggests this is a more fundamental problem. Maybe my phone is the issue. Any ideas? Do you know where file Pixi.js is located? 

Thanks again for your help.

Regards, Paul

Alan Hendry

unread,
Sep 12, 2021, 12:37:50 PM9/12/21
to DroidScript
Paul,
To look at the Pixi.js error you'd need the official technical team
they would probably need to know the version of DS and Android.
I'm not sure when your  var word="hi"  statement is run 
I'd try moving it inside the OnLoad function.
Regards, ah

Paul Goodings

unread,
Sep 12, 2021, 1:10:51 PM9/12/21
to DroidScript
Thanks Alan, tried moving the var but I'm still getting the error. Pretty sure this is some kind of system problem. Any idea how I can contact the tech team? Maybe I can try running it on another phone.

Regards, Paul

Alan Hendry

unread,
Sep 13, 2021, 6:10:37 AM9/13/21
to DroidScript
Paul,

The official team monitor this group (and beta and premium) and respond.
I believe the current priority is to get the builder to create aab bundles
(Google Play Store now requires that new apps be in a new format aab instead of APKs)

I can't find pixi.js (on Android Oreo) I suspect it's just included with Android, possibly https://pixijs.com/

Regards, ah

Paul Goodings

unread,
Sep 13, 2021, 12:41:21 PM9/13/21
to DroidScript
Hi Alan,

Let's hope the official team pick up this issue  The path to the pixi.js file suggests it is an absolute address in the android OS. I will explore, but I expect it will be very difficult to track down the bug working backwards, if you see what I mean! Anyway I love a good mystery.

What puzzles me is the intermittent nature of the error - sometimes it crashes and sometimes it works. It crashes more often than it works. My test programme crashes everytime.

I'm using Android 11 and DroidScript ver 2.09.

Regards, Paul

Paul Goodings

unread,
Sep 18, 2021, 1:52:04 PM9/18/21
to DroidScript
Hi Alan,
This bug is driving me crazy!

I tried the code on another Android phone - Android 8 also using Droidscript 2.09, which I believe is the latest version.

The GameView Tutorial SDK crashed everytime I tried to run it showing the same error message.. Strangely, my GV test programme worked once, but crashed subsequently. 

I'd be interested to know if I am the only user experiencing this bug. If it persists I will have to delete the app.  Pity, because it seems to have potential and I cannot find anything similar.

Maybe I should start a new conversation on this issue.

Regards, Paul

Alan Hendry

unread,
Sep 18, 2021, 4:35:25 PM9/18/21
to DroidScript
Hi,
I've recreated your error (Oreo, DS 2.09) sometimes
(when I open it with DS I get 
Script Error layLst is not defined
Source File ///android_asset?DroidScript.js line 1291
Then it prompts me for replacing the existing app)
It seems to add the app to DS
Occasionally it runs OK, when it fails the debug on the PC IDE shows
  • App.SetOrientation( Landscape, null )
  • App.PreventScreenLock( true )
  • App.CreateLayout( LinearVertical,FillXY,VCenter )
  • -> #0
  • App.CreateWeb( 1, 1, gameview, )
  • -> #1
  • Web.LoadHtml(
  • Lay.AddChild( #1, )
  • App.AddLayout( #0 )
  • Script Error: Cannot read properties of undefined (reading 'parent'), Line 1591, Pixi.js
If I change the code to 
    alert(6)
gfx.AddText( txt, 0, 0 );
    alert(7)
Then I see the alert 6, then the error, so it's pretty clear that the AddText is failing
With the lines related to the score commented out it always runs OK.
Regards, ah

Alan Hendry

unread,
Sep 19, 2021, 11:13:59 AM9/19/21
to DroidScript
Hi,
If you run the Example for AddText from the DS app reference
a very similar error occurs, so I presume that gfx.AddText has a bug.
(I also noticed that the tutorial has   txt = gfx.CreateText( score.toString(), 0.1, "Img/Desyrel.xml" )
the 2nd parameter is fontsize 0.1, the AddText Example has 40, probably pixels, anyway it doesn't fix the problem).
Regards, ah

Paul Goodings

unread,
Sep 20, 2021, 7:16:12 AM9/20/21
to DroidScript
I think you may have found the bug, Alan. I hadn't spotted the AddText example. 

I added your alerts to the tutorial script and got the same result. Sometimes it runs after alert 5, but often it crashes. What puzzles me is how you get an intermittent fault in a computer programme. Maybe the bug is in Pixi.js.

Is there some way to report potential bugs?  

Regards, Paul

Dave

unread,
Sep 20, 2021, 7:33:08 AM9/20/21
to DroidScript
Hi Paul,

I wouldn't try to set the text in OnAnimate() because it will try to set it 60x a second and I don't think the system will cope with that!

You could perhaps trigger it once at 3 seconds for example - 

function OnAnimate( time, timeDiff )
{
  if( !txt.data.done && time >= 3000 ) { txt.SetText(word);  txt.data.done=true }
}

What does your current code look like?

Alan Hendry

unread,
Sep 20, 2021, 7:48:24 AM9/20/21
to DroidScript
@Dave,
The Example in the reference for  AddText  also fails 

cfg.Game;
function OnLoad()
{
    text = gfx.CreateText( "Hello World", 40, "/Sys/Img/Desyrel.xml" );
}
function OnReady()
{
    gfx.AddText( text, 0.2, 0.4, 0.2 );
    gfx.Play();
}

Regards, ah

Dave

unread,
Sep 20, 2021, 8:45:57 AM9/20/21
to DroidScript
OK, So there seems to be two problems:-

1. The internal Desyrel.xml font file has a case sensitivity issue
2. The game engine does not wait properly for the font to be loaded (unlike with image assets), so you can't use it right away and need a small delay.

Here is a fix for both issues - 

cfg.Game;

function OnLoad()
{
    //Hack to extract and fix broken Desyrel font file. 
    //Delete this block of code after using it once.
    gfx.AppExec( `
        if( !app.FileExists("Img/desyrel.xml") ) 
        { 
            app.MakeFolder( "Img" ) 
            var xml = app.ReadFile( "/Sys/Img/Desyrel.xml" )
            app.WriteFile( "Img/desyrel.xml", xml.replaceAll( "Desyrel", "desyrel" ) )
            app.CopyFile( "/Sys/Img/Desyrel.png", "Img/desyrel.png" )
            alert( "Font files extracted" )
            app.Exit()
        }`
    )
    
    text = gfx.CreateText( "Hello World", 0.06, "Img/desyrel.xml" );
}


function OnReady()
{
    //We need to delay the game start slightly to give the font time to load (it's a bug)
    setTimeout( Start, 500 )
}

function Start()
{
     gfx.AddText( text, 0.1, 0.1 );
     gfx.Play()
}




Paul Goodings

unread,
Sep 20, 2021, 10:17:18 AM9/20/21
to DroidScript
Big thanks Dave (and Alan) - I'll do as you suggest. This bug has been bugging me. Now I can proceed with the very slow development of my little game.

Regards, Paul

Paul Goodings

unread,
Sep 21, 2021, 8:17:44 AM9/21/21
to DroidScript
I have text in my game! Progress.
Message has been deleted

Alan Hendry

unread,
Sep 21, 2021, 12:15:49 PM9/21/21
to DroidScript
Dave,
Sometime the tutorial worked and sometimes it didn't, so it's consistent with a timing problem.
Is that a problem to be reported to Pixi, or in DS?
https://pixijs.io/guides/basics/text.html seems to hint that it is possible to test if a font has loaded OK
// Create the loader
let font = new FontFaceObserver('Short Stack', {});
// Start loading the font
font.load().then(() => {
  // Successful load, start up your PixiJS app as usual
  let app = new PIXI.Application({ width: 640, height: 360 });
  document.body.appendChild(app.view);
  // ... etc ...
}, () => {
  // Failed load, log the error or display a message to the user
  alert('Unable to load required font!');
});
Regards, ah

Dave

unread,
Sep 30, 2021, 6:09:53 AM9/30/21
to DroidScript
I think this is our bug and not PIXIs fault.  

We have code to delay the call to OnReady() till all the images and sounds are loaded, but I don't think we have included Font loading in that bit of logic.

Reply all
Reply to author
Forward
0 new messages