Better Render + Speed %

This commit is contained in:
MasterGordon 2018-04-06 11:37:20 +02:00
parent ede4e5b7d2
commit 7ec6389141
4 changed files with 45 additions and 7 deletions

View File

@ -52,6 +52,7 @@
<span id="money"> <span id="money">
??? Dollar ??? Dollar
</span> </span>
<span style="position: fixed;color: white" id="speed"></span>
</body> </body>
</html> </html>

View File

@ -186,11 +186,16 @@ class Factory {
moveItems() { moveItems() {
for (var i = 0; i < this.items.length; i++) { for (var i = 0; i < this.items.length; i++) {
this.items[i].move() this.items[i].move()
if (this.items[i].x % 48 == 0 && this.items[i].y % 48 == 0) { if (this.items[i].x <= 0 || this.items[i].x >= 1200 || this.items[i].y <= 0 || this.items[i].y >= 576) {
var tile = this.tiles[this.items[i].x / 48][this.items[i].y / 48] console.log("removed Item")
if (tile != 0) { this.deleteItem(this.items[i])
if (tile.input.items.indexOf(this.items[i]) == -1) } else {
tile.input.addItem(this.items[i]) if (this.items[i].x % 48 == 0 && this.items[i].y % 48 == 0) {
var tile = this.tiles[this.items[i].x / 48][this.items[i].y / 48]
if (tile != 0) {
if (tile.input.items.indexOf(this.items[i]) == -1)
tile.input.addItem(this.items[i])
}
} }
} }
} }

View File

@ -128,7 +128,7 @@ function loadLang() {
lang = json lang = json
} }
function loopp(timestamp) { function loop(timestamp) {
//Check Gametick Rate //Check Gametick Rate
if (timestamp < lastFrameTimeMs + (1000 / 48)) { if (timestamp < lastFrameTimeMs + (1000 / 48)) {
requestAnimationFrame(loop) requestAnimationFrame(loop)
@ -152,7 +152,7 @@ function loopp(timestamp) {
var lastRender = 0 var lastRender = 0
function loop(timestamp) { function loopp(timestamp) {
var progress = timestamp - lastRender var progress = timestamp - lastRender
gametick(progress) gametick(progress)
@ -161,6 +161,7 @@ function loop(timestamp) {
lastRender = timestamp lastRender = timestamp
window.requestAnimationFrame(loop) window.requestAnimationFrame(loop)
} }
var tick = []
function gametick(timestep) { function gametick(timestep) {
//time gibt an in den Wievielten von 40 Ticks man sich befindet //time gibt an in den Wievielten von 40 Ticks man sich befindet
@ -172,6 +173,11 @@ function gametick(timestep) {
factorys[i].workTiles() factorys[i].workTiles()
factorys[i].despawnOldItems() factorys[i].despawnOldItems()
} }
tick.push(new Date().getTime())
if (tick.length > 48) {
tick = tick.splice(1)
$("#speed").text("Game Speed: " + ((tick[47] - tick[0]+30) / 10) + "%")
}
} }
function render() { function render() {

26
test.html Normal file
View File

@ -0,0 +1,26 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<script src="js/libs/pixi.min.js"></script>
<body>
<script type="text/javascript">
//Create a Pixi Application
let app = new PIXI.Application({
width: 256, // default: 800
height: 256, // default: 600
antialias: false, // default: false
transparent: true, // default: false
resolution: 1 // default: 1
});
//Add the canvas that Pixi automatically created for you to the HTML document
document.body.appendChild(app.view);
</script>
</body>
</html>