'sprite' dragging (made progress but have new problems)

cpc6128

Member
Licensed User
I was wondering whether someone who is better at basic4ppc than I could take a look at my code and tell me where I'm going wrong!

The attached project works on my desktop but has the following problems on my PPC:

a) the subroutine:

Sub hk_HardKeyPressed

Select hk.KeyPressed
Case hk.KeyEnter:
AppClose
End Select

End Sub

does not function as expected (i.e. to end the program). I am sure this is something very simple but I have the exact same subroutine in another program and it works fine!

b) The screen does not display properly on my PPC. This is probably due to the method I am using, which as is follows
1. in App_Start, I use formMain.DrawImage to draw a permanent background image onto the backlayer of formMain
2. then, every timer tick, I erase the entire forelayer of formMain and use formMain.fDrawImage to draw the appropriate icons onto it

The reason I want to draw the screen this way (rather than use Sprites) is so that the icons can be dragged around smoothly using the touch screen (currently they are constrained so they can only be dragged 2 hexes straight up). I realise that erasing and then re-drawing the entire forelayer every time is inefficient but that is something I can look at later.

Any ideas?
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
I'm still looking through your code, however the reason for the hardkeys not working is because you've overlooked creating a new instance in app_start.
Just add hk.new1("form1",true,true,true) and you'll be up and running again.
Will get back to you about the display problem when I suss out what happening.

Regards,
RandomCoder
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Attached is a modified code that will hopefully get you moving forward again.
It's not complete as I somewhat struggled to understand exaclty what was happening with the maths.
Basically I'm approaching the problem by storing the last x and y of the icon so that when it moves the previous position can be erased.
Some of your code is duplicated such as creating a new instance of drawer etc, you only need do this the once.
Hope this is enough to help you see a way forward.

Regards,
RandomCoder
 

cpc6128

Member
Licensed User
Thank you very much for having a look at my code!
It seems that the display problems on the PPC were caused by refreshing the entire form at every timer tick which was obviously more than it could handle. I will continue with the method you have implemented - it looks like a good solution. It is certainly more efficient and much less flickery.

There still seems to be an issue with the display on the PPC though - transparency. It works fine on the desktop, but what should be transparent shows up black on the PPC. Something to worry about later though perhaps. Thanks again for your help.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Yes I saw the problem last night but thought that there must be a way around it.
Anyway, I seem to recall this issue being raised before - and here it is.... http://www.b4x.com/forum/showthread.php?t=638&highlight=overlap
Hopefully this will solve your problem although it looks like it is a little convoluted.

Basically I think that the idea is to draw the image and store its position. Then redraw in a new position, repaint the background using the stored (last position values) and store the new position again etc.

I noticed that you were redrawing all three icons each time. Ideally you only want to redraw the items that have changed. This will significantly improve the speed of operation as only small changes will be being made each cycle.

Regards,
RandomCoder
 

cpc6128

Member
Licensed User
Success!

Thanks for that forum link, it was very helpful. It seems the key is not to use the forelayer at all but draw entirely on the backlayer.
I implemented another bitmap as a buffer (as you suggested) to keep track of what has to be redrawn under the icon that is moving. This works great.
The code needs a lot of cleaning up, and there are still some issues that need to be addressed (such as: still doesn't work properly on PPC), but I am well on my way now.

I have attached my code in case you want to see what I have done.
 

Attachments

  • space_mod2.sbp
    9 KB · Views: 215
Top