Microsoft MakeCode

Strange recent behavior with setPosition method?

Hello -
This evening I came back to play a game I had posted earlier this year, Tiny Soccer Cars. I immediately noticed that some of the items on game play screen are no longer positioned as they were when the game was first published. On closer inspection I see the ball, scores, clock and boost meters in are shifted 1 pixel up and 1 pixel to the left. I’m assuming this change might also have something to do with why the ball no longer gains height when hit from below. The gitHub version of the game still looks and plays as intended and, for reference, can be found below the game description in the page linked above.

Items out of place:
image

All of the items that are out of place are positioned using the setPosition method. I thought I may be able to simply update my code to adjust for the offset; however, I also noticed that when the boost meters are scrolled off the edge of the screen, their positions change. :astonished: This is most easily seen in practice mode when the car is driven toward the goal on the right of the screen and the ball remains in the kick-off position:
image

I’m guessing this might be a bug, but if not please let me know if any of you have seen this and if there is a work-around or intended behavior I’m missing.

Thanks!
-theCobolKid

3 Likes

That’s amazing game!!!
When using the github version there are a few bugs though.
Sometimes the car direction get stuck…

Thanks Jabberwock! Yeah, the stuck direction a known bug in the game when using a keyboard. I think I tried to address it at some point but just left it since I’d never see it when using a joystick. The car direction gets stuck when pressing the right arrow key two or more times while the left arrow key is held down (happens with any opposing arrow key directions). I’ve seen this in other games, too, but only with a single press of the opposing direction, so I think I did something in attempt to keep that from happening.

This is a great game. Also, I love the handle ‘theCobolKid’. I guess I am getting to be considered an old dinosaur. I started out programming in COBOL.

I’ve pared down my game to more clearly show the problem. My main concern is that gameplay has been affected (the ball is no longer hit up into the air) and it appears I don’t have a work-around. I’m not sure the bug reported below is related to the ball height problem or not, but this is what I’ve noticed.

To help see the problem, the player 1-4 scores are used to display positions of items on the screen.
Upper Left - Camera X Center * 1000 (*1000 is to see digits beyond the decimal)
Lower Left - Car X Position * 1000 (*1000 is to see digits beyond the decimal)
Upper Right - Boost Meter X Position
Lower Right - Arrow X Position (pointing Boost Meter border)

Steps to Reproduce/Observe:

  1. Start Game (Tiny Soccer Cars - Position Bug)
  2. Notice the Arrow is in line with the right border of the Boost Meters
  3. Note the Boost Meter and Arrow X positions (79 and 94, respectively)
  4. Drive the car to the right so the cars position (Lower Left Meter) is greater than 204500
  5. Notice that the the Arrow has shifted 1 pixel to the right even though the Boost Meter and Arrow positions are still the same as seen in step 3.

Expected Result: Boost Meter and Arrow remain in same positions relative to each other regardless of camera placement

Actual Result: Boost Meter shifts 1 pixel to the right when Boost Meter image touches the Left border of the screen.

Note: Another game in the Arcade seems to be affected similarly is Jet-Pack Jenny. The control of Jenny’s altitude is very erratic, much different than what I remember and different than the preview movie for the game.

1 Like

Thanks for brining this to our attention and the thorough reproduction!
I filed an issue: https://github.com/microsoft/pxt-arcade/issues/3032
I’ll report back with an ETA once we have one.

2 Likes

@theCobolKid Does this play right to you / anything stand out as wrong? (I would suggest opening in a private browsing window as this one’s a test build of the editor) https://arcade.makecode.com/app/0610dda95754bed7e6df6ce7485f7d128dd0f4ea-1375337f35#pub:_YCAEPpYjk5mt

If that looks good, I put up https://github.com/theCobolKid/tinysoccercars/pull/1 which should fix the issues if you merge it in (besides one old rendering edge case that is currently messing up the scoreboard, which will be fixed with the next bug fix / patch release soonish: https://github.com/microsoft/pxt-common-packages/pull/1227)

The main issue is from the prior release - there were a few bugs around fractional values in sprite positions that got fixed, which broke some assumptions made in this game --previously, x/y were tracked internally as being able to have decimal places but when read would come out as integer values / get truncated. The game also hit another issue with odd-dimensioned sprites being misaligned due to a similar issue (halving the width/height was getting truncated when odd, as it was effectively flooring width / height divided by 2).

The main things that broke from this would be when there was logic assuming that x/y would always be integers, which is often pretty subtle – you can check the PR to see cases where I truncated the value with | 0 or |= 0 to get an idea of where things were getting offset. The other fixes were just offsetting positions by 1 when placing odd-sized sprites that were previously getting slightly misplaced

(@darzu tagging for the update)

2 Likes

@jwunderl, thank you so much for looking into this and for providing updates to my code. The ball gaining elevation when hit is fixed and it appears the scoreboard problem is fixed too (maybe that update has already been pushed). This is great to see and I really appreciate you taking the time to help.

The github version plays fine so I don’t think I’ll merge the changes there; I’d like to keep it “as is” for reference. But I will definitely update the game on this site.

There are a few things that are not quite right in the link you shared, but I think I’m able to fix them. These are:

  1. The ball does not bounce when it hits the ground, fixed by not truncating ballZStats.vy and ballZStats.y (z velocity and z position of the ball) in the letBallBounce function. I see that you added these lines as a fix for the ball constantly bouncing. I was able to make modifications to allow the ball to bounce when it hits the ground but keep it from bouncing constantly.

  2. Collision checking for the ball/car bouncing off of walls and the top goal post appears to be offset by 1 pixel in some cases (I’ll probably have to spend some time to get this exactly right). If you want to see this occurring, one example is driving the car against the top half of the far right wall; the car bounces off the wall with 1 green pixel visible. This is different that driving the car against the bottom half of the right wall or anywhere on the left wall where there is not a green pixel visible as the car bounces off the wall.

Thanks again!!

1 Like

@jwunderl I’m not seeing how to edit the post where Tiny Soccer Cars was first shared. I was hoping to replace the existing version with the one linked below. Is that possible?

Ahh, that’s a result of the new approval system; there’s no way to set it so edits trigger a review to make sure everything is safe (I don’t think at least) so they’re semi disabled. I updated the link in the post to the on you just shared for you~

1 Like