Created
June 3, 2018 00:36
-
-
Save blakedallen/f771d8e0615ff8d35f0630db6a10bd6d to your computer and use it in GitHub Desktop.
Phaser Render error
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> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.2/phaser.min.js"></script> | |
</head> | |
<body> | |
<script> | |
var player; | |
var cursors; | |
var pixelWidth = 12; | |
var pixelHeight = 12; | |
var frame = 0; | |
var CURRENT_CYCLE = 0; | |
var MAX_CYCLES = 3; | |
var state = 'cat'; | |
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: create, update:update }); | |
function create() { | |
var cat = [ | |
'....443...443.', | |
'...4433..4433.', | |
'..44333.48333.', | |
'88888888244444', | |
'44444444433333', | |
'44444444433333', | |
'44044404433333', | |
'44488844433333', | |
'44400044433333', | |
'44F202F4433333', | |
'44202024433333', | |
'44F222F4433333', | |
'44444444433333', | |
'4433...4433.33', | |
'4433...4433.33' | |
]; | |
console.log(cat); | |
game.create.texture('cat', cat, pixelWidth, pixelHeight); | |
var burd = [ | |
"A682EA1D51D8D46", | |
"5.1628F1.F81757", | |
"1A6F2672B234AE1", | |
"B.8BB42746AFA22", | |
"E4.113385.D1.D.", | |
"6EF22BA.66181D3", | |
"7E18A7DD6F8F3D2", | |
".D47D225761427D", | |
"B4BDA5DE..778E7", | |
"1B46.BEF48321D8", | |
"FF6.7.347746D2.", | |
"A2AF57B4B4F4.DD", | |
"EAD335264158B14", | |
"A133FB31E4.E728", | |
"FAF52EBF7.3E81D"]; | |
game.create.texture('burd', burd, pixelWidth, pixelHeight); | |
var selections = [".","1","2","3","4","5","6","7","8","A","B","D","E","F"] | |
var d = []; | |
for (var i = 0; i < 15; i++){ | |
var inner = []; | |
for (var j = 0; j < 15; j++){ | |
var idx = Math.floor(Math.random() * selections.length); | |
var item = selections[idx]; | |
inner.push(item); | |
//inner.push("5") | |
} | |
d.push(inner.join('')); | |
} | |
//console.log(burd, data) | |
console.log(d); | |
game.create.texture('rand',d, pixelWidth, pixelHeight); | |
player = game.add.sprite(300, 300, 'burd'); | |
player.anchor.set(0.5); | |
game.physics.arcade.enable(player); | |
cursors = game.input.keyboard.createCursorKeys(); | |
game.input.onDown.add(changeMummy, this); | |
} | |
function update() { | |
frame += 1; | |
if (frame >= 30) { | |
frame = 0; | |
CURRENT_CYCLE += 1; | |
} | |
player.body.velocity.x = 0; | |
player.body.velocity.y = 0; | |
if (cursors.left.isDown) | |
{ | |
player.body.velocity.x = -200; | |
player.scale.x = 1; | |
} | |
else if (cursors.right.isDown) | |
{ | |
player.body.velocity.x = 200; | |
player.scale.x = -1; | |
} | |
if (cursors.up.isDown) | |
{ | |
player.body.velocity.y = -200; | |
player.scale.y = 1; | |
} | |
else if (cursors.down.isDown) | |
{ | |
player.body.velocity.y = 200; | |
player.scale.y = -1; | |
} | |
// if ((frame % 3 == 0) && (MAX_CYCLES > CURRENT_CYCLE)) { | |
// randomMap() | |
// } | |
} | |
function changeMummy() { | |
if (state === 'cat') { | |
player.loadTexture('burd', 0); | |
state = 'burd'; | |
} else { | |
player.loadTexture('cat', 0); | |
state = 'cat'; | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment