(Solved) Creating a sprite inside virtual cell

Hi there,

As a basis I am using the grid example project to create a virtual grid.
What I want to achieve is when clicking inside a cell, a sprite is created and snapped inside the grid.
This is whats happening:

grid

As you can see the sprites are created, but are not always positioned inside the desired cell.

My code:

Please see the first reply below

Maybe there should be a different approach to when creating sprite on the x and y position of the cursor.

By the way, the sprite itself has the same dimension of the cell (32*32). I also played with the origin point of the sprite, but doesnt help with the problem.

Anyone have an idea? Thank you

The code

Wow never mind, I already found the solution!

I changed the position of the created sprite to cursorX()-16 and cursorY()-16