Jump to content

image top of rectangle


ruslanfan
 Share

Recommended Posts

Hello!

Dont know how to move image top of rectangle.

Anyone know how to fix this?

Thanks!

var width = window.innerWidth;
var height= window.innerHeight;
var glass;
var Left;

var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.WebGL, 'phaser-example',
    {   
        preload:preload,
        create: create,
        render: render,
        update: update
});

function preload(){
    game.load.image('glass','glass.png');
}

function create(){

    game.stage.backgroundColor = '#ffffff';

    Left = new Phaser.Rectangle(width/2, 0, -100, height);

    glass = game.add.sprite(100,100,'glass');

    leftKey = game.input.keyboard.addKey(Phaser.Keyboard.LEFT);
    leftKey.onDown.add(leftW, this);
}


function leftW(){
    Left.width-=50;
}

function update(){
    Left.width +=1;
   
    if(Left.width>-1){
        Left.width=0;
    }
}

function render () {
    game.debug.geom(Left, '#fbc162');
}

 

Link to comment
Share on other sites

@dude78 in my scene two rectangles at center with width = 0,  and when i press arrow right or left width of particular rectangle visually increase, so the left rectangle is minus value because it's moving to left side of screen. Here it is https://codepen.io/ruslanlearncode/full/yRbKPd/  Oh yes, my mistake, i see it now, "Should always be either zero or a positive value". 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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