Jump to content

cacheAsBitmap and pivot problem


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:



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.

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.


  • Recently Browsing   0 members

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