Jump to content

Sprite enableDrag problem (Help)


Heppell08
 Share

Recommended Posts

So i have coded most of my AS3 project over to HTML5 and i'm very impressed with the progress I'm making because it's going better than i thought. But the problem is I've ran into a weird issue and i cant explain/see why it is doing it lol.

So in my game i have cards that are randomly spawned in depending on a random number generator. I set the rarity of the cards the further down the line i go for the more powerful cards. So i coded in a few cards for now so i could test stuff and i noticed in the console that only 1 card is having problems being draggable by the mouse. 

Every card is coded the same way and i'll show this below now:

function preload() {game.load.image('fcard3', 'assets/firecard3.png');}function create() {fcard3 = game.add.sprite(300,300,'fcard3');fcard3.visible = false;fcard3.exists = false;fcard3.inputEnabled = true;fcard3.input.enableDrag(true);}

This is the exact card i'm having issues with but its all coded the same way and the other cards done react like this. The card spawns in and i see it fine ingame it just isnt draggable even though ive coded it in as draggable. Anyway any help would be nice and if you need more info i can provide it. Thanks

Link to comment
Share on other sites

The first thing the input handler does is check to see if the sprite is visible. If not, then it skips all pointer events for it:

    checkPointerOver: function (pointer) {        if (this.enabled === false || this.sprite.visible === false || (this.sprite.group && this.sprite.group.visible === false))        {            return false;        }

So I wouldn't expect your code above to work until fcard3.visible = true and the card exists.

Link to comment
Share on other sites

It's working now, it was actually a type error but the reason behind the invisible card is this:

I have a button, that button randomly generates a number and that random number is in relation to a card. So my example is this>

If i have a common firecard then its number range is between 1-10. Now that means i have 10 common firecards. Now my cards are created and added in but are invisible. When i press my button like so:

function spawnCard() { 	spawnRate = game.rnd.integerInRange(1, 15); 	if(spawnRate === 1) 	{ 		fcard1.visible = true; 		fcard1.exists = true; 	} 	if(spawnRate === 5) 	{ 		fcard2.visible = true; 		fcard2.exists = true; 	} 	if(spawnRate === 12) 	{ 		fcard3.visible = true;        fcard3.exists = true; 	} }

Bare in mind that above code is very primitive at the minute but as you see, if i press the button and the random number is 12, i then technically "spawn" the firecard3.

Hope that makes sense :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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