My object code (The player don’t stick to the Tilemap object):
objectFloats = this.physics.add.group({ allowGravity: false, immovable: true, moves: false });
objectFloats.addMultiple(
map.createFromObjects('objectFloats', 'objectFloat', { key: '' })
);
objectFloats.getChildren().forEach((objectFloat, index) => {
objectFloat.body.width = 96;
objectFloat.body.height = 16;
objectFloat.body.setVelocityX(-50);
objectFloat.body.setBounceX(1);
}, this);
this.physics.add.collider(player, objectFloats);
And another code tweens (The player stick to the image):
block = this.physics.add.image(100, 500, '').setImmovable(true);
block.body.setAllowGravity(false);
this.tweens.timeline({
targets: block.body.velocity,
loop: -1,
tweens: [
{
x: 100,
y: 0,
duration: 2000,
ease: 'Stepped'
},
{
x: -100,
y: 0,
duration: 2000,
ease: 'Stepped'
}
]
});
this.physics.add.collider(block, player);
How do I stick the player to the Tilemap object?