Search the Community

Showing results for tags 'sprites'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Coding and Game Design
  • Frameworks
    • Phaser 3
    • Phaser 2
    • Pixi.js
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 191 results

  1. PhasedEvolution

    Phaser how to create isometric sprites?

    Hello. Noob question. Hard time reading and understanding isometric docs. http://udof.org/phaser/iso/doc/Phaser.Plugin.Isometric.Body.html#toc1 I want to create a isometric sprite. Not add it, but create it: I know that I can add it like game.add.isoSprite(). It is like when I create a group and create a sprite in it with "player1 = group_name.create(...);" I would like to create a isosprite. Is not implemented in isometric plugin? Do I have to add a isoSprite to the world and then add it to the group with group.add?
  2. jorgeluis009

    Vector Sprites in Phaser

    I have some vector art stuff, and i was wondering if anyone know any form to load vector art into phaser? I found some post like this : http://www.html5gamedevs.com/topic/2491-how-do-you-create-your-visuals/?hl=vector, but that post doesn't really answer my question. Thanks!!!!!
  3. I am working on a robot game and I am using phaser library. My requirement is to pass the x y coordinates to robot(sprites) and it should move according to that coordinates without any velocity or speed. Every one is using speed to move the sprite. So, kindly give me some suggestions. Now I am using following code for moving sprites: // The following code is for the robot movement // This is initial velocity player.body.velocity.x = 0; player.body.velocity.y = 0; if (cursors.left.isDown) { player.body.velocity.x = -200; } else if (cursors.right.isDown) { player.body.velocity.x = 200; } if (cursors.up.isDown) { player.body.velocity.y = -200; } else if (cursors.down.isDown) { player.body.velocity.y = 200; }
  4. View the jsfiddle demonstrating the issue (just click and drag the circle - relevant code on line 102). When I add a circle to the stage with Pixi.Graphics and drawCircle( 150, 100, 50 ), the circle when dragged becomes offset by it's position ( +150, +100 ) in the Graphics container. (and if we request the circle.position it's also inaccurate) What's the best way to add a shape to the screen and set it's position if it's not through a Graphics container?
  5. Hey guys, Just wanted to show my little in-development game engine. I decided to create my own engine as Panda.js didn't got any updates for several months. The goal here is to have a lightweight but powerfull game engine with awesome performances, whatever the device is (ie. Android) while being able to use Canvas+ (so, no DOM is used as Canvas+ doesn't supports DOM). What I've already done: Game config via `config.js` file ; Game scenes ; Ultra-customizable Sprite class that allows to modify everything drawing related ; Mouse events support (click, move, hover, down, release, out) and Drag & Drop support ; Built-in physics engine (made on my own, so a bit hacky/buggy but I plan to fix these issues :p) ; Only redraw what needs to by using a simple variable on every scene children: `needsUpdate`. What I want to do: Implement built-in networking to allow multiplayer games/apps ; Implement UI elements like Text, Buttons, Scrollable panels, Inputs to allow devs to make real Canvas UI ; Fix the overall bugs ; Add some helper classes ; Maybe implement SAT.js for collisions detection/solving ; And finally, build the game I started this engine for :). So this is an "ambitious" project that aims to allow doing things other engines wasn't able to offer me. Source code (Gitlab): https://gitlab.com/skyzohkey/PwassonEngine Demonstration: https://skyzohkey.gitlab.io/PwassonEngine Feel free to contribute to the code, open issues if you find them, create issues for suggestions too. Or simply leave a message here. Thanks for reading, I hope I'll be able to drive this project the right way.
  6. this is my first post so i apologize if i'm posting incorrectly. i'm trying to have a button change its frame and some of the others in the group. the buttons display fine initially and i can successfully change the properties but i cannot visually get them to change frames when one is clicked. on the other hand, if i want to change only one button that works (you can see that i left the code commented out for that). i left the changing button frames line blank because i've tried so many things and nothing seems to work. var GameState = { preload: function(){ this.game.load.spritesheet('btnSht', "tFassets/btnSprtSht.png", 100, 100, 4); }, create: function(){ btnArray = [ {x: 50, y: 200, id: 1, frm: 0}, {x: 150, y: 200, id: 2, frm: 0}, {x: 250, y: 200, id: 3, frm: 0}, {x: 350, y: 200, id: 4, frm: 0}, {x: 450, y: 200, id: 5, frm: 0}, {x: 50, y: 300, id: 6, frm: 0}, {x: 150, y: 300, id: 7, frm: 0}, {x: 250, y: 300, id: 8, frm: 0}, {x: 350, y: 300, id: 9, frm: 0}, {x: 450, y: 300, id: 10, frm: 0}, ]; this.btns = this.game.add.group(); var self = this; count = 0; btnArray.forEach(function (element){ btn = self.btns.create(element.x, element.y,'btnSht'); btn.idNum = element.id; btn.frame = element.frm; btn.inputEnabled = true; btn.events.onInputDown.add(self.btnFunc, this); }); }, btnFunc: function (sprite, event) { //console.log(sprite.idNum); /* this works to change the one clicked if (sprite.frame == 0) { sprite.frame = 1; count++; } else { sprite.frame = 0; count--; }; */ btnArray.forEach(function (element){ //resets all back to zero before element.frm = 0; //assigns new frame value to appropriate btns for (var i = 0; i < sprite.idNum; i++){ this.btnArray[i].frm = 1; }; //check to make sure values are changed and they are console.log(btnArray); //change btn frames visually }); }, update: function(){ }, }, game = new Phaser.Game(600, 400, Phaser.AUTO); game.state.add('GameState', GameState); game.state.start('GameState'); tF.js
  7. Hello Everyone, I want to share with you my latest pet project, it is a tool to extract images from a spritesheet, it's called SpriteSplitter, all informations are in the github : https://github.com/bmarwane/spriteSplitter . I don't know if i can put links to binaries on the forum but you will find in the repo page some pre compiled ones plus instructions on how to run the project yourself. Instructions : Open the App and load a sprite Make sure that the top left pixel on your image represent an empty area, for example if the space between the frames in a sprite sheet is transparent, the top left sprite neet to be transparent, i will make this configurable some day, but feel free to fork the project and do it if you want. Select frames Save on Disk Here is a screen capture of the app, the selected frames are overlayed with an ugly red ( will definitely change the color ) I created this tool mainly as a learning experience, and also because the only tool that i know that do this is on windows ( see ASU ). SpriteSplitter was created using ElectronJS, so the app is multi plateform, but i tested it only on mac and Linux, can any of you guys confirm to me that it's working on windows ? That's all folk, what do you think ? Thank you.
  8. I am trying to create a game where I have created one player and at the background I have added tiled map. The problem is how can I get the player coordinate every time so that I can replace the tiles covered by the player. Thank you !
  9. Hello, I've been following a Phaser spring example and I've been trying to remove the overlay sprite it draws on my circular physics body (I assume it adds this when I call body.setCircle(5)). Does anyone know how to remove this? I don't want to remove the body, I still want the physics, I just don't want the extra debug drawn sprite. Thanks
  10. I am trying to create a simple Multidimensional array that will add a sprite to the spot example [0,0] I was following how this http://www.joshmorony.com/how-to-create-a-candy-crush-or-bejeweled-game-in-phaser/ was doing by doing something similar like: this.tileGrid = [ [null, null, null, null, null, null], [null, null, null, null, null, null], [null, null, null, null, null, null], [null, null, null, null, null, null], [null, null, null, null, null, null], [null, null, null, null, null, null] ]; but all I want is being change those position in the grid to sprite and none of the animation just simply to be there. addTileItem: function(x, y){ //Choose a random tile to add var tileToAdd = this.tileTypes[1]; //Add the tile at the correct x position, but add it to the top of the game (so we can slide it in) var tile = this.tiles.create((x * this.tileWidth) + this.tileWidth / 2, 0, tileToAdd); //Animate the tile into the correct vertical position this.game.add.tween(tile).to({y:y*this.tileHeight+(this.tileHeight/2)}, 500, Phaser.Easing.Linear.In, true) //Set the tiles anchor point to the center tile.anchor.setTo(0.5, 0.5); //Enable input on the tile tile.inputEnabled = true; //Keep track of the type of tile that was added tile.tileType = tileToAdd; //Trigger the tileDown function whenever the user clicks or taps on this tile tile.events.onInputDown.add(this.tileDown, this); return tile; }, I think I am overthinking the problem but I been at this for a while any help would be greatly appreciated.
  11. Hi I'm trying to do a small product presentation with features and benefits displayed as a sprites around product and I had no problem with that. What I have problem with and have no idea how to handle this issue is a need of fading out this sprites while camera moves from one side to another. What would need to be done to get this kind of effect? I found this as an example of effect I'd like to achieve. Fading effect
  12. Liranan

    Move all connected sprites

    Hello everyone, I have this doubt (little introduction before): I think is really helpful to use a sprite property to "store" another sprite. For example, when I have several enemies and I want all of them to have a health bar I can do something like this: var enemies = game.add.group(); for(var i = 0; i < 5; i++){ var enemy = game.add.sprite(0, 0, "enemy", 0); var health = game.add.sprite(enemy.x, enemy.y, "bar", 0); enemy.health = health; enemies.add(enemy); } By doing this, I can easily locate the health bar in the game later. For example if I want to change the bar's frame I only have to: enemies[i].health.frame = 1; I can do this several times, for example if I want to add a magic bar to the enemies, a text with the name, etc. The problem is, when I want to move the enemy sprite. At this moment, I create a tween for the 'main' sprite, and another tween for each of the properties: game.add.tween(enemies[i]).to({...}); game.add.tween(enemies[i].health).to({...}); game.add.tween(enemies[i].magic).to({...}); This is ok when you have just one property for each sprite, but when the numbers go up, it starts to look... problematic. Specially when each enemy have different properties. I was wondering if there's a way to move a sprite and 'all the sprites that belongs to them' at the same time with a single tween. Thank you! Gonzalo.
  13. Hi there, Im having some issues with performance when i render thousands of sprites. Currently having issues with loading around 20k sprites, but eventually plan on having more (maybe even up to 60k) around the map. I did some research and found this is a somewhat common issue but cannot get a clear and concise answer. I ran some chrome profiles on my game to see whats holding me back: here are my results. To be honest, I don't really understand what that information means other than 20k sprites is too much. (I have a fairly decent computer and its slightly choppy at 20k trees, at say 60k its very choppy) Also, when I say choppy, I mean like it looks choppy, my movement is still fine (to make the point that its not like the game loop thats lagging). Essentially I have 20k trees being placed around a very large map that's being rendered with a tileSprite. However, it's not the map size that is holding me back since the performance I get is very dependent on the number of tree sprites. The tree's have no physics enabled on them and are just rendered and placed in a group then never touched again. Here is a snippet from my create function and how i render the trees. for(var i = 0; i<20000; i++){ treeX = Math.round(Math.random()*(mapSize-1)); treeY = Math.round(Math.random()*(mapSize-1)); temp = position(treeX, treeY); createTree = game.add.sprite(temp[0],temp[1], 'tree2'); treeGroup.add(createTree); } The position function I called in the loop just gets the pixel location of the tree's based on a tile, as shown below: var position = function(col, row){ column = (33*col+1); rowFin = (33*row+1); return [column, rowFin]; }; Any ideas as to how i can beef up my performance? Any way I could not render the tree's until they are in view? (Kill then revive when seen?) Any tips are greatly appreciated! Side note (if its useful), right now all I have is the tileSprite background, 20k trees, and movable player sprite. Edit: Would creating a chunk system be a good idea? If so anyone have any idea where to start with the best way to make one?
  14. Hi, dear game developers. I had seen that link on examples load-polygon-1 or var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.image('contra2', 'assets/pics/contra2.png'); // Load our physics data exported from PhysicsEditor game.load.physics('physicsData', 'assets/physics/sprites.json'); } var contra; var start = false; function create() { // Enable p2 physics game.physics.startSystem(Phaser.Physics.P2JS); contra = game.add.sprite(400, 300, 'contra2'); // Enable the physics body on this sprite and turn on the visual debugger game.physics.p2.enable(contra, false); // Clear the shapes and load the 'contra2' polygon from the physicsData JSON file in the cache contra.body.clearShapes(); contra.body.loadPolygon('physicsData', 'contra2'); // Just starts it rotating game.input.onDown.add(function() { start = true; }, this); } function update() { if (start) { contra.body.rotateLeft(250); } } function render() { } , and i'm trying create json like that, since i saw that example. I saw some suggestions about physics editor or mapeditor tiled. i installed it, but i have no idea about creating json like that despite researching how its doing on internet. Probably i need some help
  15. Hi Guys, I have been battling with this for some time now. I'm kinda newbie with phaser too. Currently I'm trying to build a football game where the player adds the ball (both are sprites) to his own sprite and moves around with it until is moment to "kick" the ball, sending it in any direction. My problem is that I can't seem to be able to release the ball once its been attached. I tried "moveToXY" or "AccellerateToXY" but nothing seems to be doing it. I also tried bypassing the collision "attach" behavior as it seems that it may be a problem but I dont think that is the problem, unless someone tells me otherwise. Here's a screenshot of the game so you can have better context . How can I release the ball from the sprite and send it on a given direction? What do you think is the problem? ... kick: function(direction, speed){ var ball = this.sprite.getChildAt(0); this.sprite.removeChildAt(0); game.physics.arcade.moveToXY(ball, direction.x, direction.y, speed); this.possession = false; }, ...
  16. I'm working on a game where the player character can change into different colors, depending on which power-up he takes. All animations are basically the same, except the sprite index is offset. The player sprites at index 0 through 7 are red, 8..15 are the same sprites but green, and 16..23 are blue. If the walking animation sprites are index 1,2,3 etc. for red, they are index 9,10,11 etc. for green (just add +8), and for blue add +16. See the sprite sheet example in the attachement (they are ripped and edited Megaman sprites, but that's just a placeholder graphic for now). I can't change the frames array of an animation AFAIK, so should I just add all the separate animations for each color, so something like this? this.animations.add("walking_1", [ 1, 2, 3, 4], 6, true); // red this.animations.add("walking_2", [ 9, 10, 11, 12], 6, true); // green this.animations.add("walking_3", [17, 18, 19, 20], 6, true); // blue this.animations.add("jumping_1", [ 5, 6], 6, true); // red this.animations.add("jumping_2", [13, 14], 6, true); // green this.animations.add("jumping_3", [21, 22], 6, true); // blue // and then later this.animations.play("walking_" + this._powerup_idx); // red green or blue The thing is, I want to expand it to 6, or maybe 8 power-ups and colors, so is there maybe a more clever way to handle this sort of sprite index offset in Phaser? Or is this the way to go?
  17. pranadevil

    bitmapdata and sprites

    hi there, if i create a Sprite and assign a BitmapData as its texture. then i can operate over the sprite texture(bitmapdata) using the bitmaps methods like getpixels? or how can i erase it after that ( i mean the bitmapdata)? thanks in advance
  18. MelSmits

    2D NPCs with random appearances

    I'm starting work on a game where I want to be able to randomly generate NPCs. These NPCs could have different faces, haircuts, eye colors, outfits, etc. I'm wondering what the best way is to handle this situation. These are the options I've considered: Design a spritesheet for every possible combination of feature. Let's say there's only 4 heads, 4 haircuts, 4 outfits and 4 "held items", that's 4x4x4x4 sprites, each of which would need multiple frames of animation. No thanks. Design a spritesheet per feature. One for the heads, one for the haircuts, etc. all partially transparent. Then use z-layers in CSS to overlay them into one complete NPC. Maybe there's some framework that I'm not aware of that would handle this more elegantly? Currently I'm considering option 2. I'd use a javascript function to determine whether this guy gets haircut 1, 2, 3 or 4, and use that variable to get the correct sprite. But I'm wondering if there is a 'tried and true method' for this. I might be really overcomplicating or oversimplifying things. I've only just started designing this thing so I'm not stuck on any particular framework yet. Any input would be much appreciated!
  19. Hi I need to find the distance between a player sprite and the closest sprite to it in a group of sprites, I know this can be done by iterating through each of the sprites in the group and checking them individually however, I was hoping phaser had a built in way of accomplishing this. Once the player is within a certain distance, it will die so if phaser has an event for this that will work as well. Thanks for any help
  20. flowww

    Gridify the Container Sprites

    Can we apply any plugin to gridify the sprites in a container? I am trying to group the sprites in a container so that I can move the container instead of all images inside it but I want sprites not to be overlapped.
  21. Hello, I'm a previously flash developer and learning games development using phaser and noticed that many things are done differently here. For example, you make an animated character something like that: game.load.atlasJSONHash('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json'); What if you have 20 animated characters in a game? Will you load 20 png and 20 json files? Then there will be other asset files. Is there a way to combine assets so that there are few load requests from the server.
  22. I've stumbled across an undesirable effect. When I add a filter to a sprite, and rotate it, the sprite is smoothed (blurred a small amount, looks like linear maybe) and also, it shakes slightly (you have to look closely to see it, but it becomes very apparent on small sprites. I don't know if this is phaser or pixi, but I was wondering if anyone knew of a way to alleviate the effect. The position thing looks to be loss of precision on the position or at least the effect makes it look like that, jumping from one pixel location to the next or something like that. The other I don't know about. There's no interpolation in the filter, the only thing I'm really doing is gl_fragcolor = texture2D(uSampler, vTextureCoord); both effects are removed if you just comment out the line: sprite.filters = [filter]; (removing the filter) here's a link to the simple example: https://brokedrobot.com/resources/dev/public/index2.html and here's the code for that example: <html id="html" style="overflow: hidden;" ng-app="html"> <head> <title>Example</title> <meta name="author" content="glitchedRaven"> <meta name="keywords" content=""> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" /> <script src="phaser.min.js"></script> </head> <body style="background: green; margin: 0vh; padding: 0vh;"> <script> var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }, true); function preload() { game.load.image('texture', 'test.png'); } var filter; var sprite; function create() { // Shader by Kali (https://www.shadertoy.com/view/4dfGDM) // Image patched by Richard Davey var fragmentSrc = [ "precision mediump float;", "uniform float time;", "uniform vec2 resolution;", "varying vec2 vTextureCoord;", "uniform sampler2D iChannel0;", "uniform sampler2D uSampler;", "void main( void ) {", "vec2 uv = gl_FragCoord.xy / resolution.xy;", "uv.y *= -1.0;", "uv.y += (sin((uv.x + (time * 0.5)) * 10.0) * 0.1) + (sin((uv.x + (time * 0.2)) * 32.0) * 0.01);", //"vec4 texColor = texture2D(uSampler, uv);", "vec4 texColor = texture2D(uSampler, vTextureCoord);", "gl_FragColor = texColor;", "}" ]; // Texture must be power-of-two sized or the filter will break sprite2 = game.add.sprite(310, 230, 'texture'); sprite = game.add.sprite(0, 0, 'texture'); sprite.width = 400; sprite.height = 300; sprite.x = 400; sprite.y = 300; sprite.anchor.set(0.5, 0.5); sprite.scale.set(1.5, 1.5); sprite.smoothed = false; var customUniforms = { iChannel0: { type: 'sampler2D', value: sprite.texture, textureData: { repeat: true } } }; filter = new Phaser.Filter(game, customUniforms, fragmentSrc); filter.setResolution(1024, 1024); sprite.filters = [ filter ]; } function update() { sprite.rotation += 0.01; filter.update(); } </script> </body> </html> As I understand it, filters use a canvas element behind the scenes to render, but is there any way I can set the imageSmoothingEnabled property of that element? Or make the filtered sprite match the unfiltered sprite some other way? To be honest, the position shaking thing is more troublesome to me than the smoothing thing, is there a way to keep the location steady?
  23. I've recently started work on a new game, experimenting with the Rotates Isometric plugin and its mostly going great. I'm using the LPC base assets for my prototyping art because they are widely available and nicely animated (picture attached), but then the bugs started appearing. Every time the character moves in a direction I play the walking animation for that direction. All directions are fine, other than the upwards movement. After the upwards animation finishes (when the player and let go of the key) the sprite continues to float slowly up (-y) at a rate of about 5px/sec, until the player puts in another movement control, at which point everything is fine and the sprite flies back to where it was before it started to float away. The game registers both the x + y velocities as 0 while floating, as they should be, and I've run out of options to try. My other, more game breaking, problem is that when the player attacks the sprite plays the animation, but flies up (again -y) almost exactly 50px. Again the game logs the velocity of the sprite as 0 while this is happening, nevermind what direction the player attacked the sprite always flies up (-y). I threw both of these problems into the same question because I thought there were many similarities between the two, and perhaps they are related. Below I'll put in the Player Movement function, but if anything else is needed please feel free to ask. Not meaning to bed but I desperately need a hand with this, my boss loves what I've produced so far and is pressuring me to produce something concrete with it. function movePlayer(direction){ switch(direction){ case 'up': player.body.velocity.x = -player.speed; player.body.velocity.y = -player.speed; player.animations.play('walk-' + direction); playerDir = direction; _moving = true; break; case 'down': player.body.velocity.x = player.speed; player.body.velocity.y = player.speed; player.animations.play('walk-' + direction); playerDir = direction; _moving = true; break; case 'left': player.body.velocity.x = -player.speed; player.body.velocity.y = player.speed; player.animations.play('walk-' + direction); playerDir = direction; _moving = true; break; case 'right': player.body.velocity.x = player.speed; player.body.velocity.y = -player.speed; player.animations.play('walk-' + direction); playerDir = direction; _moving = true; break; default: player.body.velocity.y = 0; player.body.velocity.x = 0; player.animations.stop(true); player.frameName = 'walk/' + playerDir + '/0'; _moving = false; break; } }
  24. Hey Guys, I've started a new game, experimenting with the Rotates Isometric plugin and its mostly going great. I'm using the LPC base assets for my prototyping art because they are widely available and nicely animated (picture attached), but then the bugs started appearing. Every time the character moves in a direction I play the walking animation for that direction. All directions are fine, other than the upwards movement. After the upwards animation finishes (when the player and let go of the key) the sprite continues to float slowly up (-y) at a rate of about 5px/sec, until the player puts in another movement control, at which point everything is fine and the sprite flies back to where it was before it started to float away. The game registers both the x + y velocities as 0 while floating, as they should be, and I've run out of options to try. My other, more game breaking, problem is that when the player attacks the sprite plays the animation, but flies up (again -y) almost exactly 50px. Again the game logs the velocity of the sprite as 0 while this is happening, and nevermind what direction the player attacked the sprite always flies up (-y). I threw both of these problems into the same question because I thought there were many similarities between the two, and perhaps they are related. Below I'll put in the Player Initialization and Movement functions, but if anything else is needed please feel free to ask. Cheers. Player Init: player = game.add.isoSprite(300, 300, 0, 'player', 0, characterGroup); player.anchor.set(0.5); player.scale.set(1.2); player.speed = 150; game.physics.isoArcade.enable(player); player.body.collideWorldBounds = true; game.camera.follow(player); player.animations.add('walk-down', Phaser.Animation.generateFrameNames('walk/down/', 1, 8, '', 1), 10, true); player.animations.add('walk-up', Phaser.Animation.generateFrameNames('walk/up/', 1, 8, '', 1), 10, true); player.animations.add('walk-right', Phaser.Animation.generateFrameNames('walk/right/', 1, 8, '', 1), 10, true); player.animations.add('walk-left', Phaser.Animation.generateFrameNames('walk/left/', 1, 8, '', 1), 10, true); player.animations.add('slash-up', Phaser.Animation.generateFrameNames('slash/up/', 0, 5, '', 1), 10, false).onComplete.add(function(){movePlayer('none');_attacking = false;}, this); player.animations.add('slash-right', Phaser.Animation.generateFrameNames('slash/right/', 0, 5, '', 1), 10, false).onComplete.add(function(){movePlayer('none');_attacking = false;}, this); player.animations.add('slash-left', Phaser.Animation.generateFrameNames('slash/left/', 0, 5, '', 1), 10, false).onComplete.add(function(){movePlayer('none');_attacking = false;}, this); player.animations.add('slash-down', Phaser.Animation.generateFrameNames('slash/down/', 0, 5, '', 1), 10, false).onComplete.add(function(){movePlayer('none');_attacking = false;}, this); Player Movement: function movePlayer(direction){ switch(direction){ case 'up': player.body.velocity.x = -player.speed; player.body.velocity.y = -player.speed; player.animations.play('walk-' + direction); playerDir = direction; _moving = true; break; case 'down': player.body.velocity.x = player.speed; player.body.velocity.y = player.speed; player.animations.play('walk-' + direction); playerDir = direction; _moving = true; break; case 'left': player.body.velocity.x = -player.speed; player.body.velocity.y = player.speed; player.animations.play('walk-' + direction); playerDir = direction; _moving = true; break; case 'right': player.body.velocity.x = player.speed; player.body.velocity.y = -player.speed; player.animations.play('walk-' + direction); playerDir = direction; _moving = true; break; default: player.body.velocity.x = 0; player.body.velocity.y = 0; player.animations.stop(true); player.frameName = 'walk/' + playerDir + '/0'; _moving = false; break; } }
  25. I have been working with Phaser for about 6 months now, and have recently purchased the Box2D plugin, and for the most part its great, although I am having a few basic problems with spawning the sprite with an appropriately sized body, then applying a continuous velocity. Below is the offending function. First a sprite is spawned from a loaded atlas (the zombie), but unfortunately the sprite is way too big (or my game is too small, one of them) and needs to be scaled down to a 1/4 of its original size. I found a question elsewhere on here where someone (it may have even been Rich) gave an answer to define the body separately, then reattach it to the sprite and the sprite to it. This appears to work fine-ish, giving me a body that is registered as the sprite's and collides properly etc etc. On spawn the zombie plays an anim of pulling itself out of the ground (the spawn anim), and then when that is completed it should play the walk animation, then actually move. The commented section within the OnComplete callback shows all of the different methods of getting something to move in Box2D the internet can give me, but none of them work. function spawnZombie(x, y){ var zombie = zombies.create(x, y, 'zombie'); zombie.anchor.setTo(0.5, 0.5); zombie.scale.setTo(0.25, 0.25); var zomBody = new Phaser.Physics.Box2D.Body(this.game, null, x, y, 0.5); zomBody.setRectangle(30, 50, 0, 0, 0); zombie.animations.add('spawn', Phaser.Animation.generateFrameNames('appear/appear_', 1, 11, '', 1), 7, false); zombie.animations.add('walk', Phaser.Animation.generateFrameNames('walk/go_', 1, 10, '', 1), 7, true); zomBody.sprite = zombie; zombie.body = zomBody; zombie.animations.play('spawn'); zombie.events.onAnimationComplete.add(function(){ zombie.animations.play('walk'); //zombie.body.velocity.x = -100; //zombie.body.moveLeft(100); //zomBody.moveLeft(100); //zomBody.velocity.x = -100; console.log(zombie); }, this); } Personally I think that the problem lies with the body being set as it is, as this method feels like a buggy workaround to me. The only symptom of the problem I can see within the sprite object is that setting the velocity actually does nothing, whereas elsewhere in the code it works as expected. I wouldn't be exaggerating if i said i had spent 6 hours on this problem, and I'm about 2 hours away from quitting my job forever and ritually burning my PC. Any help at all would be great, cheers.