Jump to content

cacheAsBitmap and pivot problem


Carlos
 Share

Recommended Posts

A hacky way to get over this is to offset the body subtracting the value used for the pivot.

Now the body is aligned with the sprite but the input is still in the wrong place.
 

var game = new Phaser.Game(800, 600, Phaser.CANVAS, null, {preload: preload, create: create, render: render});var sprite = [];function preload() {        game.load.image('img', 'http://icons.iconarchive.com/icons/yusuke-kamiyamane/fugue/16/target-icon.png');}function create() {    var group = game.add.group(game.world, 'group', false, true);    for (var i = 0; i < 30; i++) {                sprite[i] = group.create(game.world.randomX, game.world.randomY, 'img');                sprite[i].inputEnabled = true;                sprite[i].events.onInputDown.add(hey, this);        sprite[i].body.offset.setTo(-10, -10);            }        group.pivot.setTo(10, 10);        group.cacheAsBitmap = true;}function hey() {        alert('hey');    }function render() {        for (var i = 0; i < sprite.length; i++) {                game.debug.body(sprite[i]);        }    }

You can see that the input coordinates for the onInputDown event are not aligned with the sprite in this fiddle:

http://jsfiddle.net/cmnb/wdmxa36y/1/

-_-

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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