liakos1992

Members
  • Content Count

    30
  • Joined

  • Last visited

About liakos1992

  • Rank
    Advanced Member

Recent Profile Visitors

927 profile views
  1. This code allows you to zoom out, then center the camera to a desired point. var zoomFactor = 0.5; var cameraFocusX = 100; var cameraFocusY = 200; game.world.scale.setTo(zoomFactor); game.camera.focusOnXY(cameraFocusX * game.world.scale.x, cameraFocuzY * game.world.scale.y); If you want to zoom out from the center, set var cameraFocusX = game.world.width / 2; var cameraFocusY = game.world.height / 2; EDIT: Have in mind that after you zoom in/out (scale up/down the world), sprite.collideWorldBounds = true; will not work correctly. Also, if you want to get mouse X, Y coordinates based on world, instead of var mouseWorldX = game.input.worldX; var mouseWorldY = game.input.worldY; you should use var mouseWorldX = game.input.worldX / game.world.scale.x; var mouseWorldY = game.input.worldY / game.world.scale.y; However, sprite.events.onInputOver.add(callback) will work correctly whatever the world scale
  2. What is this language? I'm just using simple javascript. The "while (true)" is there to show a simple example where we construct "infinite" tweens. If the "game.add.tween" function ONLY returns a tween, then the code doesn't leak memory. If the function not only returns a tween, but also generates data and place it to somewhere else, then it does leak memory. I run the above example handreds of times per second, and when I scan the memory via chrome profile tools I get the same amount of memory usage, which means that memory is not leaked, but I need to make sure. (I am not sure if I scan the memory usage correctly)
  3. Does this code leak memory? var sprite = game.add.sprite(0, 0, "texture"); var tween = null; while (true) { tween = game.add.tween(sprite).to({x: X, y: Y}, 1000, null, true); }
  4. Nice idea, but this works only when game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT; . I need to use: scale.fullScreenScaleMode = Phaser.ScaleManager.SHOW_ALL; then black areas appear at the edge of the screen because the game scales up with the same width/height factor, and "vw" and "vh" calculate black areas too, so the elements scale more
  5. I had to mention it, mattstyles. I am using nwjs.io. It is a tool that converts your javascript project into a binary .exe file, so the non-fullscreen window has 800x600 dimensions, so there is a big difference between the windowed and fullscreen mode. Because of that, I can't host the project on a server. By fixing the "zebra.min.js" I mean changing the code inside. It will be hard because their community is too small and I can't find anything about that problem
  6. I want to create a game that can go fullscreen and back to normal via options. The problem is that along with the game sprites, I want the html elements to be scaled up too. I need the html elements to create a hud/ui for my game. I have found some solutions but none is perfect. I can use the phaser buttons and texts so they can scale up too, but I also need input, scroll elements and checkboxes. Checkboxes are easy to make with phaser. Scrolls are a little harder and creating inputs seems completely impossible. Because I also need a pointer/cursor while writing inside the input, and the user must be able to select the text in a "chat" area. I have tried to place the html elements in a "%" way like style="left:20%; top:10%; width:30%; height:5%;". Their size scales up, but their font and border size do not. I have tried to zoom-in elements with css3: element.style.transform = "scale(scaleFactor);" (I can calculate scaleFactor comparing the canvas size between the fullscreen and non-fullscreen mode), but it greatly reduces text quality. Elements positions become inaccurate too. I tried to search for a javascript canvas gui library and I found zebra but it seems it has a lot of bugs. "zebra.min.js" loads with errors unlike my other files; probably because my project is not on a server and I'm accessing my files locally. (Is it worth trying to fix it?) I'm asking for your ideas. I don't know what to do.
  7. Nice. Used game.state.preRender = function() { // my code here } inside the "create()" function and it's working fine.
  8. I want to combine phaser arcade physics with some custom physics of my own. But it seems that objects with velocity are playing 1 tick ahead of objects whose x and y properties are changed in the update function (like "sprite.x += 10;"). What I need is to render the game AFTER the update loop. Is there any way to do this? I've been searching this for weeks and haven't found anything yet.
  9. I want to render the game after update() for various reasons
  10. When changing a sprite's x and y in the update loop, the new position will not show until the next update(). This way, when I attach a health bar on a unit with velocity, while the unit is moving the health bar will always be behind that unit. How can I have the rendering to be done AFTER the "update()" loop?
  11. thank you. do you know how i can render everything AFTER the update loop? changes at x, y will not be seen until the next "update()"
  12. By default, the desiredFps is 60, so the delta time (physicsElapsedMS) is 16.66 ms. Each 16.66 ms phaser update sprites based on velocity, gravity and other things with a function. How to capture this physics update function or implement a callback there? I want to try to make a custom physics system
  13. If you are confused about how each client can control each character I will show you some code structure. var serverWorldData = null;tryingConnectingToServer(function(serverData) { serverWorldData = serverData; startPhaserGame(); // game = new Phaser.Game( ... ) .. });function preload() {}function create() { buildWorldBasedOnServerData(serverWorldData); loginToServerWithNameAndPassword();}function update() { clientUpdateYourGame();}- FIrst you connect to server ("tryingConnectingToServer"). Start the phaser game after you connect, if you want the starting world to be based on some primary server data. - In server side, a "client" object is made (based on socket.io) - When the connection is established, you save in a variable "serverWorldData" the server data and start the phaser game - When phaser "create()" starts, you use the "serverWorldData" and build the client world. Then you send your login or your name to the server. You want to login/request world data inside the "create()" function, otherwise you won't be able to draw the sprites you request if they arrive too early. - In server side, server receives the name and a "player" object is made containing the "client". player = {client: client, name: receivedName, x:0, y:0}. This player is stored in some "players = []" array - The server sends the logged player ONLY HIS OWN data. - Client does something like create_me(player); - The server sends all the world/effects/players data to the login player EXCEPT HIM. ( players = [player[0], player[2], player[3] ...]; ) (in case i am the player[1]) - Client does something like create_player(player[0]); create_player(playerData[2]); create_player(playerData[3]); what "create_me(player)" and "create_player(player)" do? // CLIENT SIDE// create Player classvar Player = function(playerData) { this.name = playerData.name; this.sprite = game.add.sprite(playerData.x, playerData.y, "hero"); makingMyPlayerSpriteBeautiful();}function create_me(playerData) { var me = new Player(playerData); // THIS IS ME makeMyHealthBar_GREEN(); createMyPhaserControls(); // when i am moving tell the server too ifIAmDeadIWillNotMove();}function create_player(playerData) { var enemy = new Player(playerData); // THIS IS ANOTHER PLAYER makeHisHealthBar_RED(); // no controls}