Game: Tower Defense - Questions

Robto

Member
Licensed User
Longtime User
Hi all,
For learning purposes, I want to setup a Tower Defense B4A project and I'm seeking some help/examples to get me started. I've read the beginner guide and user guide thoroughly but I'm still puzzled by some concepts. I have a lot of questions so bare with me! :)

canvas: you use a canvas to draw on views correct? So for a test world/map I could create a panel and draw a canvas on that panel and have the background of that canvas filled by a color or bitmap correct? And If I wanted to create a path via walls I should start by placing the walls via a couple of canvas objects and place them on the panel (or imageview) as walls. Is that a smart way to go forward? Not sure as the bricks in the 'arkanoid' game doesn't seem to have canvasses declared for them.

What are the differences between an imageview and a panel for that matter? And when should I use which?

Next step is to create a movable object (the attacker) which moves in the shortest path possible to the target. By having collision detection in place the attacker walks into the walls, the attacker rotates a predetermined degree untill it can move forward again when there is no wall blocking.

Is this the correct way to start? Should I use gameview? Or some other library? Right now I started with gameview.

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   Dim pnlColor As Panel
   Dim wall, attacker As BitmapData
   Dim size As Int
   size = 30dip
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   
   If FirstTime Then
      'Create the BitmapData objects.
      'These objects will be drawn by the GameView
      wall.Bitmap = LoadBitmap(File.DirAssets, "wall.png")
      wall.DestRect.Initialize(10dip, 10dip, 100dip + size, 100dip + size)
      'neerzetten van rode panel
      pnlColor.Initialize("")
      Activity.AddView(pnlColor, 10%x, 40dip, 80%x, 60%y)
      Dim cdwColor As ColorDrawable
      cdwColor.Initialize(Colors.Red, 5dip)
      pnlColor.Background = cdwColor
      End If
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
For an intense game like Tower Defence, canvases, imageviews and panels will not give you enough performance for a playable framerate.
You should use either Erel's GameView or OpenGL.
You will need to implement many algorithms like path finding, path following, bullets/particles and ofcourse sprites/objects and collision detection.
Quite frankly its not the ideal learning project...its a full blown game.
 
Upvote 0

latch

Active Member
Licensed User
Longtime User
What thedesolatesoul says is true. My game FlaTank uses only the canvas for drawing and it lags when you get a level that has more than 18 enemies and never recovers unless you restart the app. Then performance is good again.

I converted it to a Blackberry app and the performance was horrid So I started learning open gl for it. When I did a few changes into open gl I saw that was not going to fix it on the BlackBerry so I did a few tricks to improve performance for that platform. My point in saying all of that is that I wish I would have written it differently(and with opengl) from the start. Doing it now is like putting a band-aid on an amputation.

I don't think FlaTank is much less complicated than a tower defense but it has a lot less moving objects to track.

Incidentally, Robo Defense is my very favorite game on android and it is so well written, it runs nicely even on a POS tablet with a resistive screen I bought for $30 from China.

I would start with something simpler also... unless you dream in code.
 
Upvote 0

WAZUMBi

Well-Known Member
Licensed User
Longtime User
I decided to play around with gameview and made a simple game called
Space Arena

It also uses mutlitouch and there are a few hundred sprites moving at any giving time with collision detection.

I did it first without using gameview it was impossibly slow. With gameview it is much smoother however it seems to depend on the device.

It works fine on my Galaxy 10.1, Lg L45C and a few other test devices but on my Samsung Infuse it starts out really choppy and sluggish.

Anyway gameview is rather strait forward and easy to implement in my opinion. I think you will get better performance with OpenGL but there is more of a learning curve to get started.

By the way I got a little side tracked with my Space Arena game and plan to get back to it later and add more levels and modes of play if anyone's interested.
 
Upvote 0
Top