forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path001 under sea.js
More file actions
73 lines (51 loc) · 3.02 KB
/
Copy path001 under sea.js
File metadata and controls
73 lines (51 loc) · 3.02 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
61
62
63
64
65
66
67
68
69
70
71
72
73
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create });
function preload() {
// game.load.atlasXML('seacreatures', 'assets/sprites/seacreatures.png', 'assets/sprites/seacreatures.xml');
game.load.atlas('seacreatures', 'assets/sprites/seacreatures_json.png', 'assets/sprites/seacreatures_json.json');
// Just a few images to use in our underwater scene
game.load.image('undersea', 'assets/pics/undersea.jpg');
game.load.image('coral', 'assets/pics/seabed.png');
}
var jellyfish;
var crab;
var greenJellyfish;
var octopus;
var purpleFish;
var seahorse;
var squid;
var stingray;
var flyingfish;
function create() {
game.add.sprite(0, 0, 'undersea');
jellyfish = game.add.sprite(670, 20, 'seacreatures', 'blueJellyfish0000');
// In the texture atlas the jellyfish uses the frame names blueJellyfish0000 to blueJellyfish0032
// So we can use the handy generateFrameNames function to create this for us.
jellyfish.animations.add('swim', Phaser.Animation.generateFrameNames('blueJellyfish', 0, 32, '', 4), 30, true);
jellyfish.animations.play('swim');
// Let's make some more sea creatures in the same way as the jellyfish
crab = game.add.sprite(550, 480, 'seacreatures');
crab.animations.add('swim', Phaser.Animation.generateFrameNames('crab1', 0, 25, '', 4), 30, true);
crab.animations.play('swim');
greenJellyfish = game.add.sprite(330, 100, 'seacreatures');
greenJellyfish.animations.add('swim', Phaser.Animation.generateFrameNames('greenJellyfish', 0, 39, '', 4), 30, true);
greenJellyfish.animations.play('swim');
octopus = game.add.sprite(160, 400, 'seacreatures');
octopus.animations.add('swim', Phaser.Animation.generateFrameNames('octopus', 0, 24, '', 4), 30, true);
octopus.animations.play('swim');
purpleFish = game.add.sprite(800, 413, 'seacreatures');
purpleFish.animations.add('swim', Phaser.Animation.generateFrameNames('purpleFish', 0, 20, '', 4), 30, true);
purpleFish.animations.play('swim');
seahorse = game.add.sprite(491, 40, 'seacreatures');
seahorse.animations.add('swim', Phaser.Animation.generateFrameNames('seahorse', 0, 5, '', 4), 30, true);
seahorse.animations.play('swim');
squid = game.add.sprite(610, 215, 'seacreatures', 'squid0000');
stingray = game.add.sprite(80, 190, 'seacreatures');
stingray.animations.add('swim', Phaser.Animation.generateFrameNames('stingray', 0, 23, '', 4), 30, true);
stingray.animations.play('swim');
flyingfish = game.add.sprite(60, 40, 'seacreatures', 'flyingFish0000');
game.add.sprite(0, 466, 'coral');
game.add.tween(purpleFish).to({ x: -200 }, 7500, Phaser.Easing.Quadratic.InOut, true, 0, 1000, false);
game.add.tween(octopus).to({ y: 530 }, 2000, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
game.add.tween(greenJellyfish).to({ y: 250 }, 4000, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
game.add.tween(jellyfish).to({ y: 100 }, 8000, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
}