ruslanfan Posted October 10, 2018 Share Posted October 10, 2018 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 More sharing options...
ruslanfan Posted October 10, 2018 Author Share Posted October 10, 2018 for example i can use png instead "new Phaser.Rectangle" and it looks ok, but it needs images - not ok Link to comment Share on other sites More sharing options...
dude78 Posted October 11, 2018 Share Posted October 11, 2018 @ruslanfan, Why did you set width of Rectangle to -100? https://photonstorm.github.io/phaser-ce/Phaser.Rectangle.html#Rectangle Link to comment Share on other sites More sharing options...
ruslanfan Posted October 11, 2018 Author Share Posted October 11, 2018 @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 More sharing options...
dude78 Posted October 12, 2018 Share Posted October 12, 2018 @ruslanfan, did you solve the problem? Link to comment Share on other sites More sharing options...
Recommended Posts