owen Posted August 16, 2014 Share Posted August 16, 2014 HiI've added 4 objects (tiles) to the Object Layer in my Tiled map which are to be sprites in my game. I have checked that my object layer name matches my code and yes the sprites appear on the game --- but they dont' do anything yet. Now I want to apply some physics to those objects, for which I am first going to have to create the sprites from these objects. I'm doing this using createFromObjects as follows: map.createFromObjects('Object Layer 1', RED_APPLE, 'redApple', 0, true, false, redApples); map.createFromObjects('Object Layer 1', GREEN_APPLE, 'greenApple', 0, true, false, greenApples);Does that look right to you? I am expecting this to have created 4 sprites across 2 groups (redApples and greenApples). And when I run the game, yes, I'm seeing the expected sprites. But I cannot figure how to take it further and apply my physics eg. gravity to these groups. What is the best/easiest way of applying gravity and bounce to both groups? Can I apply it somehow to a whole group at a time? If so, how do I first even refer to the groups? Thanks,Owen Link to comment Share on other sites More sharing options...
owen Posted August 16, 2014 Author Share Posted August 16, 2014 I think I have solved this by using forEach on the groups, as below. map.createFromObjects('Object Layer 1', RED_APPLE, 'redApple', 0, true, false, redApples); map.createFromObjects('Object Layer 1', GREEN_APPLE, 'greenApple', 0, true, false, greenApples); // apply physics to object layer redApples.forEach(function (apple) { game.physics.arcade.enable(apple); apple.body.bounce.y = RED_APPLE_BOUNCE; apple.body.gravity.y = RED_APPLE_GRAVITY; apple.body.collideWorldBounds = true; }, this, false); greenApples.forEach(function (apple) { game.physics.arcade.enable(apple); apple.body.bounce.y = GREEN_APPLE_BOUNCE; apple.body.gravity.y = GREEN_APPLE_GRAVITY; apple.body.collideWorldBounds = true; }, this, false); Link to comment Share on other sites More sharing options...
valueerror Posted August 17, 2014 Share Posted August 17, 2014 thats how i do it to.. i think this is a very good approach..do you know that you can give those sprite propertiesdirectly in tiled? like name,velocity,customproperties.. they can thenbe accessed with mysprite.name or mysprite.customproperty Link to comment Share on other sites More sharing options...
kidos Posted August 17, 2014 Share Posted August 17, 2014 This is the same way that I'm doing too, works great. owen 1 Link to comment Share on other sites More sharing options...
Recommended Posts