Scripts / Move Sprite when key is pressed

Author
Message
Nathan38
15
Years of Service
User Offline
Joined: 13th Feb 2011
Location:
Posted: 11th Jul 2016 15:28 Edited at: 11th Jul 2016 15:40
Hi all,
I'm trying to make a small menu that can be toggled when the P key is pressed. The below code does create the sprite however when the Key P is pressed, it is not moved to the coordinates that it should be.

If I set the starting position of the sprite to 50,50, instead of 200,200, the sprite starts in the center of the screen, if I then press the P key, it disappears.



Any help with this would be hugely appreciated, it's driving me crazy
AmenMoses
GameGuru Master
10
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Jul 2016 18:39
200, 200 is off screen, 50,50 is centre of the screen, sprite coordinates are in % of screen not pixels.

So 0, 0 is top left, 100, 100 is bottom right.

Hope that helps.
Been there, done that, got all the T-Shirts!
PM
Nathan38
15
Years of Service
User Offline
Joined: 13th Feb 2011
Location:
Posted: 11th Jul 2016 18:43
Hi AmenMoses,
Thanks for getting back to me, the problem is that the sprite just doesn't show at all when the key is pressed, the positioning is fine
AmenMoses
GameGuru Master
10
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Jul 2016 20:44
if p_key_pressed == 0 and not release_key() then
p_key_pressed = 1
SetSpritePosition (character_panel_Sprite,25,25)
end

if p_key_pressed == 1 and release_key() then
p_key_pressed = 0
SetSpritePosition (character_panel_Sprite,200,200)
end
Been there, done that, got all the T-Shirts!
PM
Nathan38
15
Years of Service
User Offline
Joined: 13th Feb 2011
Location:
Posted: 11th Jul 2016 22:41
It's getting there, the menu only stays up when the P key is held, rather than a toggle
AmenMoses
GameGuru Master
10
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Jul 2016 23:12 Edited at: 11th Jul 2016 23:14
I did wonder why the code was so complex.

Try this

Been there, done that, got all the T-Shirts!
PM
Nathan38
15
Years of Service
User Offline
Joined: 13th Feb 2011
Location:
Posted: 12th Jul 2016 09:38 Edited at: 12th Jul 2016 10:14
Thank you So much AmenMoses!

I don't quite understand it yet, but it works beautifully! now I just need to figure out how to get some text on there

thanks again!

Login to post a reply

Server time is: 2026-06-09 03:20:28
Your offset time is: 2026-06-09 03:20:28