-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
47 lines (35 loc) · 943 Bytes
/
sketch.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
var sea,ship;
var seaImg,shipImg;
function preload(){
//uncomment the code to add animation to ship
shipImg1 = loadAnimation("ship-1.png");
//shipImg1 = loadAnimation("ship-1.png");
//shipImg1 = loadAnimation("ship-1");
shipImg1 = loadAnimation("ship-1.png","ship-2.png","ship-1.png","ship-2.png");
//shipImg1 = loadAnimation("ship-1","ship-2","ship-1","ship-2");
seaImg = loadImage("sea.png");
}
function setup(){
createCanvas(400,400);
background("blue");
// Moving background
sea=createSprite(400,200);
sea.addImage(seaImg);
sea.velocityX = -5;
sea.scale=0.3;
ship = createSprite(130,200,30,30);
ship.addAnimation("movingShip",shipImg1);
ship.scale =0.25;
}
function draw() {
background(0);
sea.velocityX = -3;
//uncomment code to reset the background
if(sea.x < 0){
//sea.x = 0;
//sea.x = sea.width;
sea.x = sea.width/8;
//sea.y = height;
}
drawSprites();
}