@@ -5,17 +5,18 @@ function preload() {
55
66 game . load . tilemap ( 'map' , 'assets/maps/newtest.json' , null , Phaser . Tilemap . TILED_JSON ) ;
77 game . load . tileset ( 'tiles' , 'assets/maps/ground_1x1.png' , 32 , 32 ) ;
8- // game.load.image('phaser', 'assets/sprites/phaser-ship.png');
8+ game . load . image ( 'phaser' , 'assets/sprites/phaser-ship.png' ) ;
99 // game.load.image('phaser', 'assets/sprites/mushroom2.png');
1010 // game.load.image('phaser', 'assets/sprites/wabbit.png');
1111 // game.load.image('phaser', 'assets/sprites/arrow.png');
12- game . load . image ( 'phaser' , 'assets/sprites/darkwing_crazy.png' ) ;
12+ // game.load.image('phaser', 'assets/sprites/darkwing_crazy.png');
1313
1414}
1515
1616var cursors ;
1717var map ;
1818var layer ;
19+ var layer2 ;
1920var sprite ;
2021
2122function create ( ) {
@@ -28,48 +29,63 @@ function create() {
2829
2930 // Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, tilemap, layer) {
3031
31- layer = game . add . tilemapLayer ( 0 , 0 , 800 , 600 , null , map , 0 ) ;
32+ // layer = game.add.tilemapLayer(0, 0, 800, 600, null, map, 0);
33+ layer = game . add . tilemapLayer ( 0 , 0 , 400 , 600 , null , map , 0 ) ;
34+
35+ // layer2 = game.add.tilemapLayer(0, 0, 400, 600, null, map, 0);
36+ layer . cameraOffset . x = 400 ;
3237
3338 // tileset = game.add.tileset('tilesNes');
3439 // layer = game.add.tilemapLayer(0, 0, map.layers[0].width*tilesetNes.tileWidth, 600, tileset, map, 0);
35-
3640 // disable this and you can place anywhere, but will almost certainly screw collision
37- // layer.fixedToCamera=false;
3841
39- // this screws something up - not quite sure what, but needs investigating!
40- // layer.resizeWorld();
42+ layer . resizeWorld ( ) ;
4143
42- sprite = game . add . sprite ( 200 , 420 , 'phaser' ) ;
44+ sprite = game . add . sprite ( 260 , 100 , 'phaser' ) ;
4345 sprite . anchor . setTo ( 0.5 , 0.5 ) ;
44- sprite . angle = 35 ;
4546
46- // game.camera.follow(sprite);
47+ // We'll set a lower max angular velocity here to keep it from going totally nuts
48+ sprite . body . maxAngular = 500 ;
4749
48- cursors = game . input . keyboard . createCursorKeys ( ) ;
50+ // Apply a drag otherwise the sprite will just spin and never slow down
51+ sprite . body . angularDrag = 50 ;
52+
53+ // sprite.body.drag.x = 50;
54+ // sprite.body.drag.y = 20;
55+
56+ // sprite.body.velocity.x = 50;
4957
50- game . input . onDown . add ( dump , this ) ;
58+ sprite . body . bounce . x = 0.8 ;
59+ sprite . body . bounce . y = 0.8 ;
5160
61+ // sprite.angle = 35;
62+
63+ game . camera . follow ( sprite ) ;
64+
65+ game . input . onDown . add ( getIt , this ) ;
66+
67+ cursors = game . input . keyboard . createCursorKeys ( ) ;
5268
5369}
5470
55- function dump ( ) {
71+ function getIt ( ) {
5672
57- console . log ( sprite . bounds ) ;
58- console . log ( sprite . body . hull ) ;
59- console . log ( 'wy' , sprite . world . y ) ;
73+ console . log ( 'cam' , game . camera . bounds ) ;
74+ console . log ( 'w' , game . world . bounds ) ;
75+ // console.log(layer.getTiles(sprite.body.x , sprite.body.y, sprite.body.width, sprite.body.height, true, true) );
6076
6177}
6278
6379function update ( ) {
6480
65- /*
81+ /*
6682 if (cursors.left.isDown)
6783 {
68- layer.scrollX -= 4 ;
84+ game.camera.x -= 1 ;
6985 }
7086 else if (cursors.right.isDown)
7187 {
72- layer.scrollX += 4 ;
88+ game.camera.x += 1 ;
7389 }
7490
7591 if (cursors.up.isDown)
@@ -80,10 +96,42 @@ function update() {
8096 {
8197 layer.scrollY += 4;
8298 }
83- */
84-
99+ */
85100 game . physics . collide ( sprite , layer ) ;
86101
102+ sprite . body . velocity . x = 0 ;
103+ sprite . body . velocity . y = 0 ;
104+ sprite . body . angularVelocity = 0 ;
105+
106+ // sprite.body.acceleration.x = 0;
107+ // sprite.body.angularAcceleration = 0;
108+
109+ if ( cursors . left . isDown )
110+ {
111+ // sprite.body.acceleration.x = -200;
112+ sprite . body . angularVelocity = - 300 ;
113+ // sprite.body.angularAcceleration -= 200;
114+ }
115+ else if ( cursors . right . isDown )
116+ {
117+ // sprite.body.acceleration.x = 200;
118+ sprite . body . angularVelocity = 300 ;
119+ // sprite.body.angularAcceleration += 200;
120+ }
121+
122+ if ( cursors . up . isDown )
123+ {
124+ game . physics . velocityFromAngle ( sprite . angle , 300 , sprite . body . velocity ) ;
125+ }
126+ else
127+ {
128+ // game.physics.velocityFromAngle(sprite.angle, sprite.body.velocity, sprite.body.velocity);
129+ }
130+
131+
132+
133+
134+ /*
87135 sprite.body.velocity.x = 0;
88136 sprite.body.velocity.y = 0;
89137
@@ -108,6 +156,7 @@ function update() {
108156 sprite.body.velocity.x = 900;
109157 // sprite.scale.x = 1;
110158 }
159+ */
111160
112161
113162}
@@ -117,7 +166,10 @@ function render() {
117166 // game.debug.renderSpriteBody(sprite);
118167 game . debug . renderSpriteBounds ( sprite ) ;
119168
120- game . debug . renderText ( sprite . x , 32 , 32 ) ;
121- game . debug . renderText ( sprite . y , 32 , 48 ) ;
169+ // game.debug.renderText(sprite.x, 32, 32);
170+ // game.debug.renderText(sprite.y, 32, 48);
171+
172+ game . debug . renderText ( layer . scrollX , 32 , 32 ) ;
173+ game . debug . renderText ( layer . scrollY , 32 , 48 ) ;
122174
123175}
0 commit comments