BASIC

Author Topic: Mask for background animations and transparencies  (Read 14726 times)

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4174
    • View Profile
    • Portfolio
Hi everyone.

While coding this one game, I finally came into slowdowns on more simple platforms.
All my fault of course as I simply ditched code till it could not handle anymore and frames dropped.

Now I´m looking into speeding things up and trying to understand how can I achieve the same without much trouble.

So, in this game, I have clouds moving on the background, the middleground, I´m pasting a huge sprite every cicle to cover those.

Game has no transparencies so smoothshade is off.
Is there a better/faster way to create this mask?

On another note, is there any performance issues (considering a caanoo) when I use png 32 bits instead of the purple sprite method?

Thanks for any help on that.
« Last Edit: 2013-Feb-09 by erico »

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: Mask for background animations
« Reply #1 on: 2013-Feb-07 »
If the slowdown is due to lots of rendering 2D textures, are you using Polyvector? If so, have you put all your sprites into as few sprite sheets as possible?

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4174
    • View Profile
    • Portfolio
Re: Mask for background animations
« Reply #2 on: 2013-Feb-07 »
No polyvectors, just standard sprite commands.

I best illustrate the case, the TOO BIG SPRITE goes over the background so to cover the clouds.
Is there a way I can use a mask over the background clouds or something similar and less taxing?

Also, I´m drawing the hearts and hud stuff every frame, not needed, can I simply paste a sprite on the background and avoid that too?

[attachment deleted by admin]
« Last Edit: 2013-Feb-07 by erico »

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: Mask for background animations
« Reply #3 on: 2013-Feb-07 »
I can't be sure but from what I can see of the specs the Caanoo should be able to take a lot more than that without slowing up. You shouldn't need a mask. Hmm.

If you are calling Drawsprite many times you could speed things up by converting the sprite commands to polyvector commands. I can help you do that if you like.

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4174
    • View Profile
    • Portfolio
Re: Mask for background animations
« Reply #4 on: 2013-Feb-07 »
Thanks Wampus! Really welcome!

The caanoo can sure handle a lot more then that, it is just that I went on bashing flat coding without ever thinking on optimization issues or anything else. and there is also a lot going over that image not into this example.

Part of the plan was to see when the little caanoo would not handle anymore of my slopy code and exactly where I would have to take care next time I code something I´d wish to also run on it.

