hi i’m new to phaser 3 and i have a lot of problems.
as I can create an infinite platforms loop like in this example: Phaser - Examples - Time - Basic Repeat Event try with:
game.time.events.repeat(Phaser.Timer.SECOND * 2, 10, createBall, this);
function createPlataformsl() {
plataforms = this.physics.add.sprite(Phaser.Math.Between(0,600), 0, 'barra').setDisplaySize(200, 200).setSize(80,8);
}
for some reason it doesn’t work
game demo:
https://games.phasereditor2d.com/Ederishh/Game/
type or paste code here
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
parent: 'container',
physics: {
default: 'arcade',
arcade: { gravity: { y:70 },
debug: false
}
},
scene: {
preload: preload,
create: create,
update: update
}
};
var game = new Phaser.Game(config);
var cursors;
var player;
var score = 0;
var scoreText;
var plataforms;
function preload (){
//----------------------pleyer-------------------//
this.load.image('ball', 'assets/Ball.png');
//----------------------Background-------------------//
this.load.image('background', 'assets/lofi-1.jpg');
//----------------------Audio-------------------//
this.load.audio('leve-1','assets/level-1.mp3');
//----------------------plataforms-------------------//
this.load.image('barra','assets/barra.png');
}
function create (){
//-----------------backgraund-------------//
this.add.image(400, 300, 'background').setDisplaySize(800, 600);
//--------------------Audio-------------------------------------//
let audio = this.sound.add('leve-1',{loop:true}); audio.play();
//-------------------- Puntuacion -------------------------------------//
scoreText = this.add.text(16, 16, 'score: 0', { fontSize: '32px', fill: '#fff' });
//-------------------- fisicas de la bola -------------------------------------//
player = this.physics.add.sprite(Phaser.Math.Between(0,600), 0, 'ball');
player.setDisplaySize(50,50);
player.setGravityY(20000);
player.setCollideWorldBounds(true);
player.setBounce(0.70);
//------------------ plataformas --------------//
//game.time.events.repeat(Phaser.Timer.SECOND * 2, 10, createPlataforms, this);//
//function createPlataforms(){
this.barra = this.physics.add.sprite(Phaser.Math.Between(0,600), 0, 'barra');
this.barra.setDisplaySize(200, 200)
this.barra.setSize(80,8)
//}
//-------------------crear controles----------//
cursors = this.input.keyboard.createCursorKeys();
//----------------------- Colisiones -----------//
this.physics.add.collider(player,this.barra);
this.barra.body.checkCollision.up = true;
this.barra.body.checkCollision.down = false;
this.barra.body.checkCollision.left = false;
this.barra.body.checkCollision.right = false;
}
function update (){
//-----------------controles----------------//
player.setVelocity(0);
if (cursors.left.isDown){
player.setVelocityX(-500);
}
else if (cursors.right.isDown){
player.setVelocityX(500);
}
if (cursors.space.isDown){
player.setVelocityY(-500);
}}