zazazayou

Members
  • Content count

    8
  • Joined

  • Last visited

  1. Saving and Loading

    thanks, that sounds like its exactly what i need to look into
  2. Saving and Loading

    I have been working on a game in javascript, and I'm stuck as to how to handle saving and loading. I want to ultimately publish it both as an online browser game and as a downloadable desktop application (which I'd do with electron). But for now it is just a browser game. You can see it here by the way on my github page: https://jpchaufan.github.io/ What I have going now is not really working. I tried using local storage. The problem is that the game is kind of minecraft-like, in that it has an infinite world, that keeps generating as you walk around. When I stringify the world data into JSON, it is huge, like easily 6 million characters long, and potentially way more as the player walks around even a little bit. As a result, saving the game takes FOREVER, and practically crashes the browser if the world has been explored much. I also tried another alternative, to try and avoid the limitations of local storage. I tried just printing out the save data for the player to copy and save manually themselves. Then give them the option of loading the game from local storage, or letting them copy in their own data to load. This didnt really solve the problem. It still takes forever to print the data out, and lets the player cheat too easily. I tried encrypting the data but it already takes too long to do, so it just made it worse. Now I am hoping that this becomes easier on a desktop version of the game, or if I actually put the game online on a real webpage with a back-end. I actually would hope that the game can auto-save, so that the player can't go back if he dies or messes up. I mean my game is pretty simplistic compared to a game like minecraft or any MMO that has a big world.
  3. Collision breaks when loading in a Tiled tilemap

    Thanks MTiger, that solution worked, just increasing the tile bias, like this: this.game.physics.arcade.TILE_BIAS *= 2; This article here explained why, in case anyone is interested: http://thoughts.amphibian.com/2016/02/dont-fall-through-tile-bias-in-phaser.htm
  4. I m building a little platformer-type game and am having this problem: When the player is moving really fast, (basically when he falls a large distance) he no longer collides with stuff, and falls right through the floor. This problem comes up when I switch from making regular sprites in a group for floors and platforms, to loading in a tilemap from Tiled. I also notice a change, which is my only hint that something is working differently with the physics - the sprite's body.touching property no longer reads, and instead body.blocked now reads. So for example, if I let the player jump only if player.touching.down is true, I have to switch this condition when using the Tiled tilemap to player.blocked.down, because touching becomes always false. I don't really know phaser well enough to know why this is, but I just know its weird. here is how my code was before, when just making a group of sprites for platforms: this.platforms = this.add.group(); this.platforms.enableBody = true; var element; platformData.forEach(function( platform ){ element = this.platforms.create(platform.x, platform.y, 'green'); element.scale.setTo(platform.scaleX, platform.scaleY); }, this); this.platforms.setAll('body.immovable', true); // so they don't fall this.platforms.setAll('body.allowGravity', false); // so they can't be moved by other bodies and here is how it is when I load the map from Tiled: //create a tilemap object this.map = this.add.tilemap('level1'); //join the tile images to the json data this.map.addTilesetImage('tilesheet', 'gameTiles'); //create tile layers this.tileLayer = this.map.createLayer('tileLayer'); //collision layer should be collisionLayer this.map.setCollisionBetween(1, 1, true, 'tileLayer'); //resize the world to fit the layer this.tileLayer.resizeWorld(); And in update(): this.game.physics.arcade.collide(this.player, this.tileLayer); So it's weird, it collides just fine in every case, except when loading stuff from Tiled and moving really fast, and I don't really know why in one case bodies touch and in the other case bodies block, or what the difference really is supposed to mean.
  5. so i have a game where there are different enemies who look different and so have different spritesheets. and i have a pool of objects mechanism to recycle the dead enemy objects into new ones, kinda like this: var enemy = this.state.enemies.getFirstDead(); if (!enemy){ enemy = new MyGame.Enemy(this.state, cords.x, cords.y, data); this.state.enemies.add(enemy); } else { enemy.reset(cords.x, cords.y, data); } so the problem is like this: sprites are not properly having their animations changed from their old selves to their new selves. their sprites change properly for the most part but are keeping bits of info from the old animations, ie they are not being fully replaced when i call the this.animations.add again. the data parameter is an object with a buncha info about each enemy, including animation info. kinda like this: { key: 'troll', scale: 0.8, health: 20, movementSpeed: 60, attack: {amount: 2, delay: 0.5, type: 'physical', frames: [0, 1, 2, 3, 4, 5, 6, 7], fps: 16}, death: {frames: Phaser.ArrayUtils.numberArray(0, 31), fps: 32} } so in my modified reset method, which runs actually every time an enemy is created, these animations are made, pulling the frames and stuff from data and making an animation, like this (in the reset method of Enemy): this.animations.add('attack', this.data.attack.frames, this.data.attack.fps || 12, false); and when i run that line with different data on a sprite that was recycled, the data is not fully over-written, resulting in these mutating enemies that change from trolls to scorpions as their various animations play. the first thing i tried was calling this.animations.destroy() on my modified .kill() method that is called on all dying sprites, i thought that shoulda fixed it... but then i immediately get this error, 'Cannot read property 'getFrameIndexes' of null(…)', as if the animations were not being properly cleared and then added freshly again. i hope this made sense, thanks for the help guys.
  6. thanks for the help tom, it worked out when I made all the frames the same size and then adjusted the collision box specially for frames like duck, like you said
  7. ok but then how would i deal with the smaller pictures that get a bunch of extra space added to their collision box? all the smaller frames will collide before the image actually touches
  8. I am running into all sorts of trouble when animating sprites with frames of different dimensions. I mean like if frame 1 of a walk animation is 30x35 and frame 2 is 38x38, for example, i have a problem keeping the sprite level with the floor. it will either fall through the floor, or be up in the air. I have tried to set the anchor y point to 1 so that it stays level with the ground, this would be ideal if it worked I have tried using setSize to try and keep the sprite object's dimensions fixed throughout the animation, not as ideal of a solution but it didnt work anyways. In my game, which is a platformer type game, I have enemies that check the floor in front of them, and if there is no block, (i.e they are on the edge of a platform) they turn around to avoid falling off. but the animation causes the enemy to hover over ground level. not only does it look ugly but it causes them to go back and forth over and over I also want the player to be able to duck, shrinking the size of his hitbox to avoid head-level projectiles, but as i said, he just falls through the world. thanks