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 / how to use getspriteinbox()

Author
Message
Jo Bach
9
Years of Service
User Offline
Joined: 22nd Dec 2014
Location:
Posted: 11th Jan 2015 00:20
Hi all,

As a beginner agk2-programmer I saw the great example demo baws in agk2. I try to practice to find out how the code in this works.

I made a cup sprite that includes the setspriteshapebox and setspriteaddbox at the bottom of the screen.
the sprite of the cup is 80px x 80px


Now i let a ball fall, at the top of the screen by clicking. It falls and stays in the cup (physics are on), that works correct. But i want to get the score to add 1 when it falls in the cup.

When i use getspriteinbox(bal, GetSpriteX(cup),GetSpriteX(cup)+80, GetSpriteY(cup), GetSpriteY(cup)+80) it counts the score like crazy from falling. It stops counting when it catched in the basket.

I can't find out why the score is counting when the ball starts at the top off the screen. It have at least start counting when te bal is (at least close to or) in "the box of the cup"?

With SetPhysicsDebugOn(), I can't see the getspriteinthebox()-box. (the set- and addspriteboxes are visible).

What am I doing wrong?

Is there a more info about the getspriteinbox() function?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 11th Jan 2015 15:24
was this row from code?
Quote: "getspriteinbox(bal, GetSpriteX(cup),GetSpriteX(cup)+80, GetSpriteY(cup), GetSpriteY(cup)+80)"

GetSpriteInBox( iSprite, x1, y1, x2, y2 )

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
Jo Bach
9
Years of Service
User Offline
Joined: 22nd Dec 2014
Location:
Posted: 12th Jan 2015 22:31
Yes. Now I see it. tnx.

Tnx the example didn't show the x and y values. I missed that one. lol.

Now it starts working better.

Still I can't see that "box" in debug.

Is this function "GetSpriteInBox" a non visual box? that can detect if a sprite is inside this box?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Jan 2015 09:29
its not a physics part but u can draw lines for it,
for easy use 2 diagonal lines.

WorldToScreenX ( x )
WorldToScreenY ( y )
DrawLine ( x1, y1, x2, y2, red, green, blue )

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)

Login to post a reply

Server time is: 2024-11-25 15:38:59
Your offset time is: 2024-11-25 15:38:59