hicotech

Members
  • Content Count

    20
  • Joined

  • Last visited

About hicotech

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I dont know how you have it but if you use isometric layout you probably want to recalculate it to orthogonal before you use pathfinding.. and then most likely back http://clintbellanger.net/articles/isometric_math/
  2. I had "similar" question recently and yes using spritesheets is best of course (as you probably know all games of any kind use that) but then there is a question spriteSheet vs spriteAtlas I asked here http://www.html5gamedevs.com/topic/9588-texture-atlas-better-than-spritesheets-performancewise/ and there is one good source of info.. after some concepts I managed to get just two calls to graphic card (even when using more than 1 spriteAtlas with many images inside of them) and game is much faster in terms of what GPU has to deal with read more here https://phaser.io/tutorials/advanced-rendering-tutorial/part2
  3. just divide coordinates by 15 then arrayData.push([Math.floor(game.input.activePointer.worldX / 15), Math.floor(game.input.activePointer.worldY / 15)]);
  4. what exactly are you trying to achieve? as far as I know Phaser runs in 60FPS so update function is called 60 times per second.. that means that with array declaration in update function you keep creating new empty array and once any tile is clicked you put coordinate to array, log it to console but obviously on next iteration array is again empty.. this will push array of x,y coordinates to your arrayData everytime when you click somewhere in the game tilemap var arrayData = []; var game = new Phaser.Game({ width : 800, height : 600, renderer : Phaser.AUTO, parent : 'canvas-wrapper', antialias : true, multiTexture : true, enableDebug : false, state : { preload : preload, create : create, update : update, render : render } }); function preload() { // foo // create game tiles here } function create() { game.input.onDown.add(function() { arrayData.push([game.input.activePointer.worldX, game.input.activePointer.worldX]) }); }
  5. as I said.. I will use finite state machine for NPCs in general I will have an object or any kind of "grouping functionality" where I keep data about my NPCs.. for example if I have two states "walk" and "idle" I will need to do physical update of position only for those NPCs which are in "walk" state.. in separate function/class I will be handling state change and viewport checks something like this function create () { // create NPCs // init state machine } function update () { // forEach of to be updated NPCs do something group.forEach(function (npc) { // move to x,y } } function stateMachine (npcs) { // for each of npcs check if in viewport // set the state and // assign to "group" or do something else }
  6. after discussion with a colleague and after I read some articles then most likely finite state machine approach will be much better.. and in update function I will check only those which are supposed to be updated..
  7. ok got it.. as I am using the framework/engine I wanted to use some native functionality but obviously there is none for this kind of stuff and your solution sounds reasonable.. I will go with this approach.. thanks
  8. so basically you say to use two different states for actual game, right? if not then, how would you (technically) do actual act of player entering a building when you need to regenerate whole map.. but possibly show previous one in next couple of seconds? because there might be different number of different building or locations.. I would then need to prepare everything what is possible to enter from that location
  9. I am starting to think that this whole approach is not correct.. it can get pretty slow if there are many NPCs In create function I set loop so NPC checks every 5 seconds if its in camera view and moving.. if in camera view but standing then it generates random point where to go (can be off screen) and sets isMoving flag to true.. Then in update function I check (in every frame) for isMoving flag and if its true then NPC starts traversing the generated path (array of points) Whole idea is that every 5 seconds I can set character to isMoving state and update function will start moving NPC on next call.. I added simple code with comments so you can imagine what I mean function create() { // Every 5 seconds check if character is in viewport and moving // If yes and not moving then get random path where to go game.time.events.loop(5000, function () { if(character.inCamera) { if (!characters[character.name].isMoving) { // Here we generate path for character (pathfinding) // And set isMoving flag to true getPath(character); } } }, this); } function update() { charactersGroup.forEach(function (character) { // Stop character from physical movement character.body.velocity.set(0); if(character.inCamera) { // If character has isMoving flag set to true (set by getPath func) then traverse path if (characters[character.name] && characters[character.name].isMoving) { // Move to next tile in path array // Last tile set isMoving flag to false traversePath(character); playAnimation(character); } } }); }
  10. I am not trying to write D2 (though its great game!) in javascript but logic for those RPG games is always similar.. so basically it is possible to use states even for different map parts just not as common.. would then be some other approach which which I can load different map assets? I didnt see anything else
  11. I have set condition in my update function so it checks if sprite/character is in viewport.. but still I dont like the idea of looping through all characters in an update function just to check if they are inCamera and to get them moving
  12. Hi,, so I am wondering what is the correct use of states.. obviously as Boot, Preloader, Main Menu, Game as per examples and docs.. but can or should states be used for different game locations? for example player enters a building, different city, different map location Imagine RPG game where player can wonder around in "free" world and at some point enters some city.. then within the city enters different bulildings (many of them).. should all those be different states or is there any other better approach for cases when world/map/screen changes completely Example of LPC demo where you can enter buildings or go north through woods and enter different location http://lpc.opengameart.org/static/lpc-style-guide/demo.html Example of Diablo where player is in one location "world" and about to enter another location "castle"
  13. Interested in points 2 and 3 as well.. If we talk about point 3 then its probably worth to mention that in my case I created concept map in Tiled with just grass and stones plus 3 objects.. everything is handled by createFromObjects function and all these 3 objects are added to the same group.. I need to loop through them in create function and sadly also in update function.. however two of the objects share same sprite and they have same gid and one of those two is off screen.. when they are added by createFromObjects function autoCull parameter is set to true.. forEach function loops through that one as well anyway.. it would mean that all objects (enemies or whatever) are added in the beginning and are updated all the time if this approach is used.. probably there is another approach with which not all objects in group are updated when update function is called but didnt find it yet EDIT: I guess sprite.inCamera property can help EDIT2: in this example http://phaser.io/examples/v2/tilemaps/create-from-objects question mark and exit "tiles" disappear when they are off screen.. move slowly and you will see that once camera view passes the middle of tile it just go invisible This is what I mean function preload() { game.load.atlas('terrain', 'resources/images/terrain/terrain.png', 'resources/images/terrain/terrain.json', Phaser.Loader.TEXTURE_ATLAS_JSON_HASH); game.load.atlas('characters', 'resources/images/characters/characters.png', 'resources/images/characters/characters.json', Phaser.Loader.TEXTURE_ATLAS_JSON_HASH); game.load.tilemap('staticMap', 'resources/map/map.json', null, Phaser.Tilemap.TILED_JSON); } function create() { // Create map var map = game.add.tilemap('staticMap'); map.addTilesetImage('terrain', 'terrain'); // Create layers grass = map.createLayer('Grass'); stones = map.createLayer('Stones'); // Create characters group charactersGroup = game.add.group(); charactersGroup.enableBody = true; // Create characters // Two of the objects have same gid but different names map.createFromObjects('Characters', 11, 'characters', 'jim/walk/down/01', true, false, charactersGroup); map.createFromObjects('Characters', 47, 'characters', 'bob/walk/down/01', true, true, charactersGroup); // Initialize character charactersGroup.forEach(function (character) { // some setup // here all 3 objects are available }); } function update() { charactersGroup.forEach(function (character) { // random moving code // again all 3 objects are updated }); }
  14. I did this.. if this is what you are looking for function preload() { game.load.atlas('terrain', 'resources/images/terrain/terrain.png', 'resources/images/terrain/terrain.json', Phaser.Loader.TEXTURE_ATLAS_JSON_HASH); game.load.tilemap('staticMap', 'resources/map/map.json', null, Phaser.Tilemap.TILED_JSON); } function create() { // Create map map = game.add.tilemap('staticMap'); map.addTilesetImage('terrain', 'terrain'); // Create layers grass = map.createLayer('Grass'); stones = map.createLayer('Stones'); }