Share My Creation Objects in B4a - No problem ;-) - O yes, and a simple 2D game engine ...

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 :cool:
- 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

  • Sopwith.jpg
    Sopwith.jpg
    20.5 KB · Views: 9,613
  • SopwithDemo.zip
    272.7 KB · Views: 1,263
Last edited:

ssg

Well-Known Member
Licensed User
lol... the ideas are starting to trickle in!

I'll announce my projects once i get them completed :D

and yes.. the render speed is way smoother now!

excellent work! and thanks for sharing!!
 

francoisg

Active Member
Licensed User
Thank you!
Glad someone else might find a use for it - and about the sharing ... hel, I need SOME way of enjoying my work, so I need to play every now and then as well ;-)

When I started programming (many years back) it was ALL fun - now it's a job!

Anyway, back to work I guess ....
 

ssg

Well-Known Member
Licensed User
A couple of fixes for the code:

1 - Dim tmr As Timer should be in process_globals, currently you hit an error if u exit the game and start it again.

2 - your other variables will need to be reset again, so i'd change the activity_start to the following:

B4X:
   Activity.LoadLayout("layout_main")
   
   Activity.AddMenuItem("Exit", "mnuExit")
   Activity.AddMenuItem("Reset", "mnuReset")
   Activity.AddMenuItem("Change Background", "mnuChangeBackground")

   gwcanvas1 = GWCanvas.Create(Activity)
   LoadBackground      
   LoadSprites
   If FirstTime Then
      tmr.Initialize("tmr", 10)
      tmr.Enabled = True      
   End If

Do highlight if i've done something not quite right above... cheers!
 

francoisg

Active Member
Licensed User
150 sprites, all at the same time, and it actually works? better than I expected ;-)
I have updated the example code with some changes (as well as the suggested changes by ssg) ... the planes will now "explode" instead of just disappearing, shows of the "animation" capabilities of sprites as well...
 

Attachments

  • SopwithDemo.zip
    270.5 KB · Views: 446

magarcan

Active Member
Licensed User
Any updates?? I'm looking for any game dev library and this is the only I've found. After reading about this, it seems to be really powerful. I'll test this at home.

Thanks!!
 

Kamac

Active Member
Licensed User
Unless you need 2d physics or just 3d features, then it's the best just to write your own small engine, during game creation :)

If you want a 3d 'engine' then it's avaible at OpenGL ES topic which contains the library itself. There are samples posted by Jim Brown and someone else, and they do great as small engines! (I've used one myself for 3d)
 

magarcan

Active Member
Licensed User
Unless you need 2d physics or just 3d features, then it's the best just to write your own small engine, during game creation :)

If you want a 3d 'engine' then it's avaible at OpenGL ES topic which contains the library itself. There are samples posted by Jim Brown and someone else, and they do great as small engines! (I've used one myself for 3d)
By now, I only want to play with 2D. In that case, do you know where can I find some info in order to begin develop my own engine???
Thanks!!!
 

DoogieDog

Member
Licensed User
Cannot run Sopwith demo with trial edition ?

I'm thinking of buying B4A for game making and worried about having alot of sprites animate correctly. I found this great demo, but cannot run with the trial version. This is the compile error.

Error parsing program.
Error description: Unknown type: gwcanvas
Are you missing a library reference?

Am I correct that the trial version does not support libraries, or have I set up the project incorrectly?

DD
 

francoisg

Active Member
Licensed User
No additional libraries are needed for the demo (all the code is included in the download) - should work fine with the demo version of B4A ...
The GWCanvas type that it is complaining about should be located in the GWCanvas module. The module file should be in the same directory as the rest of the project.

I see there is a bit of a problem in the demo when used on higher res (960 x 540 for example) devices (background & ground issues) - will post a fix as soon as possible ...
 

DoogieDog

Member
Licensed User
Startup Error when opening Sopwith.b4a the first time

This is the error I get , then a subsequent buy me screen

This project includes multiple code modules. This feature is not supported by the trial version

Darn it!

DD

BTW - Awesome software so far!
 

francoisg

Active Member
Licensed User
ok,
that makes sense ;-)

Sorry, then I guess I can't help you:sign0148:

I'd say, bite the bullet and buy the cheapest version you can. Should let you experiment enough to be sure if it will work for you or not???

BTW: There is a new version available for download now, with the resolution bug fixed ...
 
Last edited:
Top