Scripts / how to create/delete sprites in the main function

Author
Message
AlreadyTakenGuy
3
Years of Service
User Offline
Joined: 25th Mar 2021
Location:
Posted: 30th Mar 2021 19:51
Hello there!
I would like to create a "sprite" by pressing C and delete it by pressing E. But if I enter these commands in the main it doesn't work, the sprite is not deleted.
Do you have any idea how to solve this problem?
Thank you!


PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 30th Mar 2021 20:16 Edited at: 30th Mar 2021 20:17
probably just creating loads of sprites on top of each other as the keypresses are true for all frames the key is pressed.



edit, not sure what happened to the indenting there
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 30th Mar 2021 21:01
Unless you are in danger of using up all 10,000 sprites there is very little to be gained by deleting them btw.

Images use up storage equal to the size of the image, sprites are just a small table of values referencing the main image they were created from, when drawn on screen they are generated from the main image itself.

(you can find this out the hard way is you delete the image and then try to use the spite! )
Been there, done that, got all the T-Shirts!
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 30th Mar 2021 23:22 Edited at: 30th Mar 2021 23:31
The one key press is easy to fix but most users might not realize that.
Aside from the memory allocation (I have no knowledge on) sounds like a good test
subject what AmenMoses said.
having something like; g_OneKeyPressC

if g_OneKeyPressC = true then ---------- "You Caught the One and Only Easter Bunny!"
might be a useful global.lua function seeing as this is a common request.
It would allow for only one key press at a time similarly would be useful for g_Scancode.

I think it might be as simple as this (tell me if I missed something):
g_OneKeyPressC = g_KeyPressC
-- (engine watches for keypress)
g_OneKeyPressC = g_OneKeyPressC + g_KeyPressC
-----------------------------------------------------
-----alternatively to use true/false-----
----------------------------------------------------
if g_KeyPressC == 1 and g_OneKeyPressC == false then
g_OneKeyPressC = true
else
g_OneKeyPressC = false --(( does this code /setting it true here / contradict itself? ))
end

then you can (as above);
if g_OneKeyPressC == 1 then --- (alternatively = true)
Text(,,,," ---------- You Caught the One and Only Easter Bunny!")
else
Text(,,,," Missed! ---------- "The Easter Bunny is fast!")
end
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 30th Mar 2021 23:35
Well, @ above I don't think my first suggestion is gonna work...?
Haven't tested second one either lol

@1st;
g_OneKeyPressC = 0 <<=== (neither will this)
-- (engine watches for keypress)
g_OneKeyPressC = g_OneKeyPressC + g_KeyPressC
PM
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 31st Mar 2021 10:41
Often you are best changing sprite position out of the screen for later use, rather than delete them and create them, again and again, obviously depending on how often you are going to use them.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM

Login to post a reply

Server time is: 2024-12-22 01:43:37
Your offset time is: 2024-12-22 01:43:37