Pc version goes fine, altough sometimes I get black flashes when the rain kicks in, but that is probably my cheap scalling routine :-[

Last year I did a code-test to check performance on caanoo considering sprite/polyvector commands.
At that GLB version, I got the best fps when using SPRITE commands.
kitty also stated that the caanoo is best optimized for those.
Here the thread:
http://www.glbasic.com/forum/index.php?topic=7197.msg59212#msg59212

Thing is, the game is just about done, missing very few features and sound/music, front end and end sequences.

I think if I can´t find a solution, it is best maybe to reduce the clouds area so to reduce the sprite pasted and maybe giggle a bit the other huge sprite goings.

I really appreciate  your offer though, thanks a million! :good:


Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: Mask for background animations
« Reply #5 on: 2013-Feb-07 »
Ah ok. Sprite commands are optimized for Caanoo. Sorry for distracting you with that. I don't own such a device and I guess its faster for CPU rather than hardware render in 2D. And ok, so maybe the Cannoo can't take *too* much. I read the thread you linked to and I've also been reading this: http://caanoo-code.blogspot.ca/2011/12/2d-drawing-performance.html. I can see why you might be considering using a mask. That is...a bit tricky.

Fixing the refresh rate to 30 FPS, separating background into layers that include the clouds a bit like this and seeing if making sure you're saving your sprites as RGB888 makes a difference are the only suggestions I can think of. Using a mask could be done but I've never done this.

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4174
    • View Profile
    • Portfolio
Re: Mask for background animations
« Reply #6 on: 2013-Feb-07 »
No need to be sorry, I suspect polyvectors could gain some here, but on my tests, I could not make it run properly on caanoo, but then again, was an older version of GLB and I never used them in first place, altough my tests worked on pc as it should.

Thanks for the link! A bit too advanced for me, but it is great read, I do have to learn more on these. :good:

The backround clouds are composed of those 3 clouds that move with distinct speed.
I can get them smaller too as there will probably be some background and that will make it easier on the handheld.

Since things has been 60fps from the beguinning and it is an action game, I will cry(truly) if I have to lower that... :-[

I will try the rgb888 (that is no alpha channel right? using a color as mask, usually that purple/pink right?).

I´m not sure about a mask either, maybe I could draw the clouds on a different off screen and delete the part, but grabbing it back and pasting on the former screen sounds as an even more taxing thing...at least in my mind :(

Clouds are there to show the wind/storm movement and they change speed every other time.
Thanks for all the hints, let me see if the png24bit+pink/purple handles better then the png32bit.
Super thanks :good:

EDIT: oh, you mean rbg888 as 8bits per channel right? no alpha..
« Last Edit: 2013-Feb-07 by erico »

Offline Wampus

  • Prof. Inline
  • *****
  • Posts: 1004
    • View Profile
Re: Mask for background animations
« Reply #7 on: 2013-Feb-07 »
No alpha. Correct. I don't know what it would do but its worth a try. Why not try RGB565 too because that is often *very well* optimised for lower end hardware. It may make a significant difference or none at all.

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4174
    • View Profile
    • Portfolio
Re: Mask for background animations
« Reply #8 on: 2013-Feb-07 »
It did  :O :O :O

I could not use PNGs though, so I converted some of the heavier GFX to BMP rgb888.
Now things are all going around the 60fps again :O

Oh my :) :'( I think I can increase the number of sprites on the rain and add so much more special effects! :happy:
...and I only converted the bigger sprites!

I´m incredibly happy now, you can´t tell! :)

I didn´t know such could be a difference, I thought things were converted to the same inside GLB but had no idea about how the alpha would be handled, specially on lower handhelds!

Gee, super ultra 7 hardcore special thank you!!

I will try the RGB565 too.

I think I have a few beers over the fridge, will do a little celebration! :booze:
Awesome!

ps: the game is to sport many endings, you just made yourself into one now... I hope this thread helps other caanoo users on the issue too! :good:

EDIT: on another front, the black flashing square I was getting during rain on PC also disappeared. But I also got my smoothshading to false and alphamode to 0. yeeeahhhh :good:

EDIT2: heck, not quite gone the blinking, but waaay reduced, will check the scalling later :good:


« Last Edit: 2013-Feb-07 by erico »

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4142
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Mask for background animations
« Reply #9 on: 2013-Feb-07 »
The Caanoo is pretty good with sprites, but rubbish with Polyvectors (I'm having a nightmare trying to get the dark sections in AquaVenture running at any decent speed - they're great on pc, good enough on the Pandora, but Caanoo? No way).

What you are doing should be no bother for the Caanoo - My "Shadow Of The Beast" demo runs with 11 parallax layers and huge tree sprites and full character control at 60FPS on the GP2X and Wiz - what you were asking shouldn't have any problems at all. Glad you got it sorted in the end though :)

I can't wait to see this game in action - you seem to have been working on it for a while, constantly teasing us with those lovely images :)
I came. I saw. I played.

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4174
    • View Profile
    • Portfolio
Re: Mask for background animations
« Reply #10 on: 2013-Feb-07 »
Thanks Ian.

The huge sprites are fine, the real problem is my coding.
I´m not instructed on doing so properly.

I learned BASIC on a coco 2 from the manual, an then advanced to AMOS, I never researched coding techniks nor anything related to how I should do it.
The AMOS factory community helped me a lot on this front.
I always took the approach of achieving the things no matter what, and always relied on the power of the language.
Many times I had to downgrade some ideas for performance because I just didn´t knew better.

It is one thing I love in GLB, I can just get things done, computers are so powerfull nowadays.

Still, I have to improve my coding abilities, in this case, I´m doing collisions on variables, not even using the collision commands ;/
Everything is drawn and checked all the time, I´m wasting A LOT of the caanoos power on that.
I do hope to use it as a way of learning to better code.

GLB is great and this community rocks, I can´t state that enough. <3

EDIT:what dark sections?? :O Don´t tell me please...

« Last Edit: 2013-Feb-07 by erico »

Offline mentalthink

  • Prof. Inline
  • *****
  • Posts: 3356
  • Integrated Brain
    • View Profile
Re: Mask for background animations
« Reply #11 on: 2013-Feb-07 »
Hi Erico the graphics are very nice... this it's pixel art, or it's LW whit some filter... very very nice!!!

Whats it's bmp 888, bmp can contain transparency?¿...  :blink: :blink: If it's true, I'm a bit Donkey... 4 years using GLbasic and now I know this...  :nw:

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4142
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Mask for background animations
« Reply #12 on: 2013-Feb-07 »
Quote
EDIT:what dark sections?? :O Don´t tell me please...
Unless I can pull a rabbit out of a hat, you won't be seeing them on the Caanoo I'm afraid :(

They don't look particularly good in static screenies so I attached a small (jerky) video. Don't watch if you don't want to ;) :P

[attachment deleted by admin]
I came. I saw. I played.

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4174
    • View Profile
    • Portfolio
Re: Mask for background animations
« Reply #13 on: 2013-Feb-07 »
Hi Erico the graphics are very nice... this it's pixel art, or it's LW whit some filter... very very nice!!!
Whats it's bmp 888, bmp can contain transparency?¿...  :blink: :blink: If it's true, I'm a bit Donkey... 4 years using GLbasic and now I know this...  :nw:

Pixel art. I did cheat a bit by using some hand draw and photo references, still those are not the final, but are close.
I can´t lightwave small sprites, it has to be hand done. :(

Like those on Ian Price game (which are really awesome).
He is getting pretty good at that!

The 888 I guess refers to the bits per channel, ye 8 bits for red, 8 for green , etc.
On photoshop, when saving BMP, there is an advanced button, there you can state the type.
But even if I use 32 bit to save, when loading I can´t see the alpha, altough the channel is there in full black.
I never knew BMP could handle 32 bit either.

On the BMP888 type, the transparency will be that pink color 255,0,128.
It is just a mask, no antialiase or degrees of transparencies.

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4174
    • View Profile
    • Portfolio
Re: Mask for background animations
« Reply #14 on: 2013-Feb-07 »
Quote
EDIT:what dark sections?? :O Don´t tell me please...
Unless I can pull a rabbit out of a hat, you won't be seeing them on the Caanoo I'm afraid :(
They don't look particularly good in static screenies so I attached a small (jerky) video. Don't watch if you don't want to ;) :P

..as if I have the choice not to see it :rant:
At least it is not spoiling the puzzle hehe :good:

Now let me see if I get it.
The idea is that each thing that produces a light, has a filled circle over it and that is the only seen part of the stage?

Seems simple at first, and such must be able to be done as I want similar on my ´living dead rogue´ game.
First thought would be to use some offscreen buffer, but I´m not sure how fast they move on caanoo, but they seem fast on PC.
Something like:

-draw the game on an off screen 1.
-create another off screen 2 in black.
-draw a pink (to be transparent) circle over the objects that produce light on this screen 2.
-grab screen 2 and paste over scree 1
-show the result.

In this way of thinking (which you probably thought of it too), lots of off screen things going, I´m not sure if the caanoo can handle such.

I will see if I can think of any other way. It must be possible!