# Help with floating sprites

**URL:** <https://forum.makecode.com/t/help-with-floating-sprites/4408>\
**Category:** Help\
**Created:** [November 13, 2020, 4:29pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408 "2020-11-13T16:29:26Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [November 13, 2020, 4:29pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/1 "2020-11-13T16:29:26Z")

</div>

I am working on my next game, Rygary, which I intend to make as a spin off the game ‘Rygar’. For those that have never seen the game: [https://www.youtube.com/watch?v=fYSUq\_RHybw&t=1515s](https://www.youtube.com/watch?v=fYSUq_RHybw&t=1515s)

I am wondering if you can test the game for me.

> **[Rygary](https://arcade.makecode.com/54090-39137-89187-77123)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

Everything works fine when playing on a computer. When playing on my phone (Nokia 7.2 Chrome), and when the enemies appear, they all become ‘Matrix Revolution’-like and start floating in the air. This is usually happening when I start swinging the sword. In a game update I keep setting the position of the sword sprite relative to the player.

I thought about limiting the number of enemies. Can someone help me out? I appreciate all the help I can get and value your feedback. Thanks.

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [November 14, 2020, 9:35am UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/2 "2020-11-14T09:35:15Z")

</div>

@jwunderl @richard @peli @mmoskal @AlexK

Sorry to all spam you about this, but I am desperate in finding out what the issue is here.

On a computer when there are about 90-100 sprites and the fps drops around 10, then all sprites begin to float. If I try playing this on hardware, even on my mobile phone mentioned above, then as soon as one/two sprites appear the same problems occurs.

I know I can limit the number of sprites, but even after one it becomes an issue. I tried so many things, from removing the background entirely, making the tilemap smaller (100x8; I don’t mind if it should be smaller again) , removing all animations (even when the player shoots). The moment that the player jumps the problem occurs . I set a sprite to be in front of the player and have that sprite follow the camera. In a game update I set the player to be some distance away from the other sprite. Could it be that the ‘game update’ methods are computationally intensive? Even without any enemies, when the player jumps, it jumps erratically (way too high).

I am really pleased with the platform, and love and appreciate the community support, but I am starting too lose faith in stability of the platform. It seems to me that the moment a game becomes too large, it doesn’t work on a phone, on my PyGamer. I was able to play it on my PyGamer but that stopped working after some time. I don’t mind playing it on a computer, but it would be nice if it worked on a my phone and/or hardware.

Can someone please help? 😖

My apologies in advance for the methods being spread out all over the place. That happens unfortunately whenever I have to switch to Javascript and remove an extension. After which all the methods have moved.

---

<div class="post-metadata">

**Author:** ![andrew-ski](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/andrew-ski/32/1774_2.png) [@andrew-ski](https://forum.makecode.com/u/andrew-ski)\
**Post date:** [November 14, 2020, 2:20pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/3 "2020-11-14T14:20:28Z")

</div>

Running a low power laptop with chromium browser and I’m seeing the floating issues pretty quickly. It definitely gets worse as I make my way across the map. I couldn’t make it to the end of the map without killing enemies due to the float/lag.

Good luck. Looks like some intense code.

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [November 14, 2020, 3:33pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/4 "2020-11-14T15:33:08Z")

</div>

Thank you for getting back to me on this. There are quite a number of different functions, but really the only ones which should affect performance are the ones called in game update. Even after I removed all calls to use animation, it was still a problem.

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [November 16, 2020, 5:28pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/5 "2020-11-16T17:28:12Z")

</div>

This is a physics bug that happens whenever the computer is not giving enough resources to the iframe or when the game is very resource intensive. In this case, it’s probably the number of sprites combined with the large tilemap.

You’re most likely to see this happen when focused on the workspace and scrolling around, because that is resource intensive and takes away processing time from the simulator. Also more likely to happen on lower-end hardware.

I believe we have a bug open for this somewhere

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [November 16, 2020, 5:32pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/6 "2020-11-16T17:32:38Z")

</div>

Thanks for getting back to me on this Richard. I am trying to cut down on the number of methods in the game update, and moving this to ‘event’ driven checks.  
Just curious…  
Is it better to check in a game update interval method (even if this means it is not real time) when a player is doing something? Does this give the hardware more time to process things?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [November 16, 2020, 5:39pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/7 "2020-11-16T17:39:12Z")

</div>

No, you should do it in on game update! Your code doesn’t look particularly heavy, this is probably just due to the physics engine itself.

---

<div class="post-metadata">

**Author:** ![Dreadmask197](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/dreadmask197/32/10494_2.png) [@Dreadmask197](https://forum.makecode.com/u/Dreadmask197)\
**Post date:** [November 16, 2020, 6:48pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/8 "2020-11-16T18:48:41Z")

</div>

Hey @cosmoscowboy! I’ve had that same problem but it’s on my laptop and on my phone. When I play this game, all the coins float all the way up. I believe it’s because of all the sprites in a game update block.

> [@Plinko automated](https://forum.makecode.com/t/plinko-automated/4240):
>
> I made plinko… AGAIN! I made this about 4 months ago and still don’t know what @richard’s math for bouncing is?! But this time it’s automated. you might need to press A for some time. Have Fun!!

This is my link. It’s an automated Plinko game and it kills me. If you survive for a while, you will see all the balls still going, and eventually, it will lag and all the coins go up

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [December 7, 2020, 10:09pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/9 "2020-12-07T22:09:12Z")

</div>

> [@richard](#):
>
> You’re most likely to see this happen when focused on the workspace and scrolling around, because that is resource intensive and takes away processing time from the simulator.

I know this is an old post, but I would like to pick up this game again. I am not sure what you mean by the statement above. Could you explain ‘focused on the workspace and scrolling around’?

---

<div class="post-metadata">

**Author:** ![richard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/richard/32/5417_2.png) [@richard](https://forum.makecode.com/u/richard)\
**Post date:** [December 7, 2020, 10:30pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/10 "2020-12-07T22:30:30Z")

</div>

If you are using the blocks workspace and scrolling it around (panning), your computer needs to spend extra time re-rendering all of the blocks. As a result, it takes away some resources from things it thinks you aren’t using, like the simulator iframe.

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [December 9, 2020, 9:01pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/11 "2020-12-09T21:01:08Z")

</div>

As stated in my original post, this problem only occurs when playing the game on hardware, or on my phone. Playing the game within a browser on my computer is not a problem.

If I am playing the game (on hardware or on my phone) without seeing the code, surely that should not need to spend time recalculating the block code. (_If you are using the blocks workspace and scrolling it around (panning), your computer needs to spend extra time re-rendering all of the blocks._)

---

<div class="post-metadata">

**Author:** ![cosmoscowboy](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/cosmoscowboy/32/1718_2.png) [@cosmoscowboy](https://forum.makecode.com/u/cosmoscowboy)\
**Post date:** [December 9, 2020, 9:07pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/12 "2020-12-09T21:07:38Z")

</div>

> [@Dreadmask197](#):
>
> This is my link. It’s an automated Plinko game and it kills me. If you survive for a while, you will see all the balls still going, and eventually, it will lag and all the coins go up

This is because you are spawning too many sprites that what the platform can handle. My problem with the floating sprites was occurring even when I just spawned one enemy sprite.

---

<div class="post-metadata">

**Author:** ![NxNMatrixGL](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/nxnmatrixgl/32/2553_2.png) [@NxNMatrixGL](https://forum.makecode.com/u/NxNMatrixGL)\
**Post date:** [January 4, 2021, 11:49pm UTC](https://forum.makecode.com/t/help-with-floating-sprites/4408/13 "2021-01-04T23:49:30Z")

</div>

I love Rygar. Great MakeCode edition! I think I will play the original tonight.
