Hi everyone, I have a problem with my game.
I have created a character that is of type sprite and a group of images that are TileSprites. When I move my character following the mouse, I have a tween that does magic. But when the sprite moves and meets one of those TileSprites, I need the sprite to stop the movement only in the direction where the obstacle is.
I can’t make a static group, because when the main character is on a specific coordinate point I have a parallax effect and all the objects move in the opposite direction. I tried it with collides, but it doesn’t work.
I’ve defined:
private elementsGroup: GO.Group;
private mainCharactec: GO.Sprite;
create() {
this.elementsGroup = this.physics.add.group();
this.elementsGroup.createMultiple(
[
{ key: 'enciamsH', frame: 0, repeat: 2, setXY: { x: 200, y: 400, stepX: 540, stepY: 960 } },
{ key: 'colsH', frame: 0, repeat: 2, setXY: { x: 776, y: 400, stepX: -540, stepY: 1080 } },
{ key: 'enciamsV', frame: 0, repeat: 0, setXY: { x: 584, y: 784, stepX: 540 } },
{ key: 'colsV', frame: 0, repeat: 0, setXY: { x: 200, y: 784, stepX: 540 } },
]
)
this.mainCharacter = this.physics.add.sprite( 422, 1010, 'logo').setBounce(0).setFriction(0).setCollideWorldBounds(true);
this.followMouse(this.mainCharacter);
this.physics.world.setBoundsCollision();
this.physics.add.collider(this.elementsGroup, this.logo);
}
function followMouse(this.mainCharacter) {
.... //code to run tween
this.tweens.add({
targets: sprite,
x: coordX,
y: coordY,
duration: 200
});
....
}