Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #30 from adireddy/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Adi committed Jan 22, 2015
2 parents 761f778 + 5f58ca1 commit 0e21e60
Show file tree
Hide file tree
Showing 44 changed files with 1,741 additions and 523 deletions.
62 changes: 47 additions & 15 deletions docs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17725,6 +17725,42 @@ Documentation for this class was provided by <a href="https://developer.mozilla.
<m n=":final"/>
</meta>
</class>
<class path="pixi.Application" params="" file="pixi/Application.hx">
<pixelRatio public="1" get="null"><x path="Float"/></pixelRatio>
<skipFrame public="1" get="null"><x path="Bool"/></skipFrame>
<width public="1" get="null"><x path="Float"/></width>
<height public="1" get="null"><x path="Float"/></height>
<resize public="1" get="null"><x path="Bool"/></resize>
<stats public="1" get="null" set="accessor"><x path="Bool"/></stats>
<backgroundColor public="1" get="null"><x path="Int"/></backgroundColor>
<onUpdate public="1"><f a="">
<x path="Float"/>
<x path="Void"/>
</f></onUpdate>
<onResize public="1"><f a=""><x path="Void"/></f></onResize>
<_stage set="null"><c path="pixi.display.Stage"/></_stage>
<_canvas><c path="js.html.CanvasElement"/></_canvas>
<_renderer><c path="pixi.renderers.webgl.WebGLRenderer"/></_renderer>
<_stats><c path="pixi.utils.Stats"/></_stats>
<_lastTime><c path="Date"/></_lastTime>
<_currentTime><c path="Date"/></_currentTime>
<_elapsedTime><x path="Float"/></_elapsedTime>
<_skipFrame><x path="Bool"/></_skipFrame>
<_setDefaultValues set="method" line="96"><f a=""><x path="Void"/></f></_setDefaultValues>
<start public="1" set="method" line="106"><f a=""><x path="Void"/></f></start>
<_onWindowResize set="method" line="126"><f a="event">
<c path="js.html.Event"/>
<x path="Void"/>
</f></_onWindowResize>
<_onRequestAnimationFrame set="method" line="135"><f a=""><x path="Void"/></f></_onRequestAnimationFrame>
<_calculateElapsedTime set="method" line="147"><f a=""><x path="Void"/></f></_calculateElapsedTime>
<set_stats set="method" line="153"><f a="val">
<x path="Bool"/>
<x path="Bool"/>
</f></set_stats>
<new public="1" set="method" line="91"><f a=""><x path="Void"/></f></new>
<meta><m n=":keep"/></meta>
</class>
<typedef path="pixi.CanvasElement" params="" file="pixi/DomDefinitions.hx" module="pixi.DomDefinitions">
<c path="js.html.CanvasElement"/>
<haxe_doc>* Because macros cannot access the JS package, put
Expand Down Expand Up @@ -21823,14 +21859,7 @@ Documentation for this class was provided by <a href="https://developer.mozilla.
</f></new>
<meta><m n=":native"><e>"PIXI.GraphicsData"</e></m></meta>
</class>
<class path="pixi.renderers.IRenderer" params="" file="pixi/renderers/IRenderer.hx" interface="1">
<view public="1"><t path="pixi.CanvasElement"/></view>
<render public="1" set="method"><f a="stage">
<c path="pixi.display.Stage"/>
<x path="Void"/>
</f></render>
<meta><m n=":keep"/></meta>
</class>
<class path="pixi.renderers.IRenderer" params="" file="pixi/renderers/IRenderer.hx" interface="1"><meta><m n=":keep"/></meta></class>
<class path="pixi.renderers.canvas.CanvasGraphics" params="" file="pixi/renderers/canvas/CanvasGraphics.hx" extern="1">
<renderGraphics public="1" set="method" static="1"><f a="graphics:context">
<c path="pixi.primitives.Graphics"/>
Expand Down Expand Up @@ -24475,20 +24504,23 @@ Documentation for this class was provided by <a href="https://developer.mozilla.
<meta><m n=":native"><e>"PIXI.AjaxRequest"</e></m></meta>
</class>
<class path="samples.nape.Main" params="" file="samples/nape/Main.hx">
<main set="method" line="85" static="1">
<extends path="pixi.Application"/>
<main set="method" line="83" static="1">
<f a=""><x path="Void"/></f>
<meta><m n=":keep"/></meta>
</main>
<_renderer><c path="pixi.renderers.IRenderer"/></_renderer>
<_stage><c path="pixi.display.Stage"/></_stage>
<_floor><c path="nape.phys.Body"/></_floor>
<_space><c path="nape.space.Space"/></_space>
<_balls><c path="Array"><c path="pixi.display.Sprite"/></c></_balls>
<_pballs><c path="Array"><c path="nape.phys.Body"/></c></_pballs>
<_setUpPhysics set="method" line="44"><f a=""><x path="Void"/></f></_setUpPhysics>
<_addBall set="method" line="54"><f a=""><x path="Void"/></f></_addBall>
<animate set="method" line="71"><f a=""><x path="Void"/></f></animate>
<new public="1" set="method" line="29"><f a=""><x path="Void"/></f></new>
<_init set="method" line="37"><f a=""><x path="Void"/></f></_init>
<_onUpdate set="method" line="46"><f a="elapsedTime">
<x path="Float"/>
<x path="Void"/>
</f></_onUpdate>
<_setUpPhysics set="method" line="56"><f a=""><x path="Void"/></f></_setUpPhysics>
<_addBall set="method" line="66"><f a=""><x path="Void"/></f></_addBall>
<new public="1" set="method" line="24"><f a=""><x path="Void"/></f></new>
<meta><m n=":keep"/></meta>
</class>
<class path="zpp_nape.ZPP_ID" params="" file="/haxelib/nape/2,0,16/zpp_nape/ID.hx" module="zpp_nape.ID">
Expand Down
166 changes: 166 additions & 0 deletions pixi/Application.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/* Helper class that can be used by any pixi application
*
* @author Adi Reddy Mora
* http://adireddy.github.io
* @license MIT
* @copyright 2015
*/

