Bonjour

Actuellement, j'essaye de développer un petit jeu sous Phaser qui génère des cubes à intervalle de temps et les laissent tomber, puis le jouer peut les déplacer.

Cependant je rencontre plusieurs problèmes:
1 : Parfois lorsque un cube est crée, lorsqu'il tombe dans sa collone et qu'il y a deja plusieurs cubes, alors le premier cubes disparait.
2 : Le jouer peut quand même se mettre derrière un cubes, alors que je gère les collisions.

Si quelqu'un a une idée, je suis preneur.

Voici mon code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var game = new Phaser.Game(300, 500, Phaser.AUTO, 'canvasGame', { preload: preload, create: create, update: update, render: render });
 
function preload() {
 
    game.load.image('background', 'assets/Blackboard.png');
    game.load.image('ground', 'assets/ground.png');
    game.load.spritesheet('box', 'assets/box_30.png', 31, 31);
    game.load.spritesheet('dude', 'assets/dude.png', 32, 48);
 
}
 
var player;
var platforms
var BOX_SIZE_SPACED = 30;
var BOARD_COLS;
var BOARD_ROWS;
var boxGroup;
var countBoxLoop = 2;
var timeLoop = 7000;
var velocityBoxY = 150;
var createbox_bool = true;
 
 
function create() {
    //  We're going to be using physics, so enable the Arcade Physics system
    game.physics.startSystem(Phaser.Physics.ARCADE);
    //game.physics.p2.setImpactEvents(true);
 
    game.add.sprite(0, 0, 'background');
 
    platforms = game.add.group();
    platforms.physicsBodyType = Phaser.Physics.ARCADE;
    platforms.enableBody = true;
    var ground = platforms.create(0, game.world.height - 20, 'ground');
    ground.body.immovable = true;
 
    player = game.add.sprite(32, game.world.height - 100, 'dude');
    game.physics.arcade.enable(player);
    player.body.bounce.y = 0.2;
    player.body.gravity.y = 500;
    player.body.collideWorldBounds = true;
 
    //  Our two animations, walking left and right.
    player.animations.add('left', [0, 1, 2, 3], 10, true);
    player.animations.add('right', [5, 6, 7, 8], 10, true);
 
    BOARD_COLS = Phaser.Math.floor(game.world.width / BOX_SIZE_SPACED);
    BOARD_ROWS = Phaser.Math.floor(game.world.height / BOX_SIZE_SPACED);
 
    boxGroup = game.add.group();
    boxGroup.physicsBodyType = Phaser.Physics.ARCADE;
 
    //game.physics.p2.enable([ platforms, boxGroup], false);
 
    createBox();
    game.time.events.loop(timeLoop, createBox, this);
 
    //  Our controls.
    cursors = game.input.keyboard.createCursorKeys();
 
}
 
function createBox() {
    var i = game.rnd.integerInRange(0, 10);
    var j = 0;
    var spriteBox = boxGroup.create(i * BOX_SIZE_SPACED, j * BOX_SIZE_SPACED, "box");
    game.physics.enable( [spriteBox], Phaser.Physics.ARCADE);
 
    spriteBox.body.collideWorldBounds = true;
    spriteBox.body.velocity.y = velocityBoxY;
    spriteBox.body.gravity.y = 200;
 
}
 
function boxHit (body, shapeA, shapeB, equation) {
    console.log('kinematic');
    body.body.kinematic = true;
}
 
function update () {
    game.physics.arcade.collide(player, boxGroup);
    game.physics.arcade.collide(player, platforms);
    game.physics.arcade.collide(boxGroup, boxGroup);
    game.physics.arcade.collide(boxGroup, platforms);
    //game.physics.arcade.collide(boxGroup, boxGroup, boxHit, null, this);
    //game.physics.arcade.collide(boxGroup, platforms, boxHit, null, this);
 
    //  Reset the players velocity (movement)
    player.body.velocity.x = 0;
 
    if (cursors.left.isDown)
    {
        //  Move to the left
        player.body.velocity.x = -150;
 
        player.animations.play('left');
    }
    else if (cursors.right.isDown)
    {
        //  Move to the right
        player.body.velocity.x = 150;
 
        player.animations.play('right');
    }
    else
    {
        //  Stand still
        player.animations.stop();
 
        player.frame = 4;
    }
 
    //  Allow the player to jump if they are touching the ground.
    if (cursors.up.isDown && player.body.touching.down)
    {
        player.body.velocity.y = -350;
    }
 
}
 
function render () {
 
    game.debug.inputInfo(32, 32);
 
}
Voila le jeu pour l'instant, pour vous faire une idée :
Nom : Capture-d'écran-2015-01-08-08.40.png
Affichages : 486
Taille : 23,2 Ko

Cordialement.