Pixl demos

Posted on
  • In most of the demos there is a variable 'g' that refers to the graphics display. In the Pixl, where is that defined? Is it 'built-in' in some way?

    see: http://www.espruino.com/Pico+Flappy+Bird­+Game

  • Yes, g is just built-in. I was going to have 'Pixl.getGraphics()' or something, but then I wanted people to be able to connect and start using it immediately without much typing, so I kept g as that's what pretty much all the graphics examples do anyway.

    I'll add a section on it to the Pixl reference at http://www.espruino.com/Pixl.js in the next few hours.

  • TBH - I'd prefer an explicit assignment myself - but understand the thinking. Hopefully no one uses 'g' as a variable name!

  • @davidhay - absolutely! think about all the code that is already going on... and now reserving a single char variable name is a no-no for me... I tried to come up with a solution... but cannot really think of one.

  • We need to remember we are on a micro here... any long name takes up precious jsvars. Length 1-4 still fits in a var, however I'm not sure gfx or similar would be any better!

  • well yes, but how much extra (compiled) space does an explicit assignment take?

    ie:

    g = Pixl.getGraphics();
    
  • how much extra (compiled) space does an explicit assignment take?

    It's not about the compiled space, it was about allowing people to take it out the box and start using the graphics right away with the minimum amount of boilerplate required.

    reserving a single char variable name is a no-no for me... I tried to come up with a solution... but cannot really think of one.

    var gfx = g;delete g;? Or just write your code such that the scoping means you don't overwrite the global g.

    I can add Pixl.getGraphics() in a firmware update - or maybe E.getGraphics() makes more sense so it can be handled on other platforms as well. At least then it's not a big deal to just delete/overwrite the built-in g if you don't like it.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Pixl demos

Posted by Avatar for davidhay @davidhay

Actions