package pixi;

import js.html.Event;
import js.html.CanvasElement;
import js.Browser;
import pixi.renderers.webgl.WebGLRenderer;
import pixi.utils.Detector;
import pixi.display.Stage;
import pixi.utils.Stats;

class Application {

/*
* Sets the pixel ratio of the application
* @default 1
*/
public var pixelRatio(null, default):Float;

/*
* Default frame rate is 60 FPS and this can be set to true to get 30 FPS
* @default false
*/
public var skipFrame(null, default):Bool;

/*
* Width of the application
* @default Browser.window.innerWidth
*/
public var width(null, default):Float;

/*
* Height of the application
* @default Browser.window.innerHeight
*/
public var height(null, default):Float;

/*
* Whether you want to resize the canvas and renderer on browser resize
* Should be set to false when custom width and height are used for the application
* @default true
*/
public var resize(null, default):Bool;

/*
* Enable/disable stats for the application
* Note that stats.js is not part of pixi so don't forget to include it you html page
* Can be found in libs folder - <script type="text/javascript" src="libs/stats.min.js"></script>
* @default false
*/
public var stats(null, set):Bool;

/*
* Sets the background color of the stage
* @default 0xFFFFFF
*/
public var backgroundColor(null, default):Int;

/*
* Update listener function
*/
public var onUpdate:Float -> Void;

/*
* Windo resize listener function
*/
public var onResize:Void -> Void;

/*
* Pixi stage
* Read-only
*/
var _stage(default, null):Stage;

var _canvas:CanvasElement;
var _renderer:WebGLRenderer;
var _stats:Stats;

var _lastTime:Date;
var _currentTime:Date;
var _elapsedTime:Float;
var _skipFrame:Bool;

public function new() {
_lastTime = Date.now();
_setDefaultValues();
}

function _setDefaultValues() {
pixelRatio = 1;
skipFrame = false;
stats = false;
backgroundColor = 0xFFFFFF;
width = Browser.window.innerWidth;
height = Browser.window.innerHeight;
_skipFrame = false;
}

public function start() {
_canvas = Browser.document.createCanvasElement();
_canvas.style.width = width + "px";
_canvas.style.height = height + "px";
_canvas.style.position = "absolute";
Browser.document.body.appendChild(_canvas);

_stage = new Stage(backgroundColor);

var renderingOptions:RenderingOptions = {};
renderingOptions.view = _canvas;
renderingOptions.resolution = pixelRatio;

_renderer = Detector.autoDetectRenderer(width, height, renderingOptions);
Browser.document.body.appendChild(_renderer.view);
Browser.window.onresize = _onWindowResize;
Browser.window.requestAnimationFrame(cast _onRequestAnimationFrame);
_lastTime = Date.now();
}

function _onWindowResize(event:Event) {
width = Browser.window.innerWidth;
height = Browser.window.innerHeight;
_renderer.resize(width, height);
_canvas.style.width = width + "px";
_canvas.style.height = height + "px";
if (onResize != null) onResize();
}

function _onRequestAnimationFrame() {
if (skipFrame && _skipFrame) _skipFrame = false;
else {
_skipFrame = true;
_calculateElapsedTime();
if (onUpdate != null) onUpdate(_elapsedTime);
_renderer.render(_stage);
}
Browser.window.requestAnimationFrame(cast _onRequestAnimationFrame);
if (_stats != null) _stats.update();
}

function _calculateElapsedTime() {
_currentTime = Date.now();
_elapsedTime = _currentTime.getTime() - _lastTime.getTime();
_lastTime = _currentTime;
}

function set_stats(val:Bool):Bool {
if (val) {
var _container = Browser.document.createElement("div");
Browser.document.body.appendChild(_container);
_stats = new Stats();
_stats.domElement.style.position = "absolute";
_stats.domElement.style.top = "2px";
_stats.domElement.style.right = "2px";
_container.appendChild(_stats.domElement);
_stats.begin();
}
return stats = val;
}
}
4 changes: 3 additions & 1 deletion pixi/DomDefinitions.hx
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ package pixi;
typedef Element = Dynamic;
typedef Image = Dynamic;
typedef DivElement = Dynamic;
#end
#end

