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 / Help needed with Sprite button function

Author
Message
DemonHill
16
Years of Service
User Offline
Joined: 20th Mar 2008
Location:
Posted: 29th Oct 2017 10:40 Edited at: 29th Oct 2017 10:57
I am new to AppGameKit having used Dark Basic Pro in the past. Try as I may I cant get this function working. I am trying to create a function to use a three state sprite image for hover over and pressing, however I get a sprite position at 0,0, even though I declare coordinates and get a button in the right place... not sure if this is inherent in AppGameKit or the way I an using functions etc.

I would really appreciate someone looking at the code below... Media attached also


Attachments

Login to view attachments
puzzler2018
User Banned
Posted: 29th Oct 2017 11:19 Edited at: 29th Oct 2017 11:26
Try



I see in the code that your repeating creating sprites during the main loop processing - this is a no no

I have tweaked it a bit for you

EDIT - remove the sleep(100) - (line 102) I put it there to see it in action to be a little slower
D
puzzler2018
User Banned
Posted: 29th Oct 2017 13:48
Optimised it just slightly



If need anymore assist then let us know

Have fun with AppGameKit and welcome

D
DemonHill
16
Years of Service
User Offline
Joined: 20th Mar 2008
Location:
Posted: 29th Oct 2017 14:22 Edited at: 29th Oct 2017 14:47
really appreciated guys, works great thanks, although what if I want multiple buttons with different images... hence why I declared the Function ThreeStateButton(mx1,my1,norm_image,hover_image,pressed_image) originally... so you could call the function but with different images for subsequent buttons... how would that work ?
puzzler2018
User Banned
Posted: 29th Oct 2017 15:24 Edited at: 29th Oct 2017 15:34
Multiple buttons



EDIT:- added a buttonpressed (to let the app know which was pressed



D
DemonHill
16
Years of Service
User Offline
Joined: 20th Mar 2008
Location:
Posted: 29th Oct 2017 16:30
But how do you have different buttons ? i.e. with different sprites ? Sorry that's why I had the Function with the image to be used declared originally....

ThreestateButton (posx,posy,sizex,sizey,norm_image,hover_image,pressed_image)

With integers for the 3 images for each button.

So for one button you would have

ThreestateButton (posx,posy,sizex,sizey,50,51,52) where the images for the three buttons are 50,51 and 52

and

ThreestateButton (posx,posy,sizex,sizey,60,61,61) where for this button you would use 3 other images..
puzzler2018
User Banned
Posted: 29th Oct 2017 16:35
Maybe change the load code to something like
button[a].normal = CreateSprite(Loadimage("button"+str(a)+".png"))
button[a].hover = CreateSprite(Loadimage("button"+str(a)+".hover.png"))
button[a].pressed = CreateSprite(Loadimage("button"+str(a)+".pressed.png"))


Then making sure your actual images are like this

button1normal.png, button1pressed.png, button1hover.png
button2normal.png, button2pressed.png, button2hover.png
button3normal.png, button3pressed.png, button3hover.png
button4normal.png, button4pressed.png, button4hover.png
button5normal.png, button5pressed.png, button5hover.png
button6normal.png, button6pressed.png, button6hover.png
button7normal.png, button7pressed.png, button7hover.png
button8normal.png, button8pressed.png, button8hover.png

DemonHill
16
Years of Service
User Offline
Joined: 20th Mar 2008
Location:
Posted: 29th Oct 2017 17:10
Perfect, just figured that out, but not as quickly as you responded. really appreciate the support thanks
puzzler2018
User Banned
Posted: 29th Oct 2017 17:13
Your welcome

Login to post a reply

Server time is: 2024-11-22 20:34:31
Your offset time is: 2024-11-22 20:34:31