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 Studio Chat / Multiple CreateImage() Calls for Same Image

Author
Message
3Dski
User Offline
Joined: 8th Jan 2020
Location:
Posted: 12th Jan 2020 01:42
This isn't really a "bug" but I feel it's a bit of an optimization issue...

I've seen code examples, as well as code created in the AppGameKit Studio scene editor, where CreateImage() is called more than once for the same image and giving it a different ID. However, it seems like it would be much more efficient to simply load the image one for repeated sprites, then reuse that image ID to create the sprites. As a likely scenario, the same sprite may be repeated for a large number of wall blocks and the editor will not only create the sprites (which is logical), it also illogically creates LoadImage() calls for every single instance of the same image.

In addition, because the *.scene file is managed by the editor, there seems to be no way to optimize its current behavior. So, I would think that logic could be added to the scene editor to watch for when an image is loaded into the project's media folder and generate the LoadImage() call with a trackable image ID. Then, for each instance that's dragged into the scene, it's logical that this requires a CreateSprite() call. The tracking would be done by using the name of the file used for image in the media folder; i.e., if the "snow.png" image has already been loaded, ignore the load and generate the CreateSprite for every instance of that image place into the scene.
Qugurun
AGK Developer
5
Years of Service
User Offline
Joined: 8th Dec 2014
Location: Tyumen, Russia
Posted: 12th Jan 2020 05:16 Edited at: 12th Jan 2020 05:24
You can write your image loader to control.

PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 17th Jan 2020 15:31
Actually, if you use the scene editor, you should use the 'paint tool' thing from the Scene Manager screen. Any sprite you have created in a scene will show up in that Scene Manager screen and any sprite you select there will allow you to 'paint' with the sprite in the scene many times over, WITHOUT the Scene editor creating a new image and loading it from the new image.

"In addition, because the *.scene file is managed by the editor, there seems to be no way to optimize its current behavior."

True, but you can run any code with the scene being loaded / active. There are plenty of things it doesn't support yet.

I would also like it if doing a _cleanup() and _setup() of a scene would come with the option to reuse the same IDs.
I use one of the scenes for the card battle system of my current game and 'turning it on / off' now results in AppGameKit recreating and reloading everything from scratch, with new IDs. I know I could just write my own _cleanup() code, which is fine. But depending on the amount of scenes, I'm not sure extremely high ID numbers would be such a desired side effect for any game running for hours and hours, constantly reloading.
3Dski
User Offline
Joined: 8th Jan 2020
Location:
Posted: 20th Jan 2020 17:33
Quote: "Any sprite you have created in a scene will show up in that Scene Manager screen and any sprite you select there will allow you to 'paint' with the sprite in the scene many times over, WITHOUT the Scene editor creating a new image and loading it from the new image."


In my test, I simply placed, two instances of the same sprite via the editor, and it did create a line of code to load the same image for each. If there is a different paint mode that behaves in a more efficient manner, the understanding of the consequences of which mode you're using would definitely be important, especially for a large scene!

I'm going to investigate the editor's behavior a bit more. Thanks!

3Dski
User Offline
Joined: 8th Jan 2020
Location:
Posted: 20th Jan 2020 18:14 Edited at: 20th Jan 2020 18:49
I see what the options are now. If you drag a single sprite into the scene you'll get code that looks like this...



Conversely, if you right-click on the sprite in the scene, there is an option to "Duplicate" the sprite, which keeps it from calling LoadImage() on the same sprite.

One elementary thing that's bugging me is, I can't seem to find an option like "snap to grid" so the sprites automatically align to the grid when placing them. Am I missing something here? Ah Ha... I found the settings in a very awkward location. I would have expected thw snap setting in a more handy location : (
PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 21st Jan 2020 17:10
Aside from using the right click duplicate, you can also use the Scene Manager to quickly 'paint with sprites', see attached image:



If you click on a sprite in that window, it becomes black. Then you can click anywhere in your scene and it will put a sprite there. The first image you use will have to be dragged into the scene first the way you did, so it will show up in the Scene Manager.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2020-02-26 07:06:40
Your offset time is: 2020-02-26 07:06:40