class DomDefinitions {}
1 change: 1 addition & 0 deletions samples/_output/basics.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<title>haxe-pixi-basics</title>

<script type="text/javascript" src="libs/pixi.min.js"></script>
<script type="text/javascript" src="libs/stats.min.js"></script>

<style>
html,body { margin: 0; padding: 0; width: 100%; height: 100%; }
Expand Down
1 change: 1 addition & 0 deletions samples/_output/bitmaptext.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<title>haxe-pixi-bitmaptext</title>

<script type="text/javascript" src="libs/pixi.min.js"></script>
<script type="text/javascript" src="libs/stats.min.js"></script>

<style>
html,body { margin: 0; padding: 0; width: 100%; height: 100%; }
Expand Down
1 change: 1 addition & 0 deletions samples/_output/blur.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<title>haxe-pixi-blur</title>

<script type="text/javascript" src="libs/pixi.min.js"></script>
<script type="text/javascript" src="libs/stats.min.js"></script>

<style>
html,body { margin: 0; padding: 0; width: 100%; height: 100%; }
Expand Down
1 change: 1 addition & 0 deletions samples/_output/colourmatrix.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<title>haxe-pixi-colourmatrix</title>

<script type="text/javascript" src="libs/pixi.min.js"></script>
<script type="text/javascript" src="libs/stats.min.js"></script>

<style>
html,body { margin: 0; padding: 0; width: 100%; height: 100%; }
Expand Down
1 change: 1 addition & 0 deletions samples/_output/graphics.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<title>haxe-pixi-graphics</title>

<script type="text/javascript" src="libs/pixi.min.js"></script>
<script type="text/javascript" src="libs/stats.min.js"></script>

<style>
html,body { margin: 0; padding: 0; width: 100%; height: 100%; }
Expand Down
Loading

0 comments on commit 0e21e60

Please sign in to comment.