angelkom Posted May 21, 2014 Share Posted May 21, 2014 I've set the shape to be the size of the sprites but still when I jump the collision doesn't happen on the right spot...this is my code. game.module( 'game.main').require('engine.core','engine.physics').body(function() {game.addAsset('grass.png', 'grass');game.addAsset('p1_stand.png', 'player');game.Debug.enabled = true;SceneGame = game.Scene.extend({ backgroundColor: 0xd0f4f7, init: function() { this.world = new game.World(0, 2000); var grass = new game.TilingSprite('grass'); grass.position.set(0, game.system.height - grass.height); grass.speed.x = -300; this.stage.addChild(grass); this.addObject(grass); var grassShape = new game.Rectangle(grass.width, grass.height); var grassBody = new game.Body({ position: {x: 0, y: game.system.height - grass.height}, collisionGroup: 1, collideAgainst: 0 }); grassBody.addShape(grassShape); this.world.addBody(grassBody); var player = new game.Sprite('player'); player.position.set(game.system.width/6, game.system.height - grass.height - player.height); var playerShape = new game.Rectangle(player.width, player.height); var playerBody = new game.Body({ position: {x: game.system.width/6, y: game.system.height - grass.height - player.height}, velocityLimit: {x: 100, y: 1000}, collisionGroup: 0, collideAgainst: 1 }); playerBody.addShape(playerShape); this.world.addBody(playerBody); this.stage.addChild(player); this.addObject(player); grassBody.collide = function() { console.log('hi'); } player.update = function() { player.position.x = playerBody.position.x; player.position.y = playerBody.position.y; } this.mousedown = function() { playerBody.mass = 1; playerBody.velocity.y = -900; } }});game.start(SceneGame, 1024, 768);}); Quote Link to comment Share on other sites More sharing options...
enpu Posted May 22, 2014 Share Posted May 22, 2014 Hmm i think you are positioning wrong. You see body position is center of shape, so try to set your sprite anchor to center too.player.anchor.set(0.5, 0.5);or if you don't want to change anchor, then:player.update = function() { player.position.x = playerBody.position.x - player.width / 2; player.position.y = playerBody.position.y - player.height / 2;}Also you can see your physics shapes if you enable debugDraw,just put ?debugdraw into end of your url. Quote Link to comment Share on other sites More sharing options...
angelkom Posted May 22, 2014 Author Share Posted May 22, 2014 Great ok I understand now and with debugdraw I can see the shapes and the bodies? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.