mirror of
https://github.com/wassname/phaser.git
synced 2026-08-02 13:00:25 +08:00
Sprite.loadTexture added.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
$title = "Changing a Sprite Texture";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.atlasJSONHash('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
||||
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
|
||||
|
||||
}
|
||||
|
||||
var bot;
|
||||
|
||||
function create() {
|
||||
|
||||
bot = game.add.sprite(200, 200, 'bot');
|
||||
|
||||
bot.animations.add('run');
|
||||
|
||||
bot.animations.play('run', 15, true);
|
||||
|
||||
game.input.onDown.addOnce(changeMummy, this);
|
||||
|
||||
}
|
||||
|
||||
function changeMummy() {
|
||||
|
||||
bot.loadTexture('mummy', 0);
|
||||
|
||||
bot.animations.add('walk');
|
||||
|
||||
bot.animations.play('walk', 30, true);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderSpriteBounds(bot);
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create });
|
||||
|
||||
function preload() {
|
||||
@@ -34,8 +32,6 @@
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
Binary file not shown.
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
$title = "Transform Tests";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('atari', 'assets/sprites/atari130xe.png');
|
||||
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
|
||||
|
||||
}
|
||||
|
||||
var testGroup;
|
||||
var sprite1;
|
||||
var sprite2;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = '#2d2d2d';
|
||||
|
||||
game.world.setBounds(-1000, -1000, 2000, 2000);
|
||||
|
||||
testGroup = game.add.group();
|
||||
|
||||
test2();
|
||||
|
||||
}
|
||||
|
||||
function test1 () {
|
||||
|
||||
// Test 1 - 2 sprites in world space (seems to work fine with local transform?)
|
||||
sprite1 = game.add.sprite(-600, 200, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
// sprite1.body.setSize(100, 100, 0, 0);
|
||||
|
||||
sprite2 = game.add.sprite(-100, 220, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
|
||||
game.camera.focusOn(sprite1);
|
||||
game.camera.x += 300;
|
||||
|
||||
game.input.onDown.add(go1, this);
|
||||
|
||||
}
|
||||
|
||||
function test2 () {
|
||||
|
||||
// 1 sprite in world space (seems to work fine with local transform?) and 1 in a group
|
||||
|
||||
sprite1 = testGroup.create(0, -150, 'atari');
|
||||
sprite1.name = 'atari';
|
||||
sprite1.body.immovable = true;
|
||||
// sprite1.body.setSize(100, 100, 0, 0);
|
||||
|
||||
sprite2 = game.add.sprite(-100, 150, 'mushroom');
|
||||
sprite2.name = 'mushroom';
|
||||
|
||||
testGroup.x = -600;
|
||||
testGroup.y = 200;
|
||||
|
||||
game.camera.focusOn(sprite2);
|
||||
game.camera.x -= 300;
|
||||
|
||||
game.input.onDown.add(go2, this);
|
||||
|
||||
}
|
||||
|
||||
function go1 () {
|
||||
|
||||
sprite1.body.velocity.x = 100;
|
||||
sprite2.body.velocity.x = -100;
|
||||
|
||||
}
|
||||
|
||||
function go2 () {
|
||||
|
||||
sprite2.body.velocity.x = -100;
|
||||
|
||||
}
|
||||
|
||||
function update () {
|
||||
|
||||
game.physics.collide(sprite1, sprite2, collisionHandler, null, this);
|
||||
|
||||
}
|
||||
|
||||
function collisionHandler (obj1, obj2) {
|
||||
|
||||
game.stage.backgroundColor = '#992d2d';
|
||||
|
||||
console.log(obj1.name + ' collided with ' + obj2.name);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
// game.debug.renderSpriteInfo(sprite1, 32, 32);
|
||||
// game.debug.renderSpriteCollision(sprite1, 32, 400);
|
||||
|
||||
game.debug.renderSpriteCoords(sprite1, 32, 32);
|
||||
game.debug.renderSpriteCoords(sprite2, 300, 32);
|
||||
|
||||
game.debug.renderCameraInfo(game.camera, 32, 500);
|
||||
|
||||
game.debug.renderSpriteBody(sprite1);
|
||||
game.debug.renderSpriteBody(sprite2);
|
||||
|
||||
game.debug.renderGroupInfo(testGroup, 500, 500);
|
||||
game.debug.renderPixel(testGroup.x, testGroup.y, 'rgb(255,255,0)');
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -1,6 +1,14 @@
|
||||
<?php
|
||||
$title = "Tanks";
|
||||
require('../head.php');
|
||||
$title = "Tanks " . $_SERVER['SERVER_NAME'];
|
||||
|
||||
if ($_SERVER['SERVER_NAME'] == 'gametest.mobi')
|
||||
{
|
||||
require('head_live.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
require('../head.php');
|
||||
}
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
@@ -82,12 +90,14 @@
|
||||
|
||||
};
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
|
||||
// var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload () {
|
||||
|
||||
game.load.atlas('tank', 'assets/games/tanks/tanks.png', 'assets/games/tanks/tanks.json');
|
||||
game.load.atlas('enemy', 'assets/games/tanks/enemy-tanks.png', 'assets/games/tanks/tanks.json');
|
||||
game.load.image('logo', 'assets/games/tanks/logo.png');
|
||||
game.load.image('bullet', 'assets/games/tanks/bullet.png');
|
||||
game.load.image('earth', 'assets/games/tanks/scorched_earth.png');
|
||||
game.load.spritesheet('kaboom', 'assets/games/tanks/explosion.png', 64, 64, 23);
|
||||
@@ -104,6 +114,8 @@
|
||||
var enemyBullets;
|
||||
var explosions;
|
||||
|
||||
var logo;
|
||||
|
||||
var currentSpeed = 0;
|
||||
var cursors;
|
||||
|
||||
@@ -145,7 +157,7 @@
|
||||
// Create some baddies to waste :)
|
||||
enemies = [];
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
enemies.push(new EnemyTank(i, game, tank, enemyBullets));
|
||||
}
|
||||
@@ -174,14 +186,26 @@
|
||||
tank.bringToTop();
|
||||
turret.bringToTop();
|
||||
|
||||
logo = game.add.sprite(0, 200, 'logo');
|
||||
logo.fixedToCamera = true;
|
||||
|
||||
game.input.onDown.add(removeLogo, this);
|
||||
|
||||
game.camera.follow(tank);
|
||||
game.camera.deadzone = new Phaser.Rectangle(100, 100, 600, 400);
|
||||
game.camera.deadzone = new Phaser.Rectangle(150, 150, 500, 300);
|
||||
game.camera.focusOnXY(0, 0);
|
||||
|
||||
cursors = game.input.keyboard.createCursorKeys();
|
||||
|
||||
}
|
||||
|
||||
function removeLogo () {
|
||||
|
||||
game.input.onDown.remove(removeLogo, this);
|
||||
logo.kill();
|
||||
|
||||
}
|
||||
|
||||
function update () {
|
||||
|
||||
game.physics.collide(enemyBullets, tank, bulletHitPlayer, null, this);
|
||||
@@ -290,5 +314,12 @@
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
if ($_SERVER['SERVER_NAME'] == 'gametest.mobi')
|
||||
{
|
||||
require('foot.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
require('../foot.php');
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,8 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>phaser - <?php echo $title?></title>
|
||||
<script src="phaser.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
Reference in New Issue
Block a user