Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Hiding a sprite and also disabling its interactions

Author
Message
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 11th Nov 2012 06:57
I notice that SetSpriteVisible() does not affect user interactions with the sprite. If one sprite is on top of another sprite, it always is the one that gets detected via GetSpriteHit() even if it is not visible.

I am curious what methods others have used to make sure that sprites can't interact with anything once they have been set to invisible using SetSpriteVisible(sprNum, 0)? SetSpriteActive() does not help in the situation described above.

Here's a code snippet, the second sprite is always the one detected under the mouse even if it is not visible. Ideally I shouldn't have to move the sprite off-screen or perform other transformations on it just to enable/disable its interactivity when needed.


Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 11th Nov 2012 07:39
I haven't run into this problem myself, probably because I delete sprites and recreate them on the fly but I understand that won't always be convenient.

What you could try is instead of using SetSpriteVisible(), you could set the sprite's size to 0. And then to return to it's original size (size when created) you can use SetSpriteSize(spr, -1,-1). It's probably a good idea to store the sprite's width and height before sizing it to 0, just in case.

I haven't personally tried the above method myself in a situation similar to yours so if you embark on this journey, let me know the results.

Cheers

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th Nov 2012 08:58 Edited at: 11th Nov 2012 08:59
You could just use setSpriteShape(spriteID,0), this will give the sprite no shape to detect.


this.mess = abs(sin(times#))
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 11th Nov 2012 09:35
option 1: put the sprite outside the window like at position -1000, -1000

options 2: use Spritegroups to detect Hits, and set your sprite to a different group
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 11th Nov 2012 11:55
Quote: "You could just use setSpriteShape(spriteID,0), this will give the sprite no shape to detect."


Do it as bax writes .

To activate it again so do you use the same command setSpriteShape(spriteID,3).

And you can use any shape id when reactivating it again as the first shape created will be used again if you dont delete the shape.

I use it alot in my platformer.

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2012 10:13
The "setSpriteShape(spriteID, 0)" solution appears to be broken in v108 so until it is fixed you can use this "setSpriteShapeCircle(spriteID, 0, 0, 0)" to get the same effect.

setSpriteActive only sets whether Physics or Animation is active contrary to my own previous belief


this.mess = abs(sin(times#))
DVader
20
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 10th Dec 2012 16:54 Edited at: 10th Dec 2012 16:57
You can also use the getspritevisible command to check whether it is visible. If it is, collide, if it isn't ignore.
So:
if getspritevisible(hare)=1
if getspritecollide(fox,hare)=1
setspritevisible(hare,0)
endif
endif
This will detect if the 2 sprites collide and also check if hare is visible. If it is, it collides, if it isn't, it ignores it.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th Dec 2012 17:02
Good idea DVader


this.mess = abs(sin(times#))

Login to post a reply

Server time is: 2024-04-28 00:27:17
Your offset time is: 2024-04-28 00:27:17