Sign in to follow this  

image top of rectangle

Recommended Posts


Dont know how to move image top of rectangle.

Anyone know how to fix this?


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',
        create: create,
        render: render,
        update: update

function preload(){

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(){

function update(){
    Left.width +=1;

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


Share this post

Link to post
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  Oh yes, my mistake, i see it now, "Should always be either zero or a positive value". 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.