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.

Newcomers AppGameKit Corner / Using a sprite as a button

Author
Message
ragnarox
8
Years of Service
User Offline
Joined: 4th Oct 2015
Location:
Posted: 4th Oct 2015 20:54
Hello,

I've scoured the forum for a way to do this, but I have not found exactly what I am looking for, only hints and suggestions.

Basically, what I want to do is when I click a certain sprite (4) on my screen I want it to make my sprite (7) visible - i have set it to invisible by default.

I know the basic gist is that I nest this:

SetSpriteVisible(7, 1)

inside an 'if' statement. with the 'if...' being whatever the code is for "sprite(ID) has been clicked".

i've tried GetSpriteHit but i don't think/can't figure out if this is the piece of code that i should be using, it hasn't worked so far.

Thank you.
Crazy Programmer
AGK Developer
19
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 4th Oct 2015 21:23 Edited at: 5th Oct 2015 04:16
I cant see your post as it is not yet visible...But taking a shot in the dark, im guessing you need to use a sprite as a button and need to know how?

First we need to make a sprite and Set Window specs

//Set Window Size//
SetWindowSize( 1024, 768, 0 )

// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )



//Make Button Sprite
Button = CreateSprite(0)

//Set Button Size
SetSpriteSize(Button,50,50)

//Set Button Position
SetSpritePosition(Button,500,350)



//Game loop//

Do

//Check to see if Cursor is Within the sprites parameters while pointer is pressed//
If GetSpriteHitTest(Button,GetPointerX(),GetPointerY()) = 1 and GetPointerPressed() = 1

//Show evidence of button pressed//
Print("Button Pressed")

endif




Sync()
loop





This is a demonstration of what you are trying to do with setting sprites visible and back to invisible.
Click the small square in middle of screen to reveal a larger square. Click the smaller square again to hide the larger square.

Beta Test Age of Knights:https://play.google.com/apps/testing/com.CrazyProgrammerProductions.my_AgeOfKnights
Download JellyFish Dive:https://play.google.com/store/apps/details?id=com.CrazyProgrammerProductions.my_JellyFishSwim
ragnarox
8
Years of Service
User Offline
Joined: 4th Oct 2015
Location:
Posted: 5th Oct 2015 15:48
Thanks dude ^ worked like a charm!

I don't know if I should I make a new thread if I have another question, I figure no need to create unneeded traffic in the forum.

SO my next quesiton

my code is getting a bit long and hard to keep track of. i know about #include "filename.agc" and I have used it to store a few functions. However, when I try to use this for other things, such as storing the code for loading sprites at the beginning, the program either doesn't compile, or it compiles but the program crashes on startup. Are there any hard and fast rules about what I can put in the #include ... command? Can it only be used for functions or can it be used for anything and am I just doing something wrong?


Thank you!
BatVink
Moderator
20
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Oct 2015 17:04
#include - only for functions, globals and constants

#insert - use for anything that makes sense at that point in your code. It puts the file into the code at that exact point.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
ragnarox
8
Years of Service
User Offline
Joined: 4th Oct 2015
Location:
Posted: 6th Oct 2015 00:47
Once again, worked perfectly. Thank you!

Just one little other question...

Can I throw my

SetVirtualResolution(1920,1080)
SetOrientationAllowed(0,0,1,1)

into the setup.agc?

or do these have to be in main.agc?

Login to post a reply

Server time is: 2024-03-29 14:30:19
Your offset time is: 2024-03-29 14:30:19