-
-
Save ellioman/e508aacd4f07028645aa126bc5474d06 to your computer and use it in GitHub Desktop.
Phaser and Creature Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>hello phaser!</title> | |
<script src="phaser.js"></script> | |
<script src="gl-matrix.js"></script> | |
<script src="flatbuffers.js"></script> | |
<script src="CreatureFlatData_generated.js"></script> | |
<script src="CreatureMeshBone.js"></script> | |
<script src="CreaturePixiJSRenderer.js"></script> | |
<script src="CreaturePhaserRenderer.js"></script> | |
</head> | |
<body> | |
<script type="text/javascript"> | |
window.onload = function() | |
{ | |
var game = new Phaser.Game(800, 600, Phaser.WEBGL, '', { preload: preload, create: create, update: update}); | |
var texture = null; | |
var demonCreature = null; | |
var demonDefaultAnimation = null; | |
var new_animation_2 = null; | |
var demonCreatureManager = null; | |
var creaturePhasorObject = null; | |
var bone1 = null; | |
var bone2 = null; | |
var bone3 = null; | |
var bone4 = null; | |
var bonePos1 = null; | |
var bonePos2 = null; | |
var bonePos3 = null; | |
var bonePos4 = null; | |
var bunny1 = null; | |
var bunny2 = null; | |
var bunny3 = null; | |
var bunny4 = null; | |
// For testing | |
var demonCreatureManager2 = null; | |
var creaturePhasorObject2 = null; | |
function preload () | |
{ | |
game.load.image('bunny', 'bunny.png'); | |
game.load.text('demonJSON', 'iceDemonExport.json'); | |
texture = PIXI.Texture.fromImage("iceDemonExport.png"); | |
} | |
function create() | |
{ | |
/****************************** | |
Demon Creature | |
*******************************/ | |
// Core Creature Objects | |
var actual_JSON = JSON.parse(game.cache.getText('demonJSON')); | |
demonCreature = new Creature(actual_JSON, false); | |
demonDefaultAnimation = new CreatureAnimation(actual_JSON, "default", false); | |
demonCreatureManager = new CreatureManager(demonCreature); | |
demonCreatureManager.AddAnimation(demonDefaultAnimation); | |
demonCreatureManager.SetActiveAnimationName("default", false); | |
demonCreatureManager.SetShouldLoop(true); | |
demonCreatureManager.SetIsPlaying(true); | |
// Get the bones... | |
bone1 = demonCreature.render_composition.root_bone.getChildByKey("Bone_15"); | |
bone2 = demonCreature.render_composition.root_bone.getChildByKey("Bone_17"); | |
bone3 = demonCreature.render_composition.root_bone.getChildByKey("Bone_12"); | |
bone4 = demonCreature.render_composition.root_bone.getChildByKey("Bone_20"); | |
// Phaser Creature Object | |
creaturePhasorObject = new Phaser.CreatureDraw(game.world, | |
game.world.centerX, | |
game.world.centerY, | |
demonCreatureManager, | |
texture); | |
creaturePhasorObject.scale.set(23.0); | |
creaturePhasorObject.timeDelta = 0.035; | |
game.world.add(creaturePhasorObject); | |
/****************************** | |
Bunny | |
*******************************/ | |
bunny1 = game.add.sprite(0, 0, 'bunny'); | |
bunny1.anchor.setTo(0.5, 0.5); | |
// bunny2 = game.add.sprite(game.world.centerX, game.world.centerY, 'bunny'); | |
// bunny2.anchor.setTo(0.5, 0.5); | |
// bunny3 = game.add.sprite(game.world.centerX, game.world.centerY, 'bunny'); | |
// bunny3.anchor.setTo(0.5, 0.5); | |
// bunny4 = game.add.sprite(game.world.centerX, game.world.centerY, 'bunny'); | |
// bunny4.anchor.setTo(0.5, 0.5); | |
// game.world.add(bunny1); | |
} | |
function update() | |
{ | |
// Update the bunny objects position | |
var world = creaturePhasorObject.world; | |
bonePos1 = bone1.getWorldStartPt(); | |
bunny1.position.x = bonePos1[0]; | |
bunny1.position.y = bonePos1[1]; | |
// bonePos2 = bone2.getWorldStartPt(); | |
// bunny2.position.x = world.x + bonePos2[0]; | |
// bunny2.position.y = world.y + bonePos2[1]; | |
// bonePos3 = bone3.getWorldStartPt(); | |
// bunny3.position.x = world.x + bonePos3[0]; | |
// bunny3.position.y = world.y + bonePos3[1]; | |
// bonePos4 = bone4.getWorldStartPt(); | |
// bunny4.position.x = world.x + bonePos4[0]; | |
// bunny4.position.y = world.y + bonePos4[1]; | |
} | |
}; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment