mirror of
https://github.com/wassname/phaser.git
synced 2026-08-02 13:00:25 +08:00
Direct assignment of Body values, allows for sloped ground walking.
This commit is contained in:
@@ -62,6 +62,7 @@ function update() {
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderBodyInfo(car, 16, 24);
|
||||
// game.debug.renderBodyInfo(car, 16, 24);
|
||||
game.debug.renderBodyInfo(aliens.getFirstAlive(), 16, 24);
|
||||
|
||||
}
|
||||
|
||||
+23
-35
@@ -10,6 +10,7 @@ function preload() {
|
||||
var sprite;
|
||||
var sprite2;
|
||||
var land;
|
||||
var cursors;
|
||||
|
||||
function create() {
|
||||
|
||||
@@ -39,10 +40,13 @@ function create() {
|
||||
new SAT.Vector(780,100),
|
||||
new SAT.Vector(0,100),
|
||||
]);
|
||||
console.log(land);
|
||||
sprite.body.velocity.x = 100;
|
||||
|
||||
game.input.onDown.add(launch, this);
|
||||
console.log(land);
|
||||
|
||||
// sprite.body.velocity.x = 150;
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
// game.input.onDown.add(launch, this);
|
||||
|
||||
}
|
||||
|
||||
@@ -55,42 +59,26 @@ function launch() {
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Tweening body scale test!
|
||||
|
||||
sprite = game.add.sprite(300, 300, 'gameboy', 0);
|
||||
sprite.name = 'red';
|
||||
sprite.body.collideWorldBounds = true;
|
||||
// sprite.body.checkCollision.right = false;
|
||||
sprite.body.bounce.setTo(1, 1);
|
||||
sprite.body.friction = 0;
|
||||
// sprite.scale.setTo(2, 2);
|
||||
|
||||
sprite2 = game.add.sprite(500, 300, 'gameboy', 2);
|
||||
sprite2.name = 'green';
|
||||
sprite2.body.collideWorldBounds = true;
|
||||
sprite2.body.bounce.setTo(1, 1);
|
||||
sprite2.body.friction = 0;
|
||||
|
||||
game.add.tween(sprite.scale).to({x: 3, y: 3}, 2000, Phaser.Easing.Linear.None, true, 0, 1000, true);
|
||||
// to: function (properties, duration, ease, autoStart, delay, repeat, yoyo) {
|
||||
|
||||
|
||||
*/
|
||||
|
||||
function update() {
|
||||
|
||||
// game.physics.collide(sprite, land);
|
||||
game.physics.collide(sprite, land);
|
||||
|
||||
if (sprite.body.overlap(land.body))
|
||||
{
|
||||
console.log('o', sprite.body.response);
|
||||
sprite.body.separate(land.body);
|
||||
}
|
||||
sprite.body.velocity.x = 0;
|
||||
// sprite.body.velocity.y = 0;
|
||||
|
||||
if (cursors.left.isDown)
|
||||
{
|
||||
sprite.body.velocity.x = -100;
|
||||
}
|
||||
else if (cursors.right.isDown)
|
||||
{
|
||||
sprite.body.velocity.x = 100;
|
||||
}
|
||||
|
||||
// game.physics.collide(sprite, sprite2);
|
||||
// game.physics.collide(sprite2, land);
|
||||
if (cursors.up.isDown)
|
||||
{
|
||||
sprite.body.velocity.y = -200;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -113,7 +101,7 @@ function render() {
|
||||
game.debug.renderPolygon(sprite2.body.polygons);
|
||||
}
|
||||
|
||||
game.debug.renderRectangle(land.body);
|
||||
// game.debug.renderRectangle(land.body);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('phaser', 'assets/sprites/phaser1.png');
|
||||
game.load.spritesheet('arrows', 'assets/sprites/arrows.png', 23, 31);
|
||||
|
||||
}
|
||||
|
||||
var arrowStart;
|
||||
var arrowEnd;
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2384e7';
|
||||
|
||||
arrowStart = game.add.sprite(100, 100, 'arrows', 0);
|
||||
|
||||
arrowEnd = game.add.sprite(400, 100, 'arrows', 1);
|
||||
|
||||
sprite = game.add.sprite(100, 164, 'phaser');
|
||||
sprite.inputEnabled = true;
|
||||
|
||||
sprite.events.onInputDown.add(move, this);
|
||||
|
||||
}
|
||||
|
||||
function move() {
|
||||
|
||||
var tween = game.add.tween(sprite).to( { x: '+500' }, 3000, Phaser.Easing.Linear.None, true);
|
||||
|
||||
tween.onComplete.add(over, this);
|
||||
|
||||
}
|
||||
|
||||
function over() {
|
||||
console.log('done');
|
||||
sprite.alpha = 0.5;
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (sprite.x > 200)
|
||||
{
|
||||
sprite.x = 200;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.spritesheet('gameboy', 'assets/sprites/gameboy_seize_color_40x60.png', 40, 60);
|
||||
|
||||
}
|
||||
|
||||
var sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#124184';
|
||||
|
||||
game.physics.gravity.y = 200;
|
||||
|
||||
sprite = game.add.sprite(200, 250, 'gameboy', 4);
|
||||
sprite.name = 'green';
|
||||
// sprite.anchor.setTo(0.5, 0.5);
|
||||
|
||||
sprite.body.bounce.setTo(0.9, 0.9);
|
||||
sprite.body.velocity.x = 150;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
// sprite.worldTransform[2] += 1;
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderBodyInfo(sprite, 32, 32);
|
||||
game.debug.renderPolygon(sprite.body.polygons);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user