UPDATE - Objects in B4a - No problem ;-) - O yes, and a simple 2D game engine ...
Hi,
thank you for everyone that tested (and found a few issues) - here is a new version with some fixes (added some more fixes, thanx to agraham for his help on speeding up the graphics, even more ;-).
The problem with the background not rendering completely at the bottom was because of a line of code in the main activity module.
The background image source rect that was specified was wrong - would work on some devices for some reason but not on others.
I had it as "gwcanvas1.BGImageRect.Initialize(sx, 0, sx + w, Activity.Height)" where it should have been
"gwcanvas1.BGImageRect.Initialize(sx, 0, sx + w, gwcanvas1.BGImage.Height)" - needed to specify image height, NOT activity height ;-)
The new demo app might run a bit slow on some devices (for instance HTC wildfire) but on most devices I tested it worked surprisingly good (especially the HTC Desire HD & SE XPeria X10)! I tested performance on quite a few (20+) sprites rendering all at the same time ...
Have fun and let me know if you can optimize / better anything I have done. Would be nice to have someone (me?) write an actual working game
using this ... any takers???
------------------------------------------
Hi,
I started wondering just how far we can push the language (B4A) before it breaks. So, I tried implementing something that will kind-of act like object orientated programming ...
So here goes...
- Basically I found that you can name a code module the same as a contained type in that code module - this leaves us with a lot of possibilities :icon_clap:
- If you now include another "base" type from another code module (MUST be declared before this code module) as one of the fields of your type, you can implement something that resembles inheritance
- Any subs included in your code module now looks and acts like static (class) functions
- Please have a look at the included source (GWCanvas, GWActor and GWSprite code modules - they MUST be included in this order, or else your code WILL NOT compile)
So, knowing that I created a simple 2D game engine that currently supports the following
- sprites (actors) - both static and animated (multi frame)
- rotation / resizing of sprites
- a static background color or ...
- a static / movable / re-sizable (see GWCanvas.BGImageRect field) background image (side-scrolling type of games maybe?)
- some simple collision detection
There are probably a LOT that we can do to add and optimize this - currently the included demo shows a simple background image (clouds) that scrolls from left to right and then bounces back while a few planes fly into each other and disintegrates. The whole process starts over when there are < 2 planes left ...
I tested this on a Sony Erriccson XPeria X10 and a Motorola Defy (MB525) and the performance on both seem acceptable (Currently I use a timer for the games loop - there must be a better way???).
Please play around with this and let me know what you guys think - use it / loose it ... whatever :sign0089:
Hi,
thank you for everyone that tested (and found a few issues) - here is a new version with some fixes (added some more fixes, thanx to agraham for his help on speeding up the graphics, even more ;-).
The problem with the background not rendering completely at the bottom was because of a line of code in the main activity module.
The background image source rect that was specified was wrong - would work on some devices for some reason but not on others.
I had it as "gwcanvas1.BGImageRect.Initialize(sx, 0, sx + w, Activity.Height)" where it should have been
"gwcanvas1.BGImageRect.Initialize(sx, 0, sx + w, gwcanvas1.BGImage.Height)" - needed to specify image height, NOT activity height ;-)
The new demo app might run a bit slow on some devices (for instance HTC wildfire) but on most devices I tested it worked surprisingly good (especially the HTC Desire HD & SE XPeria X10)! I tested performance on quite a few (20+) sprites rendering all at the same time ...
Have fun and let me know if you can optimize / better anything I have done. Would be nice to have someone (me?) write an actual working game
using this ... any takers???
------------------------------------------
Hi,
I started wondering just how far we can push the language (B4A) before it breaks. So, I tried implementing something that will kind-of act like object orientated programming ...
So here goes...
- Basically I found that you can name a code module the same as a contained type in that code module - this leaves us with a lot of possibilities :icon_clap:
- If you now include another "base" type from another code module (MUST be declared before this code module) as one of the fields of your type, you can implement something that resembles inheritance
- Any subs included in your code module now looks and acts like static (class) functions
- Please have a look at the included source (GWCanvas, GWActor and GWSprite code modules - they MUST be included in this order, or else your code WILL NOT compile)
So, knowing that I created a simple 2D game engine that currently supports the following
- sprites (actors) - both static and animated (multi frame)
- rotation / resizing of sprites
- a static background color or ...
- a static / movable / re-sizable (see GWCanvas.BGImageRect field) background image (side-scrolling type of games maybe?)
- some simple collision detection
There are probably a LOT that we can do to add and optimize this - currently the included demo shows a simple background image (clouds) that scrolls from left to right and then bounces back while a few planes fly into each other and disintegrates. The whole process starts over when there are < 2 planes left ...
I tested this on a Sony Erriccson XPeria X10 and a Motorola Defy (MB525) and the performance on both seem acceptable (Currently I use a timer for the games loop - there must be a better way???).
Please play around with this and let me know what you guys think - use it / loose it ... whatever :sign0089:
Attachments
Last edited: