RequireScript("kh2Bar.js");// maxHP is required, sectorSize and color are optional. If not provided, the default values are// sectorSize: 100 (100 HP per bar) and color: #00FF00 (green) @ 100%.var lifebar = new kh2Bar(maxHP, sectorSize, color);lifebar.show(); // bar is initially hidden, must call show() or the player won't see it// Inside your game loop:lifebar.update();lifebar.draw(x, y, width, height);
lifebar.set(currentHP);
RequireScript('hook-list.js');var UpdateHooks = HookList();var RenderHooks = HookList();SetUpdateScript('UpdateHooks()');SetRenderScript('RenderHooks()');// ...UpdateHooks.add(myLifebar.update.bind(myLifebar));RenderHooks.add(myLifebar.render.bind(myLifebar));
Is method.bind() native JS functionality though? I thought you needed an extra script for that... If not then I'm a complete idiot for rolling my own delegate() function...
Yes if it was introduced in JS 1.8.5 and up, no if anything before (so, what Sphere uses). Delegate or a custom bind method would then have to be created.
if (typeof Function.prototype.bind != 'function') { Function.prototype.bind = function (self) { var args = Array.prototype.slice.call(arguments, 1), fn = this; return function () { return fn.apply(self, args.concat(Array.prototype.slice.call(arguments))); }; };}
See now that you have a screenshot of what's going on people like myself can now realize what you meant by KH2-style life bar. It looks to be very useful and I look forward to analyzing the code and seeing how to use it or something like it in NShoot
Attatch a project and ill give it a go, drives me crazy copy/pasting code