-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
61 lines (42 loc) · 1.25 KB
/
app.js
File metadata and controls
61 lines (42 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var PIXI = require("/bower_components/pixi.js/bin/pixi.js");
var jQuery = require("/bower_components/jquery/dist/jquery.js");
function move( object, stage ) {
object.position.x += object.speed.x;
object.position.y += object.speed.y;
if (object.position.x > stage.width) { object.speed.x = object.speed.x * -1 }
}
jQuery(function(){
// create an new instance of a pixi stage
var stageOptions = {
bg: 0xdddddd,
interactive: true
}
var stage = new PIXI.Stage(stageOptions.bg, stageOptions.interactive);
// create a renderer instance.
var renderer = PIXI.autoDetectRenderer(window.innerWidth, window.innerHeight);
var target = new PIXI.Point();
// add the renderer view element to the DOM
document.body.appendChild(renderer.view);
requestAnimFrame( animate );
var texture = PIXI.Texture.fromImage("/assets/images/ball.png");
var ball = new PIXI.Sprite(texture);
ball.interactive = true;
ball.speed = {
x: 1,
y: 1
};
ball.mousedown = function(mouseData) {
console.log("Mouse Down!");
};
ball.anchor.x = 0.5;
ball.anchor.y = 0.5;
ball.position.x = 200;
ball.position.y = 200;
stage.addChild(ball);
function animate() {
requestAnimFrame( animate );
ball.rotation += 0.1;
move( ball, stage);
renderer.render(stage);
}
});