This JavaScript is more complex than I usually have to work with. I decided to read the comments, to better understand what's going on.
var getElementById = function (id) { // public, do not change signature without wrapping in _hype['API']!
Public... is that us?
Signature?!
I did see the phrase, API. That seems encouraging. Also, I'm wondering, what's the license on this code? Since it uses matter, is this automatically MIT licensed? If it's open source, that's exciting. It means that developers can contribute code.
I'm thinking not, as I saw this interesting comment...
// HypeAudio.js
// Hype
//
// Created by Jonathan Deutsch on 7/17/12.
// Copyright (c) 2012 Tumult Inc. All rights reserved.
Anyway, that hype[API] comment appears multiple times in the JavaScript file.
It's like a work of art to read this code. Seeing how cross browser issues are handled is what makes HYPE useful. With Flash, it just worked across multiple operating systems and browsers. With HTML5, it's a bit of a mess. The extra work to straighten out this issue is impressive.
Also, I have a story, if you're still worried about adding additional Physics features or expanding the API. Stencyl had a major change from version 2.x to 3.0. They dropped ActionScript and switched to Haxe / OpenFL. For those sticking to the core blocks, it was a non-issue. For those doing custom coding, it created a big problem. I'm surprised at how well the community survived that. It's so polite over there.
return { x: origin.x, y: origin.y, angle: angle };
};
// returns an { x, y } point
// cannot calculate width/height as these are dependent on proportionality (we'd also need the bounding width/height, but I don't think we'll ever be in a position to supply this)
// generically useful function, but I'm keeping in PhysicsTemplate so it doesn't bloat the runtime
That's an interesting comment. This seems like part of the gaming trinity... Position, Velocity and Collision Detection. The origin of an element is important. If the top left corner is know, and knowing the width/height of the actor is also nice, elements can be moved dynamically. The words, "I don't think we'll ever be in a position to supply this" is interesting. What isn't being supplied?
Also, matter.js has a feature called "view"... http://brm.io/matter-js-demo/#views ...which works like a camera and could be huge for Hype.
When I tested the demo and scrolled the whole scene with the mouse wheel, I was happy. I knew it could be used to solve problems like this... Scaling content together - #5 by MarkHunte
The view could be used to create scrolling games or scrolling scenes. It could also be another way to handle responsive design.
My JavaScript coding doesn't seem to be up to the challenge of the Physics API project. But if this thread changes the views of Tumult, showing how adding a Physics API is important to Hype, then it was successful. I still felt like trying, so I kept reading.
// if there's been no width/height is likely a text box without explicit dimensions. We still need to know what it is
if(widthValue == null) {
widthValue = currentElementSize.width;
}
if(heightValue == null) {
heightValue = currentElementSize.height;
}
"We still need to know what it is" ...those words alone makes a strong argument for exposing variables. Where's the harm in making the width and height variables accessible in Hype? Where's the harm in making the origin (X,Y) accessible? Where's the harm in letting developers change that information dynamically with JavaScript? Hype will likely grow, but origin, velocity and rotation seems fairly consistent.