Search the Community
Showing results for tags 'global'.
Found 11 results..
Call a global user-defined function with group.callAll()
Wunderforce posted a topic in Phaser 2Currently I have a group of sprites and I want to make them all fall at the same time. I am trying to accomplish this with the following functions, where the group (here: fallGroup) should fall when the down arrow key is pressed. (and yes, I have already initialized keys in the create() method) I have tried passing multiple versions of the function definition to callAll() (eg. "this.setVel", "game.setVel", ect.) as well as several different contexts instead of 'null' ("this", "that=this, then passing 'that' in", "game", "game.stage", ect.) but so far nothing happens. For some of the combos I get "TypeError: Cannot read property 'setVel' of undefined" others produce no error but also do not call my 'setVel' function. At this point I'm pretty lost as to what to do. Edit: appleYpos, groundYpos, appleTime; are all globally defined variables function setVel(sprite,vel) { sprite.body.velocity.y = vel; } function makeFall(group) { //calculate fall distance and then adjust velocity to meet time goal //note: velocity in physics.arcade is in pixels/sec let dist = appleYpos - groundYpos; let vel = dist/appleTime; group.callAll('setVel',null,vel); } function update() { if(keys.down.isDown) { makeFall(fallGroup); } }
How was the namespace Phaser made globally in the source code ?
FrankenStein posted a topic in Phaser 2Hello ! I really want to read the source code of phaser, but I am not that professional. the namespace Phaser is declared inside a function, so I am wondering how we can access it outside it ? (function(){ var Phaser = Phaser || {}; }).call(this); Phaser.something = 5; //Reference error, Phaser is not declared what things I ca learn to read the source code perfectly and have this awesome experience ?
no way to rotate object globaly
phil1234 posted a topic in Questions & AnswersHello, I read in the doc that rotation is achieved before translation, but I try to have an offsetted object rotate around the 0,0,0 axis and I cant find any way to achieve this ... usualy(with other engines) I offset the object on its local axis then simply rotate it globaly with a matrix/quaterion/rotate function I tried different combinations of these two mesh.translate(BABYLON.Axis.X, 3.0, BABYLON.Space.WORLD); //or LOCAL mesh.rotate(BABYLON.Axis.Y, 1.0, BABYLON.Space.WORLD); //or LOCAL (I wanted to rotate the object position with a quaternion, but the Quaternion lacks of regular/usual .mult(Vector) or .rotate(Vector) and anyway, it wouldn't be what I want to achieve) any idea ? thanks
Convert updateMeshPositions to Global
Pryme8 posted a topic in Questions & AnswersI am currently manipulating a series of ground objects. I am able to manipulate the ground with different noise effects and calculations to get the effects I am desiring on a single ground plane. The problem when I am doing it with the series of them they are all effectively getting the same manipulation applied. I am generating the ground objects in a block so they are all one right after another and look like a single plane, so they all have an offset in the global space. How then can I convert the point from its local assignment in the script: TERIABLE.UpdatePositions = function (positions) { for (var idx = 0; idx < positions.length; idx += 3) { positions[idx+1] = positions[idx]*positions[idx+2]; } }; //Section where it is called: this._block.updateMeshPositions(TERIABLE.UpdatePositions); to a global position. I might be able to do it by adding the grounds.position.x and y to the idx values? but I have not tried that yet and I am not even sure how to pass the ground object with the positions on the updateMeshPositions call i see no optional variable offset in
Global Function How?
ramspeed posted a topic in Phaser 2Hey there, I'm new to javascript and I'm trying to figure out how to create a global singleton for generic functions. I can create global variables in the Boot state, but I'd like to create an object that holds global vars and functions. I'm instancing a custom GameManager script in the index.html file like so: //initialize framework var game = new Phaser.Game(640, 960, Phaser.AUTO, 'game'); //create global object var gameManager = new GameManager(); My GameManager.js file looks like this: var GameManager = function GameManager() { console.log('game manager created'); this.myName = "adrian"; this.GetName = function() { console.log("my name is "+this.myName); } }; The problem is gameManager object is undefined elsewhere in game. Any suggestions? Thanks
Translating a mesh's vertices to screen coords
UP_AND_ATOM posted a topic in Questions & AnswersI'm very new to Babylon.js and have spent a few days reading through the docs and forums, but I haven't been able to find a good answer for this. Let's say I have a rotating and scaled cube in my scene and I want to get the absolute position of each vertex. I found this topic for translating world coords to screen coords: but so far I can only figure out how to get the position of the mesh itself, not for its vertices. In fact, even after digging around in the mesh object, I can't even find where the vertices are stored. How do I get the coordinates of a mesh's vertices so that I can translate them to screen coords so I can draw debug lines on a canvas?!
Setting global var from within "update" function
jwfurness posted a topic in Phaser 2Hello all, I'm having trouble updating 'diamondDropSpeed' from within the update function. I've included the relevant code below. 'diamondTotal' is being calculated elsewhere and is counting properly, and the code in the if statement fires properly... I just can't get the diamondDropSpeed value in the if statement to update globally. Any advice would be greatly appreciated. Thanks! BasicGame.Game = function (game) { diamondDropSpeed = 1000; };BasicGame.Game.prototype = { create: function () { diamonds = this.game.add.group(); diamondCreate = window.setInterval(function(){ diamond = diamonds.create(200, 0, 'diamond'); }, diamondDropSpeed); }, update: function () { if ( diamondTotal >= 1){ diamondDropSpeed = 200; } }};