Looks like you're not logged in

Login or Register to continue

Lesson Q&A

Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.

  • Ship waits until it's past the edge of the screen to wrap.SuperstupidyMaybe it's a rudimentary solution, but I was able to improve the game feel by adding and subtracting extra pixels onto the extremes. **var viewport_size = get_viewport_rect().size** ** position.x = wrapf(position.x, 0 - 60, viewport_size.x + 60)** ** position.y = wrapf(position.y, 0 - 60, viewport_size.y + 60)** This way my sprite has further to go on either end before it teleports to the other side. 7 8 Jul. 24, 2024
  • WrappingPJI don't understand how wrapping works, just mindlessly copied the code. Could you recommend some additional resources? 10 4 Mar. 05, 2024
  • can var viewport_size be created once?nedIs there a benefit to creating the variable once per frame, or can it be created once in the global scope of the script like this? ```gdscript @onready var viewport_size : Vector2 = get_viewport_rect().size ``` 6 2 Feb. 27, 2024
  • Adding this broke controlsweepy-lapwingI added the code and now I go only diagonal x, y, and diagonal -y, -x. Cut and paste the exact area you wrote it, bug still persists. Commented out the wrap code, the controls work fine again. 1 0 Sep. 03, 2024
  • Adding a Buffer to the Wrapunwitting-mandrillI noticed that the ship would wrap to the other side before fully leaving the screen, which looked a little janky. This was the solution I came up with: ** var viewport_size := get_viewport_rect().size** ** var ship_dimensions: Vector2 = get_node("Sprite2D").texture.get_size()** ** var x_buffer = ship_dimensions.x / 2** ** var y_buffer = ship_dimensions.y / 2** ** position.x = wrapf(position.x, 0 - x_buffer , viewport_size.x + x_buffer )** ** position.y = wrapf(position.y, 0 - y_buffer , viewport_size.y + y_buffer )** There's probably a more graceful way to do this, but it does seem to work. 1 0 Aug. 21, 2024
  • How would you add music?dofudengamesI would like to add music to the game, how would i do that i know i have to use the adoui ??? node 3 0 Aug. 12, 2024
  • Simple If/Else ApproachDustinAfter reading the topic and the goal of L9., I tried to achieve the goal as simple as possible. Is the following if/else block a feature less version of the wrapf approach? At least the result is the same. Of course not as readable as using the built in function. ```gdscript if position.x > viewport.x: position = Vector2(0, position.y) elif position.x < 0: position = Vector2(viewport.x, position.y) if position.y > viewport.y: position = Vector2(position.x, 0) elif position.y < 0: position = Vector2(position.x, viewport.y) ``` 1 0 Jul. 29, 2024
  • Strange bug upon typing the wrapping codeHave A Good DayI don't know what's up but when i type in exactly this code (posted below for another strange bug reason) the ship moves diagonally upward when going left, and diagonally down when going right, and up and down rotate the ship but don't move it's position, but it still wraps as it should. Copying and pasting the code directly from the lesson seems to fix this. The other strange bug is that, upon putting the code in an inserted code block, pressing enter 3 times just keeps making more new lines. Tested 50 times, with 50 empty new lines. I don't know if I accidentally inputted some invisible unicode symbol or what. Anyway, here's the code, with 17 extra new spaces to see if that carries over when the comment is posted. ```gdscript var viewport_size := get_viewport_rect().size position.x = wrapf(position.x, 0, viewport_size.x) position.y = wrapf(position.x, 0, viewport_size.y) ``` 1 0 Jun. 20, 2024
  • How improve the wrapf system ?ZorgThe wrapf function works well in one axis at a time, but when you move diagonally, it teleports with a glitch. If you try to move quickly in the corner, the function will first take the overlapping axis (for example, the x-axis) and respawn you on the opposite side, but shortly after, the system will notice that you are also overlapping the y-axis and will teleport you a second time. Can we improve this with another method ? Thanks by the way for this courses, it help me a lot to start with the dev and game dev programming ! and also improve my english 6 0 Apr. 06, 2024
  • Wrap around screen - mathematicallyMonarch```gdscript var viewport = get_viewport_rect().size var new_position = Vector2( fposmod((position.x + velocity.x * delta),viewport.x+1), fposmod((position.y + velocity.y * delta),viewport.y+1)) position = new_position ``` instead of using wrapf() api you can do it mathematically we can use modulus operator i did it this way bc this can be used in other game engines or programming languages, wrapf is abstracted so for ppl who want the implementation 6 0 Mar. 12, 2024
  • Get the Ship Width and Height?edmunditoI can look this up, but I will post it here for the rest of the group. How can we get the ship's sprite scaled width and height so we can wrap it as soon as the ship goes off-screen on the top and left sides? 1 0 Mar. 09, 2024
  • Tested something was wondering why?illiterate-spiderI put the variable outside of process and the wrap functions after direction.x and y. My ship stays in one spot and rotates only when i try and move. Why does this happen? 4 0 Feb. 23, 2024
  • Code Missing from Code Reference?RiskyPixelsJust wanted to flag that the direction length if statement seems to be missing from the end lesson code reference: `if direction.length() > 1.0:` `direction = direction.normalized()` as does the velocity length if statement that pairs with line 31: `if velocity.length() > 0.0:` `get_node("Sprite2D").rotation = velocity.angle()` 1 0 Feb. 21, 2024
  • Camera2D needs to be moved as wellMarkStruikSo i still had my Camera2D as a child node of the ship. this needs to be moved to the root/level. maybe i missed it in the text somewhere. but just wanted to let everyone know just in case someone is stuck there as well 7 0 Feb. 20, 2024
Site is in BETA!found a bug?