Android Question Drawing on co-incident panels problem

noclass1980

Active Member
Licensed User
Longtime User
Hi,
I have two panels (Panel1 and Panel2) with their respective canvases. They lie on top of each other. I can set the background of Panel2 with a graphic and then draw on the Panel1 canvas and change it using Panel1.Invalidate and the image on Panel2 remains in view at all times.
However, if instead, I remove the Panel2 image and call a subroutine to draw a shape and then show the shape using DrawPath on Panel2 canvas, all I get is the drawn shape on a white background and Panel1 cannot be seen at all. I know the graphics on Panel1 and Panel2 are being drawn correctly because, if I reduce the size of Panel2, then I can see Panel1 behind it. I’ve tried setting the Panel1 to transparent but it didn’t work. Should I use an imageview instead of Panel2?
Can anyone suggest why this is happening and offer a solution? Thanks in advance
 

eps

Expert
Licensed User
Longtime User
Do you not need to make the one you don't want to draw on not visible? Just because it is behind the other one it doesn't necessarily mean it's not active.

You get a similar experience if there are buttons on two panels, it is possible to click something even though you can't see it. The device knows that it is there and passes the click event through to it.

But I agree with klaus, it is a little hard to follow what you are trying to achieve, what you are experiencing and which panel is on top of which panel. I think Panel 2 is on top of (wholly?) Panel 1.
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
All I want to do is have a background shape drawn by DrawPath on one panel (Panel2) which doesn't change at all. In front of this panel is another panel (Panel1) which has animations etc and is routinely Invalidated to redraw. I want to see Panel2 through Panel1 at all times. I don 't understand why there is a difference if Panel2 has a graphic png which works and shows the changes on Panel1 correctly but if I draw a shape on Panel2 it doesn't work. I'll post a project tomorrow to show the problem but any suggestions welcome. Thanks
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Without seeing your code any concrete help is impossible !
In your first post you didn't speek about animation which appears in post #4 !?
Did you have a look at chapter 15.2.3 Simple draw functions in the Beginner's Guide ?
 
Reactions: eps
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
I’ve uploaded the programme. It is based on AB’s ABPhysicsEngine Game 2 so there is a lot of redundant coding. I’ve written this to understand the physics engine. The important lines are 63 and 68. If 63 is uncommented (and 68 is commented) then the graphic “shape.png” is displayed in Panel2. Conversely, if 63 is commented (and 68 is uncommented) then the sub routine Drawshape is called and displayed in Panel2. Here is the problem: if the graphic is used, it displays on top of Panel1 and Panel1 contents can be seen. If the Drawshape routine is used then Panel2 shows the shape with a white background and Panel1 cannot be seen. I’ve made Panel2 smaller so that Panel1 can be seen but ultimately I want Panel1 and Panel2 to be the same size. Thanks for any suggestions.
 

Attachments

  • ABTest.zip
    13.2 KB · Views: 147
Upvote 0

klaus

Expert
Licensed User
Longtime User
Unfortunately we cannot test your program because there are images missing !?
Did you test the project before posting it ?

Looking at your code I understand following:
- If you uncomment line 63 and comment line 68 you will see the image on Panel2
- If you comment line 63 and uncomment line 68 you will see the shape on a white background on Panel2, because the color you defined in the Designer is white.

I don't understand what exactly you want to do.
Do you want to draw the shape on Panel2 or on Panel1 ?
Is Panel1 on top of Panel2 ?
Do you want to have on Panel2 a background image and on Panel1 a shape or something else shown on top of the background ?
If yes you should draw this on the transparent Panel1.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
I think he wants a background image and then to animate sprites or images on the foreground panel..
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Apologies, I've added the files. The code was tested as described before uploading. What I want to do is
1. Draw a shape using the sub routine on Panel2 which is behind Panel1.
2. Draw sprites etc on Panel1 which is regularly updated
3. The shape on Panel2 does not change at all.
I realise that I could draw the shape on Panel1 but, I'm trying it this way so that I don't need to redraw the static shape everytime Panel1 is redrawn.
I am confused why using a graphic file doesn't give the white background which happens if I use the drawshape sub routine.

Doh!
It would be better if I actually read your replies properly! The problem is the colour of panel2 so I've set it to Transparent and will test it later. Thanks for being patient!
Update
Ok, setting the transarancy of Panel1 and Panel2 works but with Panel2 on top of Panel1. If I send Panel2 to the back (at line 68), the drawn line disappears. How do I get Panel1 on top of Panel 2 and still see the drawn line?
 

Attachments

  • abtest.zip
    31.5 KB · Views: 126
Last edited:
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Finally found the solution. I spotted that there is a rectangle drawn in line 168 of the updated file in reply#10 whose colour is black. So when Panel2 goes backwards it is obscured by the black rectangle. Now it can be seen underneath Panel1.
Thank you both for the conversation, I've learnt a little bit more about this marvellous B4A!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…