forked from shengxinjing/vue3-vs-vue2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
61 lines (39 loc) · 1.28 KB
/
game.js
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
61
import * as PIXI from 'pixi.js'
//Create a Pixi Application
let app = new PIXI.Application({width: 256, height: 256});
// set background
app.renderer.backgroundColor = 0x061639;
//Add the canvas that Pixi automatically created for you to the HTML document
document.body.appendChild(app.view);
// let rectangle = new PIXI.Graphics();
// rectangle.lineStyle(4, 0xFF3300, 1);
// rectangle.beginFill(0x66CCFF);
// rectangle.drawRect(0, 0, 64, 64);
// rectangle.endFill();
// rectangle.x = 0;
// rectangle.y = 0;
// app.stage.addChild(rectangle);
// app.stage.on("pointerdown",()=>{
// console.log("click")
// })
const sprite = new PIXI.Sprite();
// Set the initial position
sprite.anchor.set(0.5);
sprite.x = app.screen.width / 2;
sprite.y = app.screen.height / 2;
// Opt-in to interactivity
sprite.interactive = true;
// Shows hand cursor
sprite.buttonMode = true;
// Pointers normalize touch and mouse
sprite.on('pointerdown', onClick);
// Alternatively, use the mouse & touch events:
// sprite.on('click', onClick); // mouse-only
// sprite.on('tap', onClick); // touch-only
app.stage.addChild(sprite);
let texture = PIXI.Texture.from('examples/assets/bunny.png');
// sprite.texture = "examples/assets/bunny.png"
sprite.texture = texture;
function onClick() {
sprite.x += 4;
}