rudyardcatling

Members
  • Content Count

    5
  • Joined

  • Last visited

  1. just what the doctor prescribed ... there i was going this.scene.UIscene.restart(); and this.scene.restart('UIscene') but this.Uiscene.scene.restart() ... purrr fekt ... thanks!!!
  2. hm ... probably not how it's done as i never 'learned' anything but by myself so i tend to go with my way and what works : this.spikes = this.physics.add.staticGroup(); if(leveldata[6]){ console.log(leveldata[6]); tmp = leveldata[6].split('-'); for(let lus=0;lus<tmp.length;lus++){ let spikedat = tmp[lus].split(':'); let spikerot = spikedat[1]; let spikepos = spikedat[0].split(','); console.log(typeof spikerot); switch(spikerot){ case '0': case '2': console.log(spikerot); this.spikes.create(spikepos[0],spikepos[1], 'spikes').setSize(50,34).setOffset(10,0).setAngle(spikerot*90); break; case '1': case '3': this.spikes.create(spikepos[0],spikepos[1], 'spikes').setSize(34,50).setOffset(20,-10).setAngle(spikerot*90);//body.rotation not working or im doing it wrong break; } } } screenshot : screenshot of scene ingame (OGA1 : Oga is the new Crack : get things moving) #opengameart
  3. [edit at bottom but not completely solved to my liking] I'm probably missing something silly but i'm pretty fresh to this, i did a search for "callback on specific animationcomplete phaser" but it gets me 1346 pages, apologies but i'm just gonna ask hoping someone picks up the phone : i have one sprite named "chest" and one named "grabhand" i have a function called deathtrapcomplete() which does some camera stuff and restarts / resets the scene on gameover now i have for grabhand : this.anims.create({ key: 'traphand', frames : this.anims.generateFrameNumbers('grabhand', {start : 0, end: 29}) but for chest i have two : this.anims.create({key: 'openchest' ....etc and this.anims.create({key 'chestsaysno' ... etc i have an event for grabhand : this.grabhand.on('animationcomplete', this.deathtrapcomplete, this); which does exactly what it should, it plays the anim completely and then starts the gameover sequence, ... very tidy, lol but when i use it for chest this.chest.on('animationcomplete', this.deathtrapcomplete,this); it triggers for both "openchest" and "chestsaysno" ... which is not so good as the former is simply an empty chest with a puff of dust coming out while the latter is a chest with a deadly trap (both from the same spritesheet) So the question, how do i trigger it only for "chestsaysno" , defining two different sprites seems overkill and working around it in the call itself seems very in-elegant as the deathtrapcomplete() function is already there It's hard to imagine i cant insert the specific animationkey in the on(...) handler somewhere so my guess is i simply can't find it as im pretty much a noob, on the docs it says " event string | symbol but when i try this.chest.on('animationcomplete|chestsaysno' ... etc) it doesnt trigger anything at all (which is probably me not understanding what the pipe symbol means thats why im asking , thanks a lot if anyone has time and patience to help me out here about a minute after i find something on https://labs.phaser.io/edit.html?src=src/game objects\graphics\health bars demo.js where animation.key is used in the callback function so if i add deathtrapcomplete(animation){ if(animation.key != 'openchest'){ ...do gameover stuff.. } } it works but i still feel it would be better if i can simply define the handler to only react to the specific animation in the first place ... if anyone has any advice on the matter i would be much obliged, thanks
  4. hi, i hope i can explain myself : im trying to restart a scene with a different map without having to preload all the .json files at once so in preload i have let maplevel = $("#id").val; switch(maplevel){ case 2: //alert(maplevel); this.load.tilemapTiledJSON('map', "url here"); break; default: this.load.tilemapTiledJSON('map', "url here"); } which throws no errors anywhere in create : this.map = this.make.tilemap({key : map}); this.tiles = this.map.addTilesetImage('nameasin Tiled', 'tiles'); this.bottomlayer = this.map.createDynamicLayer(0,this.tiles,0,0); this.wallslayer = this.map.createDynamiclayer(0,this.tiles,0,0); when the sprite hits a certain kind of tile (number 12 on bottomlayer) a function calls : if(mapevent == 0){ shake/fade/delayedcall -> scene.restart // trap, player dies works it restarts the scene with player in the right place } if(mapevent == 12){ //this has to move from maplevel 1 to maplevel2 this.cameras.main.fade(1000); this.time.delayedCall(1001,function(){$(#x).val(1);$("#y").val(8);this.scene.restart();},[],this) } the first bit is a gameover event so that puts the player at the start of level 1 , which seems to work fine the second is a next level event , this bit throws no errors , it doesnt give any "key not defined" or anything at all so i assume its loaded. I actually know its loaded since if i load both files with different key names and i use switch statement in the create() section it displays the right one, however if i use it in preload everything fades and restarts but it displays the same layout as level 1 from all i can dig up i could as well load the assets in scene 1 (this is scene 9) and they would be available, so i can make it work thats not the issue my issue is, eyes on the future that i would like to only load what's needed without having to add separate scenes, i already expect to have dozens or maybe like a 100 scenes (whew ...) by the time its anywhere near finished so memory wise i think it would be advisable to only have the current JSON file loaded and size-wise it would be a lot easier if i could just use a string for the filename on restart, that would save a lot of bytes as i have 9 levels for this one alone, if i have to include <script src tags> for 9 scenes for each separate level the pagesize will increase dramatically ive been googling for a few hours now and i cant really find exactly what i need and as it throws no errors i have no clue what's wrong. My best guess would be that you can't alter the assets on a scene restart and it sticks with whatever is loaded the first time the scene is started, if that's so then i guess it can't be helped but if there would be a way to do this id be much obliged if someone takes a minutre to explain I just figure its better to do it that way up front instead of optimizing it all after total creation so in short Can i load different files to have different map layouts when i call scene.restart ? thanks in advance, J
  5. as an example : this youtube video leaving out the details : im using and so on depending on left/right/up/down arrow keys, but what i need for my particular situation is an absolute moveTo , this works fine but it just sets the sprite on a "path towards" after which it keeps moving. Now i can catch all of it in the update() section of the scene and even if perfect == doesnt seem to work (cf. shown in vid) so its >= or <= due to the fact that its several digits below the dot and the exact number doesnt hit as it updates slower than the numbers do I can use a lot of conditional structure to make it stop, and then set the absolute .x and .y to the nearest "snap" and it will be fast enough to not show but, im fairly new to all of it and its a pretty big environment so i was wondering if i might be missing a built-in command / method somewhere that does exactly just that (i seen a plugin but as id be able to write the code for it myself thats not necessary, the only thing to improve would be an exact moveTo command) in the end the game has to be turnbased (it uses ajax requests and sends only the input to the server, the intention being the game"state" or map"state" being kept serverside first to prevent all and any kind of meddling or messing as, even if someone were to alter any data it would not corellate with what's on the server and an error could be thrown Far from that though, so instead of 500 googles i'll just try to ask it here i had another little question, which is probably not very important in 2019 but : i have a sprite that's rendered in blender at 256x256 px, but for this piece i used sprite.setDisplaySize(64,64) as that is the "tile size" used , again something that wont show to the naked eye unless in very large projects but thats just curiosity : assuming a device has plenty of working memory if you're talking kilobyte sized assets does it impact performance in any way ? e.g. how does Phaser treat this ? does it make a copy of the sprite at 64x64px and uses that from memory OR does it resize the actual sprite every cycle (which means somewhere extra cpu will be used) thats just curiosity but might come in handy later when i grow up 😛 if anyone knows, thanks in advance