I’ve made a lot of progress however one of the simplest things has still got me stuck. I can’t seem to scale a sprite like below with setSize(). VScode tells me it wants
I think you found an oversight in the bindings. setSize signature is supposed to be setSize(this: LCDSprite, width: float, height: float), so that will be fixed in the next version!
The difference between the two types is that LCDSprite is the object that represents an individual sprite, PlaydateSprite is instead an SDK global object that provides essential functions related to sprites (such as creating a new sprite) but not bound to a single sprite in particular.
Another thing: setSize on a sprite doesn't scale it, to do that in the C/Nim API I suspect you should use LCDBitmap's drawScaled and use setDrawFunction on a sprite to use it as the sprite drawing method.
No worries I'll stay away from scaling for the moment.
Sorry to be a pest but another issue that I can't solve is after I compile for playdate simulator I get the following error. It all seems to work but the error worries me.
15:23:37: SDK: C:\PlaydateSDK
15:23:37: Release: 2.2.0
15:23:37: CMD: playdate.pdx
pdx directory not found: playdate.pdx
15:23:37: Loading: E:\playdate\Games_nim\test_05_Player_sprite\test_05_Player_sprite.pdx
Loading C API game: E:/playdate/Games_nim/test_05_Player_sprite/test_05_Player_sprite.pdx/pdex.dll
pc_sprite_free: non-NULL value required for argument 's'
15:23:37: Loading: OK
It seems to only happen when I use this code that is imported to create the player:
type
Player* = LCDSprite
proc initPlayer*(xPos: float, yPos: float, image: LCDBitmap): Player =
result = new(Player)
result = playdate.sprite.newSprite()
result.setImage(image, kBitmapUnflipped)
result.moveTo(xPos, yPos)
result.add()
Also the pdx directory not found has been like that from day one but I just ignore it and load the file manually in the playdate simulator.
Initializing a LCDSprite this way is not supported, then you deallocate it (warning here, because result didn't have a valid handle to a LCDSprite) to replace it with a valid playdate.sprite.newSprite().
This error: pdx directory not found: playdate.pdx
I'm not sure what's causing it without the project at hand.
Are we able to extend the sprite class like in lua? Or is it better to create a object that tracks all the info then gets the sprite to read that info at another point.
Regarding directly subclassing LCDSprite or similar, for now it's not completely supported, you could hack something like your attempt above (that works but is not an intended way to to it) but I guess it is going to be supported sometime soon.
I haven't tried a build for device until now and I'm getting the below error any clues on how I fix this. I've seen similar errors in discord but it's not clear to me how to fix the problem.
Error: invocation of external compiler program failed. The system cannot find the file specified.
Additional info: Requested command not found: 'arm-none-eabi-gcc.exe -c ...
Thanks Nino that got me on the right track. I've solved the problem. It seems on windows 11 the gcc files didn't get installed correctly. This is how I got it working if anyone else has issues with the gcc files not found:
-reinstall MSYS2 from https://www.msys2.org/
-run/open MSYS2
-in the command line type:
pacman -S mingw-w64-ucrt-x86_64-gcc
-in the command line type:
pacman -S mingw-w64-x86_64-arm-none-eabi-gcc
-in the command line type:
pacman -S mingw-w64-clang-x86_64-arm-none-eabi-gcc
-in the command line type:
pacman -S mingw-w64-ucrt-x86_64-arm-none-eabi-gcc
This might be overkill to install all the package but it saved me stuffing around. Building in VS code with the "nimble -device" now works with no errors and builds superfast.
I'm still using nim just haven't had much time lately. Here is a silly experiment I did to compare lua vs nim and well nim rocks! No sprites were used.
That's correct Daeke no sprites were used. Probably not the best for battery life as it's a full screen redraw. I haven't figured out how to redraw dirty areas for bitmaps and geometry like they do with sprites just yet, though in this case it probably would make much difference.
Yeah, all lines are probably changing every frame indeed.
Note that your comparison might actually be selling Nim short, considering it's being limited by the system's 50 fps. You could also post the cpu usage for a clearer picture
Why dirty rows? I have almost no experience with this stuff, but the one time I worked with HTML Canvas doing pixel level rendering, marking for redraw was done in rectangular regions.
Edit: I'm guessing it's just less overhead/simpler to treat the problem as 1D since you don't have to track overlapping regions and is closer to how fundamentally the image is drawn in general.
Would it be possible to switch it to draw by column? Given the screen dimensions statistically you are more likely to run more efficiently that way (I mean, still not much to be gained from this example as there's like maybe 5-8% of vertical drawlines being untouched, but you get what I mean)