# Move sprites / images into container

**URL:** https://phaser.discourse.group/t/move-sprites-images-into-container/6072
**Category:** Phaser 3
**Created:** [April 25, 2020, 2:16am UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072 "2020-04-25T02:16:08Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![AitorG](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AitorG](https://phaser.discourse.group/u/AitorG)
#### Post date: [April 25, 2020, 2:16am UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072/1 "2020-04-25T02:16:08Z")

</div>

Hello dudes!

I am trying to move images inside a container with drag and drop. I tryed all, but there is no way to focus sprite when I add input event (it always takes the container if I set setInteractive() to container, and takes nothing if I only set setInteractive() to images/sprites, tested with both childreens).

```
> export default class Inventory extends Phaser.GameObjects.Container {
> 
> constructor(scene) {
> let x = 540
> let y = 230
> super(scene, x, y)
> this.depth = 700
> this.scene = scene
> this.x = x
> this.y = y
> this.alpha = 0
> this.setScrollFactor(0)
> this.items = {}
> this.width = 200
> this.height = 330
> this.displayHeight = 330
> this.displayWidth = 200
> 
> (...more code)
> 
> this.itemToMove = this.scene.add.sprite(0, 0, 'obj').setSize(30, 30).setDisplaySize(30, 30).setInteractive()
> this.add(this.itemToMove)

```

No matters if I try to catch the event in main scene making this.input.on(‘pointerdown’, (pointer, objects) =\> {here}) (I added this.input.topOnly = false, absoluty)  
or inside container class making .on(‘pointerdown’, ()=\>{here}) after setInteractive()

I think the problem is really easy: drag and drop a sprite inside container or from one container to another, but I cant event handle a simple pointerdown input in gameObject if its inside container ☹

Thanks for all help, this is making me crazy.

---

<div class="post-metadata">

### Author: ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)
#### Post date: [April 25, 2020, 2:36am UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072/2 "2020-04-25T02:36:36Z")

</div>

Can you drag the sprite if you make the containers noninteractive?

---

<div class="post-metadata">

### Author: ![AitorG](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AitorG](https://phaser.discourse.group/u/AitorG)
#### Post date: [April 25, 2020, 11:56am UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072/4 "2020-04-25T11:56:16Z")

</div>

No :(. I tested this on container: this.disableInteractive() and this.removeInteractive().

No matters what I do, if I click on child into container there is not pointer event response :-/. I have been working with Phaser for a months without problems, this is the first time I am stucked

---

<div class="post-metadata">

### Author: ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)
#### Post date: [April 25, 2020, 4:33pm UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072/5 "2020-04-25T16:33:58Z")

</div>

I haven’t tried add/remove, but all of the dragging works correctly for me:

https://codepen.io/samme/embed/preview/NWGjKRr?height=300&slug-hash=NWGjKRr&default-tabs=js,result&host=https://codepen.io

---

<div class="post-metadata">

### Author: ![AitorG](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AitorG](https://phaser.discourse.group/u/AitorG)
#### Post date: [April 25, 2020, 4:47pm UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072/6 "2020-04-25T16:47:14Z")

</div>

I am really tilted…

I know this should be really easy but I am sure this is not working. The only difference is I am typing the container in an external class, and then, in main scene, I make something like:  
`this.inventory = new Inventory(this)`

If you see the code on top, I am doing this in the container class:

```
  var image = this.scene.add.sprite(0, 0, 1).setSize(27, 27).setInteractive()
  this.add(image)
  this.scene.input.setDraggable(image)

```

and then this in Main scene:

```
   this.input.on("dragstart", function (pointer, gameObject) {
     gameObject.setTint(0xff0000);
   });

      this.input.on("drag", function (pointer, gameObject, dragX, dragY) {
        gameObject.x = dragX;
        gameObject.y = dragY;
      });

        this.input.on("dragend", function (pointer, gameObject) {
        gameObject.clearTint();
      });

```

And its still not working… ☹

I have this function in main scene:

```
this.input.topOnly = false
this.input.on('pointerdown', (pointer, objects) => {
  console.log(objects)
})

```

And when I click in my image inside of Inventory container, it only shows on console: [Inventory]. Image is not in console.log

---

<div class="post-metadata">

### Author: ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)
#### Post date: [April 25, 2020, 5:01pm UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072/7 "2020-04-25T17:01:36Z")

</div>

Without any containers, can you drag the sprite?

---

<div class="post-metadata">

### Author: ![AitorG](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AitorG](https://phaser.discourse.group/u/AitorG)
#### Post date: [April 25, 2020, 5:06pm UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072/8 "2020-04-25T17:06:02Z")

</div>

Yes, I can even drag the Inventory container if I make that draggable  
`this.scene.input.setDraggable(this)`

---

<div class="post-metadata">

### Author: ![AitorG](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AitorG](https://phaser.discourse.group/u/AitorG)
#### Post date: [April 25, 2020, 5:09pm UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072/9 "2020-04-25T17:09:39Z")

</div>

Can we have maybe a private call (discord or something) I can show you the game (that is awesome i think :P) the code and the error ^^’

---

<div class="post-metadata">

### Author: ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)
#### Post date: [April 25, 2020, 5:47pm UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072/10 "2020-04-25T17:47:37Z")

</div>

Can you DM me on Phaser Discord? I’m **samme** there also.

---

<div class="post-metadata">

### Author: ![AitorG](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AitorG](https://phaser.discourse.group/u/AitorG)
#### Post date: [April 25, 2020, 5:54pm UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072/11 "2020-04-25T17:54:23Z")

</div>

Done 😉

I will post here the solution if we find it 😃

---

<div class="post-metadata">

### Author: ![AitorG](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@AitorG](https://phaser.discourse.group/u/AitorG)
#### Post date: [April 25, 2020, 7:15pm UTC](https://phaser.discourse.group/t/move-sprites-images-into-container/6072/12 "2020-04-25T19:15:29Z")

</div>

Finally I got the solution…

The problem is that my game is a TileMap based game, and camera follows my player. Even when container have .setScrollFactor(0), **the image appears correctly but the interactive area is not there** , you have to use **.setScrollFactor(0)** to sprite **AFTER .setInteractive()**

I think this should be fixed in phaser core, if you set interactive a object that has scrollFactor 0 and is into container with scrollFactor 0, the interactive area should be scroll factor 0 too.

Thanks for your time!!
