Sprint #2.5 - Daily Scrum #06
Product: Tetris2P AI
Sprint Summary
Daily Objectives
- Create a 2D Physics Engine
- Add Position Anchors for gameObjects
- Add Scroll and Right Click Support
Notes
How do I prevent clicks on overlapping elements? I can have objects set a target variable if they’ve been clicked. However, only the first object clicked gets first dibs on the click? OH, I can have themselves set themselves as the active target on the mousedown event! That way, the last item checked be the active target. What happens if a parent object wants to find out if a child object was clicked? I think we can ignore that case, and force the developer to execute parent functions onclick from the child button’s own update function.
Bug! For some reason, the scene click target never gets overwritten? The scene.clickTarget does get overwritten by the last item. Not setting the clickTarget to null was apparently the issue. OH, it’s cause other objects are setting it to null before the clicked object is able to do it haha. Cool cool, so that worked, but I should add a better way to check drag and hold? I think mousedown and clickTarget serve the same purpose?
I added a variable in the engine to keep track of the mousePos()!
Still to do:
-
Implement z-index? Or not. The only issue with this is that it’s only relevant for the scene’s direct children. Maybe it’s better to not implement. - Position Anchors!
- Differentiate clicks!
- Physics!
I think position anchors should be based off of AABB’s?
I need to make AABBs an actual class/object with actual getter and setter methods. If I’m making clicks and physics AABB based, I don’t want developers losing their references to their click objects and such.
Side note for the physics part: maybe each object can have a list of objects they need to detect, so they don’t have to collision check with other unrelated objects.
Let’s make the aabb object now and position anchors. Ok, I made the class with getters and setters for min and max, and it seems to be working fine so far :thumbs_up:
Now for object position and anchors. What’s the intended usage for this? So in general, each object can own multiple AABB’s. The question is do we want objects to have a general x and y position? Or should we have the information only up to AABB. I think its a easier to grasp concept if all ‘position’ related information were related to AABB’s.
I’m debating whether or not we include the ‘anchor’ references within the actual AABB objects. So what’s the main issue? If the aabb’s x and y position are relative to a moving parents, how do we figure out how/where to draw in regards to the canvas? I don’t want each gameObjects to have to follow anchor references all the way back to the canvas every single time. In order for child and grandchild objects to be drawn, their draw methods must be called from their parent’s draw function. The parent can just pass down their absolute canvas position positions, and the child objects can draw based off those. Off that logic there isn’t too much reason to keep the anchor reference in the aabb. BUT, what about objects checking/detecting onclick objects? I think each AABB needs to keep a world position along with its relative position. mouseClicks definitely need to be checked with the world position, and so does drawing to the canvas. The next question is how to implement that? When we set anchor references, we can have the parents keep track of their children instead. Wait no, we can have each aabb, keep relative position, absolute position, and parent aabb.
On update, each child update: child.absPos = child.relPos + parent.absPos
absPos or canvasPos, either works.
Is it not better though to have the parent just update their children? In general, if a child pos moves, the only related objects are the child. But if the parent moves, then both the parent and its children move. There’s no telling for sure if an anchored child objects, will even run its update loop to edit its position. FINAL ANSWER: the parents keep a reference of their anchored objects. I’m struggling with nomenclature and variable names. Do I define anchored objects as children? A N C H O R E E S = objects being anchored
how do I want to call the anchor function?
child.setAnchor(parent)
Before I go home from this cafe I wanna anchor the bouncing ball to the the draggable object :) Let’s add a lastPosition field for the AABB, since it’s healthy for moving objects apparently. Am I keeping track of the parent position of canvas position. I think it’s supposed to be canvas position. We needed a getter method for canvas position, but we want to actually keep track of parent’s canvas position. We never actually need to set canvas position is a variable based on two other variables.
Cool, the anchor points are working now :^)
Next:
- Differentiate Clicks - Putting this on the backburner
- Physics2D Engine
- Sprite Rendering
- Networking
Let’s talk more about the ‘Physics2D Engine’. The engine is basically a way to detect collisions between rigid body objects. The biggest difference between games is how you resolve collisions between objects, and what objects can collide with.
Examples:
- Player colliding with floors or walls: player’s position is halted and stopped at collision area
- Sword hit box against an enemy: enemy takes damage, collision is allowed.
Information regarding collisions:
- If a collision happens
- Ex: hitboxes
- Direction of a collision
- only four directions with AABB
- Consider combined collisions * Also resolve what happens when AABB inside another AABB
What does the developer have to do?
- Write resolver functions for collisions
Premade collision functions?
- spreventOverlap/pushOut
- bounce/reflect? (flipping velocities and stuff)
Let’s add the other click stuff now before anything else. Btw, I changed the target for the mouseup function to be the document, instead of the canvas. It was awkward moving the mouse outside of the canvas, and still having the drag in place.
Objectives Completed
-
created position anchors for gameObjects so they can describe their position relative to other objects rather than just the canvas
-
researched and outlined functions that a ‘2d physics engine’ needs to do/provide