Jump to content

[PROBLEM] I have a bit of a problem...


Djennxs
 Share

Recommended Posts

Hey guys!

 

I just recently started screwing around with Phaser and it went great, up untill now...

I opened my laptop and started up my XAMPP server to get back to work, then this happened (attached files).

 

I have no idea what happened or what it is doing. 

Also, here is my code:

<html><head>	<title>HTML5</title>	<script src="phaser.js"></script>	<style>	body{margin:0; position: absolute; width: 100%; height: 100%;}	canvas{margin-left: 15%; margin-top: 8%;}	</style>	<script src="game.js"></script></head><body>	Deaths: <span id="deaths"></span><br>	Rounds: <span id="rounds"></span></body></html>
window.onload = function(){		// var windowWidth = document.body.clientWidth;		// var windowHeight = document.body.clientHeight;		var deaths = -3;		var game = new Phaser.Game(900,480,Phaser.CANVAS,"", {preload: onPreload, create:onCreate, update:onUpdate});		var theSquare;		var xSpeed = 6;		var jumpHeight = 70;		var jumpWidth = 180;		var jumpRotation = 180;		var jumpTime = 0;		var isJumping = false;		var degToRad = 0.0174532925;		var floorY = Array(460,230);		var floorX;		var currentFloor = 0;		var floorHeight = 20;		var levelStart = 0;		var objectStart;		var levelEnd = 900;		var rounds = 0;		function onPreload(){			game.load.image("square", "square.png");			game.load.image("floorsmall", "floorsmall.png");			game.load.image("floormedium", "floormedium.png");			game.load.image("floorbig", "floorbig.png");		}		function onCreate(){				var floor1 = game.add.graphics(0,0);				floor1.lineStyle(floorHeight, 0x440044, 1);				for(i = 0; i < floorY.length; i++){					floor1.moveTo(levelStart, floorY[i] + floorHeight/2);					floor1.lineTo(levelEnd, floorY[i] + floorHeight/2);				}								floorX =	Array(game.add.sprite(objectStart,floorY[currentFloor]-game.cache.getImage("floorsmall").height,"floorsmall"), 							game.add.sprite(objectStart,floorY[currentFloor]-game.cache.getImage("floormedium").height,"floormedium"),							game.add.sprite(objectStart,floorY[currentFloor]-game.cache.getImage("floorbig").height,"floorbig"));				theSquare = game.add.sprite(levelStart,floorY[currentFloor]-game.cache.getImage("square").height/2,"square");								theSquare.anchor.setTo(0.5, 0.5);				game.input.onDown.add(jump, this);			if (currentFloor == 0){				objectStart = Array(250, 450, 650);				for(i = 0; i < floorX.length; i++){					floorX[i].x = objectStart[i];				}			}		}		function jump(){			if(!isJumping){				jumpTime = 0;				isJumping = true;			}		}		function collHandler(obj1, obj2){			if(game.physics.overlap(obj1, obj2)){				theSquare.x = levelStart;				deaths = deaths + 1;				document.getElementById('deaths').innerHTML = deaths;				rounds = 0;			}		}		function onUpdate(){			for(i = 0; i < floorX.length; i++){				collHandler(theSquare, floorX[i]);			}			var mod = currentFloor % 2;			theSquare.x += xSpeed * (1 - 2 * mod);			if(theSquare.x > levelEnd && mod == 0 || theSquare.x < levelStart && mod == 1){								currentFloor++;								if(currentFloor > floorY.length - 1){					currentFloor = 0;				}				mod = currentFloor % 2;				//WERKT NIET!!!!!				if(theSquare.x == levelStart){					currentFloor = 0;					rounds = rounds + 1;					alert('ok');					document.getElementById('rounds').innerHTML = rounds;				}				isJumping = false;				theSquare.rotation = 0;				theSquare.x = levelEnd * mod + levelStart * (1 - mod);                theSquare.y = floorY[currentFloor]-game.cache.getImage("square").height / 2;			}			if(isJumping){				var jumpFrames = jumpWidth / xSpeed;				var degreesPerFrame = jumpRotation / jumpFrames * (1 - 2 * mod);				var radiansPerFrame = (180 / jumpFrames) * degToRad;				jumpTime++;				theSquare.angle += degreesPerFrame;				theSquare.y = floorY[currentFloor]-game.cache.getImage("square").height / 2 - jumpHeight * Math.sin(radiansPerFrame * jumpTime);				if(jumpTime == jumpFrames){					isJumping = false;					theSquare.y = floorY[currentFloor]-game.cache.getImage("square").height / 2;				}			}		}		function onRender(){		}	};			// window.onresize = function(e){		 //        var theCanvas = document.querySelector('canvas');		 //        theCanvas.height = document.body.clientHeight + 'px';		 //        theCanvas.width = document.body.clientWidth + 'px';		 //    }

It's not perfect, but it works... Well, worked. Anybody who has an idea?

 

post-6488-0-86380300-1391097982_thumb.pn

Link to comment
Share on other sites

Hi!

I'm not sure about the problem, but i'm going to sugget some changes in your code to discover the problem...

index.html

<html><head>	<title>HTML5</title>	<script src="phaser.js"></script>	<style>	body{margin:0; position: absolute; width: 100%; height: 100%;}	canvas{margin-left: 15%; margin-top: 8%;}	</style>	<script src="game.js"></script></head><body>        <div id="gameContainer"></div> <!-- The game container -->	Deaths: <span id="deaths"></span><br>	Rounds: <span id="rounds"></span></body></html>

The js file

window.onload = function(){    // var windowWidth = document.body.clientWidth;    // var windowHeight = document.body.clientHeight;    var deaths = -3;    var game = new Phaser.Game(900,480,Phaser.CANVAS,"gameContainer", {preload: onPreload, create:onCreate, update:onUpdate});...

What are you seeing in the dev console? 
Try this, maybe it works.

Link to comment
Share on other sites

All I can recommand is making your html file like this:

<!DOCTYPE html><html><head>        <meta charset="utf-8"/>	<title>HTML5</title>	<style>	body{margin:0; position: absolute; width: 100%; height: 100%;}	canvas{margin-left: 15%; margin-top: 8%;}	</style></head><body>	Deaths: <span id="deaths"></span><br>	Rounds: <span id="rounds"></span>        <script src="phaser.js"></script>        <script src="game.js"></script></body></html>

Basically, adding the html5 doctype setting the page encoding to utf8 and making the script tags at the end of the body to make sure the page is loaded when your script is run, and also to improve page load time.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...