Jump to content

do you have some advice on this snippet ?


espace
 Share

Recommended Posts

hi,

i think that this snippet work good but it's interesting if you you could give me some advice or optimization that I would not have thought at the base

the principle is an object (sprite1) who is falling and some other object (table) slow down his fall.

https://jsfiddle.net/espace3d/a13v8r8b/

thanks ;)

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload,create: create, update: update, render: render });

var table
var sprite1

function preload() {
   game.load.image('circle', 'https://s13.postimg.org/xjhlzmiev/disc_png.png');
   game.load.image('rect', 'http://s10.postimg.org/6fa6mgrd5/motif.jpg');
}

function create() { 
game.physics.startSystem(Phaser.Physics.ARCADE);

        sprite1=game.add.sprite(400, 300, 'rect');
   	sprite1.anchor.x=.5
  	sprite1.anchor.y=.5
   	sprite1.width=100
   	sprite1.height=100
   	sprite1.alpha=1

game.physics.enable(sprite1, Phaser.Physics.ARCADE);

table=[]
for (var j=0; j < 10 ;j++) {
    table[j] = game.add.sprite(0, 0, 'rect')
    table[j].width = 400
    table[j].height = 1
    table[j].x = 200
    table[j].y = game.rnd.between(400,500)
    game.physics.enable(table[j], Phaser.Physics.ARCADE);
    table[j].body.immovable = true;
}
}

function update() {
    sprite1.body.velocity.y = 100
		for (var j=0; j < table.length ;j++) {
			game.physics.arcade.collide(sprite1, 				table[j],collision,null,this);
		}
}

function collision(obj1,obj2){
game.time.events.add(150,() => destroyTable(obj2),this)
}

function destroyTable(obj2){
obj2.body.enable=false
obj2.visible=false
}


function render() {
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...