Dynamic positioning of sprites causing collision boundaries issues in iOS

I am creating a simple soccer ball game. The player flings the ball towards the goal. If the ball collides with the goal, the score goes up by 1. It works perfectly fine on Android. Problem arises when it is on iOS. Even if the ball does not touch the goal, the score increases by 1. After debugging, i found out that it has something to do with the goal's X position. Anything more than X=300, it will start detecting that it has hit the goal when the ball goes to the top of the screen. Anything less than 300, it behaves as it should. Now, ideally, I would not want to hardcode the X position of my goal as it would not be in the middle of the screen.

Can anyone shed any light on this issue? Here is what my screen and code looks like.

Welcome Jacqueline.

  • Most users here code for Android; a few for ios. While it is possible sometimes to debug by inspection of the Block code, that is nearly impossible for apps like this. Knowing your Project works on Android devices but not on ios is helpful.
  • You might get a better response if you post your Project aia . If an aia is available, someone can test the behavior on an ios. Otherwise someone has to reproduce your code without knowing what your goal sprite is (dimensions, etc.), what your Screen settings are and Properties of sprites and the balls etc. which could affect the behavior.
  • What ios device are you testing on?
  • If this behavior is a bug in the ios Companion, the developers have to have an example aia to test.

So please post your Project aia here (just drag the aia file from your PC into this message box). Thanks. Someone will test, confirm the behavior and either offer a solution or pass this on to the MIT developers to confirm and fix the bug. :slight_smile:

1 Like

Thank you for your reply, Steve. I will attach my aia file with this message. I am testing on an iPad Air running 12.5.4. My students who encountered this issue is also testing on iPad (not sure which version though). All my other android students, including myself, have no issues with this code.

SoccerBall.aia (118.4 KB)

Nice Project.

I don't have an ios. I suspect the following things could be causing the issue with ios:

  • The goal image the Project uses has a 1000 x 650 image. It is used only at 200 x 100 resolution in the app. The software has to shrink the image to 200 x 100. If the ios algorithm that does this, it could be the problem.

  • the goal image is not centered; there is more 'transparency' on the right side of the image than on the left. This means the center of the goal is not the center of the sprite. Is that an issue? I don't know.

  • both above might cause issues with the resetGoal ImageSprite_Goal.Width as you surmised.

The Ball will react to the entire sprite footprint, not only the non-transparent part.

Attached is a version of the app with a 'corrected image' . The aia might run on the ios device while the sample does not. SoccerBallModified.aia (241.6 KB)

Let us know if it works. If the revision does not, I'll bring this to the attention of the MIT developers.

Meanwhile, if you wait a bit, someone might try the original code on an ios device and let us know what they experience.

Good luck.

1 Like

Thank you for your suggestions. I will definitely try them out and keep you updated of the outcome. Yes, I took into account that there are some transparent "bits" at the end and the Ball would react if it hit that bit too. I tested with hitting the far left/right corners and making the goal size really small to make sure it would not hit the transparent bit, but yet it still triggered the collision. Hence, my last guess was it has something to do with the image. But I have not had time to change the image to prove my guess yet. Thank you for changing it for me and I will test it out on my iPad and keep you updated. Thanks again!

Do keep us posted on how your testing goes. If there continue to be issues we may need to assign someone at MIT to take a look at this.

Unfortunately it is still not working with SoccerBallModified.aia. Tested on my iPad Air running 12.5.4. Works fine on my Android phone.

I have also created a SoccerBallModified2.aia with just a simple grey rectangle (created with MS Paint) to see if it would make a difference, but I am getting the same results. The collision is still detected even if it hits the top of the screen. SoccerBallModified2.aia (241.9 KB)

Would appreciate it if someone from MIT could take a look at this. Thanks!

Unfortunately it is still detecting the collision of the ball and goal sprites even if the ball hits the top of the screen (no where close to the goal) on my iPad Air.

Would appreciate it if someone from MIT could take a look at it or shed some light on it. Thanks.

Ok, I have managed to make this work by moving the goal from Y=0 to Y=(0.1 x Canvas.Height).

Perhaps the image being at the top most boundary was causing issues on iOS. Setting it at Y=0 would mean half of the sprite image would be out of bounds. If I had wanted it to be right at the top, to be precise, I should have put it as Y=ImageSprite_Goal.Height/2. However, this still didint work when I set the Y=ImageSprite_Goal.Height/2.

Here are my different tests and results:

  1. Set ImageSprite_Goal's Y=0, didint work
  2. Set ImageSprite_Goal's Y=ImageSprite_Goal.Height/2, didint work
  3. Set ImageSprite_Goal's Y=Canvas.Height * 0.1, worked!
  4. Set ImageSprite_Goal's Y=(ImageSprite_Goal.Height/2) + 5, didint work
  5. Set ImageSprite_Goal's Y=(ImageSprite_Goal.Height/2) + 10, didint work
  6. Set ImageSprite_Goal's Y=(ImageSprite_Goal.Height/2) + 15, worked!

So I can only conclude that with iOS, it somehow needs some buffer space between the sprite and the edges. Note, I tried reversing the Ball and Goal. That is, put the Ball at the top of the screen and the Goal at the bottom, I had the same collision detection issues unless I put some buffer space between the ImageSprite and edge.

Hi @Jacqueline_Lim,

We'll take a look at this today to see what might be happening on iOS.

Edit: I've been able to confirm the issue on the latest version.
Edit2: I've narrowed down how this is happening, but it's not clear yet why it's happening.

1 Like

Thank you very much for looking into it. Do keep me updated as I am interested to know why it happens.

So I worked on this over the weekend and came up with a fix. I actually encountered a separate but related problem while fixing it--two bugs for the price of one.

The underlying issue is that the logic in the iOS version for the Move block separately updates the X and Y coordinates of the ball, respectively, but each property update also triggers the test for whether the ball is colliding with any other sprites. Since the X property is updated first, the ball is moved to the center of the canvas and is now inside the goal (recall Y will be 0 since the ball has hit the top edge of the canvas).

I adjusted the logic so that the Move block calls a separate internal setter for those properties that doesn't trigger the collision logic until after the fact.

As a workaround until the next iOS version goes out with this fix, you can create a global variable, e.g., doingReset, which you set to true at the top of the reset function and then set it to false again at the end. In the collision event handler, you will need to test whether the variable is false before running the rest of the code so that you're only scoring the goal if it isn't due to the reset.


Ah! Understood! That makes perfect sense as to why it is happening.

I will be using an internal setter to get around it for the time being. Thank you very much for checking it out!