Ah, this is the question I actually meant to ask before -- can I use stuff like Font.drawText and Image.blit without running the Map Engine? Or do they require the Map Engine?
Two quick questions...
1) Can I access the player's X and Y without using GetPlayerX/Y? Since it's a function, it's inconvenient to use nested deep in my code. I'd prefer to just do player.x and player.y.
If I just did "player.x = GetPlayerX(blah)" would that work?
No, sadly you can't. That will just get you the value returned by GetPlayerX(blah) at the time you set player.x. You could wrap it inside a player.getX() function or similar, though.
Unfortunately, I need the player's X and Y positions in variables, not functions.
It depends how you structure it. You can very easily just leave the map engine running the whole time your game runs.
Mostly, you absolutely need a game loop (and not a recursive game function! Don't do that!) if you don't use the map engine in your game, or choose to use it for portions but also close it from time to time and then run it again later.
Not sure I understand, but then again, I don't really understand how the Map Engine works. Though I get that if you were making, say, an RPG, you could turn off the ME while the player's in battle. Though I can't see what'd be wrong with leaving it running in the background. The computers we're all using are probably plenty powerful enough that that little bit of wasted computing won't cause a noticable slowdown.
There's nothing wrong with leaving it running.
I was mostly thinking of games that don't use the map engine. Then I imagined a game that used the map engine for small portions of the gameplay, and wanted to ammend that case since it is possible. It's not important.
About input handling, you can check if keys are pressed using IsKeyPressed in the update script. Or you could use AreKeysLeft and GetKey (this has some advantages) in the update script.
But either way, I would put key checking code in the update script.
Oh yeah. No reason I can't use the API functions. I'm not thinking straight.
Hmm. Checking the API on the Wiki (a rare blue link!), IsKeyPressed returns a boolean. What I need - and I'm gonna test to see if I can do this myself - is to store multiple inputs in a single byte. Like, up on the low-order bit, right on bit 1, down on bit 2, etc. Well, I probably don't
need it, it's just the way I'm most used to and comfortable handling player input.
===Edit===
I see my problem. I'm thinking in terms of something like BASIC, where the program runs one line of code after another, from the top of the code to the bottom, and only does any looping if you tell it to jump back up in the code. I forgot you can while(true) something and have it keep going while you're doing other things.
while(true) does not keep going while you do other things. It is an infinite loop, meaning that when execution gets to the bottom of the block, it goes right back to the top.
Then how can the various bits of code I write be running if Sphere is infinitely stuck in the Map Engine? In Radnen's example of how function MapEngine works, it doesn't have a callback to game. So game should run once, get to MapEngine, then MapEngine should run infinitely, meaning any code not inside MapEngine (and none of my code is) shouldn't run. Or will only run once if I put it in function game() but before MapEngine.
Two quick questions...
1) Can I access the player's X and Y without using GetPlayerX/Y? Since it's a function, it's inconvenient to use nested deep in my code. I'd prefer to just do player.x and player.y.
If I just did "player.x = GetPlayerX(blah)" would that work?
It would be nice in a different Sphere, and you can do that in Sphere 1.x if you wrote a large wrapper of the player object (but you'll have to know how to do that). However, it's not standard. It would be at some point, but not presently. So you have to use the Set/Get methods for now. And all beginners should use them at first to be safe.
Oh! Wait! I don't need player.x and player.y! I was gonna use it to move the players, but I can just use QueuePlayerCommand.
It'd still be nice to have player positions as variables, not just the output of functions.
2) Is there a controller/input object built into the Sphere API? Because one super-easy way to handle custom diagonal movement would be something like...
if DPad && 0 = 1 then player.y --;
if DPad && 1 = 1 then player.x ++;
if DPad && 2 = 1 then player.y ++;
if DPad && 4 = 1 then player.x --;
In that example, obviously, DPad would store player movement in a nibble, and I could simply and-compare it to check which bits were active, so as to move the player around accordingly.
That's what I did in my Wii U Canvas game I was messing around with awhile ago. I could post the full code if anyone wants to look at the kinda programming I'm doing and used to.
Ok, I see what you are trying to do with that code. (In JS and-compare is a single &, so that's why it looked weird to me). Yes, there is a way to do that.
function InputGroup(input) {
this.num = input; // controller's input (aka player number).
}
InputGroup.prototype = {
get axisLeft () { return GetJoystickAxis(this.num, JOYSTICK_AXIS_X) < -0.5; },
get axisRight() { return GetJoystickAxis(this.num, JOYSTICK_AXIS_X) > 0.5; },
get axisUp () { return GetJoystickAxis(this.num, JOYSTICK_AXIS_Y) < -0.5; },
get axisDown () { return GetJoystickAxis(this.num, JOYSTICK_AXIS_Y) > 0.5; },
}
Then you can use:
var input = new InputGroup(0);
if (input.axisLeft) SetPlayerX(name, GetPlayerX(name) + 1);
// etc.
Nice! Thanks so much ^_^
So that'll work in Sphere just as you typed it?
Ah, I forgot about that. That's web JS, so it's only for browsers. Sphere uses a subset strictly for gaming. It's otherwise known as the SpiderMonkey v1.5 API. You can find it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference
: /
That's what I was looking through. I followed the link from the Sphere wiki. I wonder how I ended up at a page about addEventListener...oh, I see. When you use the search bar on the Reference there, it kicks you out to Google, and searches the whole Mozilla Javascript site, so I ended up on a page not about SpiderMonkey.
I see my problem. I'm thinking in terms of something like BASIC, where the program runs one line of code after another, from the top of the code to the bottom, and only does any looping if you tell it to jump back up in the code. I forgot you can while(true) something and have it keep going while you're doing other things.
You know what'd be really helpful? If the raw code of the API functions were available somewhere. Then one could peer inside and see precisely what's happening.
There is the raw code. It is online at github: https://github.com/sphere-group/sphere
That is intimidating to me. I don't suppose all the code for the API commands is listed neatly, in alphabetical order somewhere in there, is it?
And wait, is that gonna be in C++? I just wanna see the exact Javascript that's being run for various API commands.
Okay, so since Sphere 1x is interpreting, it'll basically run any Javascript I give it the way a webpage would. In SphereSFML (which I'm mentally pronouncing "surf mail"), since it's compiled, will there be some JS stuff that doesn't work?
No, Sphere runs SpiderMonkey, see the reference. The JS API should fully work, but in fact SFML version uses an even stricter ECMA5 reference, which has fewer features than SpiderMonkey, but is still indeed a complete language and should play all the games here (unless they use some weird intrinsic feature known only to SpiderMonkey, and there are a few of those games, but rare). Compiled just means it's really fast JS, that's all.
Edit:
I replied right after Jest, it takes forever responding to you!!
It's gonna pay off when I make a rockin' game that draws millions of people to Sphere :p
A RARE PROJECT UPDATEI'm trying out my SNES multitap-esque hack. I should have a rudimentary test to see whether I can go forward with it in a few days.
Oh, and I'm gonna compile all the info in this topic (and my other ones) and de-redlink the Wiki as much as I can. If I could look all this stuff up, I wouldn't have to ask.