Ooops
January 27, 2021, 07:45:34 AM

Author Topic: Create sprites beforehand or at runtime?  (Read 513 times)

Offline hosch

  • Jr. Member
  • **
  • Posts: 86
Create sprites beforehand or at runtime?
« on: July 08, 2020, 11:00:10 AM »
Hey guys,

I am messing around with AGK for a couple of weeks now and I really enjoy it. For my current 2D project, I've created all sprites beforehand, hid them and show them whenever neccessary. Are you doing it the same? Because, if you have a very large project this might be not the way to go. Since I didn't create a large project in AGK yet, I don't have any experience considering this topic. Does it make more sense to create them at runtime and delete them when not needed anymore (which means I'd have to create them every time)?

I've also seen some people defining a sprite custom type and handle them that way. How are you guys doing this? Thanks!

Offline Steve Elliott

  • Hero Member
  • *****
  • Posts: 2925
  • elgol 2021
Re: Create sprites beforehand or at runtime?
« Reply #1 on: July 08, 2020, 11:36:49 AM »
I've always hid them because the author said it produces faster code.  But it's a real pain and can lead to bugs. From now on I think I'll do what Qube does - by using DrawSprite and Swap() instead of Sync()
Windows 10 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
MacOS Big Sur 64-bit, 8Gb RAM, Intel i5 2.3 Ghz, Intel Iris Plus Graphics 640 1536 MB
Linux Mint 19.3 64-bit, 16Gb RAM, Intel i5 3.2 GHz, Nvidia GeForce GTX 1050 (2Gb)
Raspberry Pi 400, Pi4, BBC B, C64, ZX Spectrum

Offline hosch

  • Jr. Member
  • **
  • Posts: 86
Re: Create sprites beforehand or at runtime?
« Reply #2 on: July 08, 2020, 11:55:10 AM »
Yup, that's what I am experiencing as well. I see a sprite is still visible and have to go all over the code where I forgot to hide it.

Could you elaborate on Qube's method? From my understanding, I could create one sprite, then use SetSpritePosition() to put it where I need it, render it to the backbuffer with DrawSprite() and use Swap() to show it? This actually seems more straightforward to me coming from BlitzBasic, where I used loops to draw my tilemaps etc.

Offline blinkok

  • Sr. Member
  • ****
  • Posts: 280
Re: Create sprites beforehand or at runtime?
« Reply #3 on: July 08, 2020, 09:51:37 PM »
Remember that DrawSprite() means you cannot use the collision commands with that instance
If it's say, background tiles, a good idea might be to "burn" those tiles into a single image using GetImage() or RenderToScreen()

Offline 3DzForMe

  • Hero Member
  • *****
  • Posts: 1177
Re: Create sprites beforehand or at runtime?
« Reply #4 on: July 10, 2020, 07:43:00 PM »
This is interesting, as I've sprites littering my UI due to back of a fag packet coding, in fact, it's not even that. Straight from the old suede, probably explains a lot!

Offline hosch

  • Jr. Member
  • **
  • Posts: 86
Re: Create sprites beforehand or at runtime?
« Reply #5 on: July 11, 2020, 09:37:42 AM »
Remember that DrawSprite() means you cannot use the collision commands with that instance
If it's say, background tiles, a good idea might be to "burn" those tiles into a single image using GetImage() or RenderToScreen()
That's some good advice, I didn't know that!

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal