I use this sample code:
LOADSPRITE "Sprite.bmp", 0
DRAWSPRITE 0, 100, 100
how can I change color palette of a sprite without using polyvector?
is it possible?
Thanks
Only way to change that is with mem2sprite and sprite2mem I guess. Copy the sprite to an array, change the values and copy back to sprite. I guess it's possible with shaders too but I have no idea how to use those.
store in an array 500 sprite on iPhone to change its color palette, I think it's impossible!
no other solution?
How many sprites are we talking about?
If only a few, and you know the colours ahead of time (not dynamic), then creating separate sprite images is easiest.
Use one file for all the sprites, and use the 'LOADANIM()' command and 'DRAWANIM()' to draw the desired sprite.
Why don't you want to use POLYVECTORs?
If you are drawing many sprites, you could batch them and draw them all at once to get higher frame rates (even faster if they all belong to the same file), especially if you are targeting an iPhone.
But, with POLYVECTORs, you can only change one colour (well each corner of the sprite can have its own colour), so you are limited that way. Not flexible for multi-colour sprites.
[Edit]
Plus collision detection isn't automatic with POLYVECTORs!
If your sprites are square, you could leave the pixels you want coloured differently transparent.
Then before drawing the sprite, draw a rectangle area first of the desired colour behind the sprite.
Ha, so few circumstances where this would work, but its an option none the less!
polyvector are slow on iphone!
Ha really?
Damn, never tested mine on my iPhone yet!
My game is in 3D, only my font system / gui uses polys.
But even when poly-sprites are batched to only use one STARTPOLY / ENDPOLY pair, then use POLYNEWSTRIP for each sprite? Of course you need all your sprites in one file/texture to do this.
In Unity3D they refer to each time you change your texture as a draw call (or similar description, OpenGL is new to me!). And they recommended up to around a max of 30 draw calls for an iPhone game.
[Edit] - This could be a Unity3D specific limitation.
So, in GLBasic, do normal sprites batch automatically to one draw call in OpenGL somehow?
I can't see having 200 sprites (not batched) being faster than 200 poly-sprites that are batched to one draw call.
I guess what I'm asking is how does GLBasic render a sprite in OpenGL? And multiple sprites?
Slydog I wrote a routine to test polyvector sprite drawing speed on my 3rd gen iPod Touch. Without using POLYNEWSTRIP I could display 190 alpha-blended sprites on screen at 64x64 each. That's just over 5 times the entire screen area covered in 64 x 64 sprites without a dip from 60 FPS and I also included a full background image that these sprites were overlayed on. Upping the sprite size to 128 x 128 and scaling down so all sprites could be visible at once as a single grid I could display 100 of the 128 x 128 sprites without a dip from 60 FPS.
I haven't tried the above sorts of tests with POLYNEWSTRIP yet (which I'm going to do tonight) but so long as the iDevice in question is reasonably recent there is quite a bit of CPU/GPU to play with.
as a comparison to the power of the iPhone we can mention that GP2X (ages old handheld) can display 2400 animated sprites without dipping below 60 fps. And this without any polysprite tricks, just normal drawsprite. Ok, troll goes away now... :-)
That's pretty interesting, but how big are these sprites?
It was a while since I tried it but I think it was tested with both 16 and 32 pixel tiles. I also tried with gigant sprites (1024+) just for fun but that was only one sprite visible at a time... :-)
Quote from: Ragaril on 2010-Sep-17
I could display 190 alpha-blended sprites on screen at 64x64 each.
Well, that's encouraging! And maybe with the POLYNEWSTRIP thrown in, maybe we could get even more. I'm just a little worried if I need to display a screen with a lot of small text, that could start adding up fast. But it would only be for an instruction screen or something, so I wont be needing 60 FPS!
If you want to display lots of text, you draw the text to a new sprite and display that instead. Saves a lot of time.
Wow, great idea. One sprite MUST be faster than 200 poly-sprites!
How do I do that? Render it to the screen and use the GRABSPRITE() command?
If so, is GRABSPRITE() still limited to Portrait mode on the iPhone?
USESCREEN, don't ask me if it works on iPhone though since I have none :-)
USESCREEN works fine on iPhone. I used it for a background image in a test app.
"might" not work in landscape mode, yet. If it does, it will impact performance in landscape.