yltang

Members
  • Content Count

    21
  • Joined

  • Last visited

  1. I have a sprite sheet image ("character1.png") and a JSON file ("character1.json') indicating the frame positions. The positions of frames are specified as follows: { "count" : 264, "filename" : "character1.png", "position" : [ { "x1" : 5, "x2" : 65, "y1" : 4, "y2" : 86 }, { "x1" : 69, "x2" : 131, "y1" : 2, "y2" : 87 }, ... ] } How do I load the sprite sheet with the command `game.load.spritesheet(...)`. Also, how do I play the animation and access a particular frame? Thanks. character1.json
  2. How can I set the camera-follow only when the player is moving to the right? If the player is moving to the left, don't follow.
  3. How do I pass arguments to a callback function? For example: var main = { ... create: function () { this.cursor = game.input.keyboard.createCursorKeys(); }, update: function() { game.physics.arcade.collide(this.player, this.platforms, null, this.ignoreCollision); }, ignoreCollision: function(player, platform) { if (this.cursors.down.isDown) { return false; } return true; },}'this.cursors' is undefined. I guess I have to pass 'this' to 'ignoreCollision'. How do I do that?
  4. I am following the Shootout game. There are three states: Boot, Preloader, and Game. Since there is very little code in Boot state, I tried to move the code to the Preloader state. Previously: var Boot = { preload: function() { game.load.image('preload', 'assets/preload.png'); }, create: function() { game.input.maxPointers = 1; game.state.start('Preloader'); }, };var Preloader = { preload: function() { this.preloadBar = game.add.sprite(120, 260, 'preload'); game.load.setPreloadSprite(this.preloadBar); ... }, ... }; Now, the Boot state is removed and the code is moved to the Preloader state: var Preloader = { preload: function() { game.load.image('preload', 'assets/preload.png'); this.preloadBar = game.add.sprite(120, 260, 'preload'); game.load.setPreloadSprite(this.preloadBar); ... }, create: function() { game.input.maxPointers = 1; }, ...};However, Phaser complains with the error message: Phaser.Cache.getImage: Key "preload" not found in Cache. Why is that? EDIT: The following does'nt work, either. The statement "...setPreloadBar(...);" causes Phase internal errors. var Boot = { preload: function() { game.load.image('preload', 'assets/preload.png'); }, create: function() { this.preloadBar = game.add.sprite(120, 260, 'preload'); game.input.maxPointers = 1; game.state.start('Preloader'); }, };var Preloader = { preload: function() { game.load.setPreloadSprite(Boot.preloadBar); ... }, ...}
  5. Thanks a lot. However, the variable "safeTileIndex" doesn't seem to be accessible from the function of "tiles.forEach(...)". I don't know why and I end up with the following for (var i=0; i<tiles.length; i++) { if (tiles[i].index==safeTileIndex) { safeTiles.push(tiles[i]); }}
  6. Having been searching around, but couldn't find a solution. I am working on tilemaps. I would like to place a target on one of the safe tiles randomly for the player to collect. How would I do it? The following is what I'm getting so far. Please advise, thanks. ...this.map = game.add.tilemap('map');this.map.addTilesetImage('tiles', 'tiles');this.layer = this.map.createLayer('Tile Layer 1');this.map.setCollision(20, true, this.layer);// Supposing the safe tile number is 1, how do I randomly select a safe tile?this.safeTile = 1;
  7. I tried to set it to true or false, but didn't notice any difference. It seems to have no effect at all. Is that because the browser will do the anti-aliasing no matter what?
  8. Nice thought. Would you elaborate more about what you think are the responsibilities of the state? I don't seem to be able to identify them easily. Taking my code snippet as an example, suppose that "wrapPlatform" is a function to bring back the platform that is moving out of the game world. Is it one of the responsibilities of the state, or it just happens in the state?
  9. Newbie to Phaser ;-) I notice that, in most of the Phaser examples, functions tend to be written as methods of the state object. For example, var main = { ... update: function() { this.platforms.forEach(this.wrapPlatform, this); }, wrapPlatform: function(platform) { ... },};Why don't we make it a function as follows? var main = { ... update: function() { this.platforms.forEach(wrapPlatform, this); },};function wrapPlatform(platform) { ...};In such an arrangement, the length of the code of object 'main' will be significantly shorter. And the code looks cleaner, also, not so many "this.". Is there any reason or benefit writing the function as an object method? Or which one is better? Thanks.
  10. Can somebody explain the effects of the following four blend modes of a BitmapData object? There are no descriptions in Phaser's documentation. a. blendDestinationAtop b. blendDestinationIn c. blendDestinationOut d. blendDestinationOver Also, which one is the default one?
  11. I found the following good explanations about the easing functions for tween method. I know that the easing functions can also be replaced by corresponding strings, for example, 'Linear' for Linear.None and 'Quint' for Quintic. http://sole.github.io/tween.js/examples/03_graphs.html Is there any reference which lists all other corresponding strings? Thanks.