Drag & drop actor by touch? (rpg inventory solution)

Hello,

Is there any solution to the touch function when it gets to drag and drop?
I developed a simple inventroy to my game that pop up when you press a certen actor (backpack) on screen.
Inside I already set spawn rules for 3 different potions. BUT! I want to ask, Is there a way to use touch and move these actors slots?

At the moment the inventroy (backpack) is one big actor with slots painted in photoshop.
The potions spawn in correct x,y location to the inventroy actor.

What I want is that when you use touch on 1 item (actor) you should be able to move it to a new slot.
I guess that I can use transparent actors spawned on the slots then hook the items (potion actors) somehow but not sure.
Is it to complex or do someone have a solution to this issue?

Regards,

Comments

  • KIIVIINKIIVIIN Member Posts: 159

  • imjustmikeimjustmike Member Posts: 450

    It's a couple of things all together. You want a snap to be be able to drag and drop actors based on touch - that easily done by constraining the actor's position to mouse position.

    You also want those actors to be aligned to the boxes on your image, you can do that with a grid: http://forums.gamesalad.com/discussion/56974/free-snap-to-grid-tutorialtemplate-some-community-love

    Also, if I were you, I wouldn't be spawning the actors for potions etc each time the backpack is opened, it's quite wasteful in terms of game resources - you can have them all off screen and move into position. In fact, you could constrain all the potions positions to the one inventory actor and just move that actor.

  • KIIVIINKIIVIIN Member Posts: 159

    @imjustmike said:
    It's a couple of things all together. You want a snap to be be able to drag and drop actors based on touch - that easily done by constraining the actor's position to mouse position.

    You also want those actors to be aligned to the boxes on your image, you can do that with a grid: http://forums.gamesalad.com/discussion/56974/free-snap-to-grid-tutorialtemplate-some-community-love

    Also, if I were you, I wouldn't be spawning the actors for potions etc each time the backpack is opened, it's quite wasteful in terms of game resources - you can have them all off screen and move into position. In fact, you could constrain all the potions positions to the one inventory actor and just move that actor.

    So the function I use, Spawn inventory when inventroy is true and destroy inventroy when false takes a lot of data?

    Even if its getting destroied each time?
    Didnt know that :open_mouth:

  • ArmellineArmelline Member, PRO Posts: 5,365

    @KIIVIIN said:
    So the function I use, Spawn inventory when inventroy is true and destroy inventroy when false takes a lot of data?

    Even if its getting destroied each time?
    Didnt know that :open_mouth:

    Spawning and destroying them is likely to be less resource intensive. It will reduce the number of actors permanently on the scene, it will reduce the logic that needs to be scanned each cycle, and if the number of actors you're spawning is less than about 10 there's going to be no impact on the user experience. I have no idea if anyone ever actually ran tests on spawning vs moving, but the performance difference is going to be so very minor that I'd just go with whatever you prefer and find easiest.

  • imjustmikeimjustmike Member Posts: 450

    @Armelline said:

    @KIIVIIN said:
    So the function I use, Spawn inventory when inventroy is true and destroy inventroy when false takes a lot of data?

    Even if its getting destroied each time?
    Didnt know that :open_mouth:

    Spawning and destroying them is likely to be less resource intensive. It will reduce the number of actors permanently on the scene, it will reduce the logic that needs to be scanned each cycle, and if the number of actors you're spawning is less than about 10 there's going to be no impact on the user experience. I have no idea if anyone ever actually ran tests on spawning vs moving, but the performance difference is going to be so very minor that I'd just go with whatever you prefer and find easiest.

    True - but I was working on the assumption that, it being an inventory, there'd be loads of actors to spawn all at once - especially if the things like potions are stackable. I've noticed that if I'm spawning 20+ at once items my games lag out a bit.

  • KIIVIINKIIVIIN Member Posts: 159

    @imjustmike said:

    @Armelline said:

    @KIIVIIN said:
    So the function I use, Spawn inventory when inventroy is true and destroy inventroy when false takes a lot of data?

    Even if its getting destroied each time?
    Didnt know that :open_mouth:

    Spawning and destroying them is likely to be less resource intensive. It will reduce the number of actors permanently on the scene, it will reduce the logic that needs to be scanned each cycle, and if the number of actors you're spawning is less than about 10 there's going to be no impact on the user experience. I have no idea if anyone ever actually ran tests on spawning vs moving, but the performance difference is going to be so very minor that I'd just go with whatever you prefer and find easiest.

    True - but I was working on the assumption that, it being an inventory, there'd be loads of actors to spawn all at once - especially if the things like potions are stackable. I've noticed that if I'm spawning 20+ at once items my games lag out a bit.

    The only thing I spawn in the inventory is "3x power actors, 2x different potions (stackable) and 1 actor showing keys.) But was thinking for making items in the game like armor etc , mining ores and so on. So the person playing can arrange the order in the backpack them selfs. But since its so complicated to make I concider to skip this part.

Sign In or Register to comment.