Kaynağa Gözat

fix sprite, kinematicbody2d :eyes:

Ethosa 3 yıl önce
ebeveyn
işleme
cdfb0ca224

+ 1 - 1
examples/roguelike/main.nim

@@ -74,7 +74,7 @@ addKeyAction("backward", "s")
 addKeyAction("right", "d")
 addKeyAction("left", "a")
 
-player@onInput(self, event):
+player@onProcess(self):
   if isActionPressed("right"):
     player.moveAndCollide(Vector2(PLAYER_SPEED, 0))
   elif isActionPressed("left"):

+ 1 - 1
src/nodesnim/nodes2d/kinematic_body2d.nim

@@ -96,7 +96,7 @@ method moveAndCollide*(self: KinematicBody2DRef, vel: Vector2Obj) {.base.} =
   ## - `vel` is a velocity vector.
   # TODO: normal algorithn
   let
-    biggest = abs(if max(vel.x, vel.y) == 0.0: min(vel.x, vel.y) else: max(vel.x, vel.y))
+    biggest = max(vel.x.abs(), vel.y.abs())
     step = Vector2(vel.x/biggest, vel.y/biggest)
     vec = vel.abs()
     scene = self.getRootNode()

+ 2 - 7
src/nodesnim/nodes2d/sprite.nim

@@ -55,6 +55,7 @@ method draw*(self: SpriteRef, w, h: GLfloat) =
 
   # Draw
   if self.texture.texture > 0'u32:
+    glPushMatrix()
     if self.centered:
       glTranslatef(x + (self.rect_size.x / 2), y - (self.rect_size.y / 2), self.z_index_global)
       self.position = self.rect_size / 2
@@ -80,13 +81,7 @@ method draw*(self: SpriteRef, w, h: GLfloat) =
     glEnd()
     glDisable(GL_DEPTH_TEST)
     glDisable(GL_TEXTURE_2D)
-    glRotatef(-self.rotation, 0, 0, 1)
-    if self.centered:
-      glTranslatef(-x - (self.rect_size.x / 2), -y + (self.rect_size.y / 2), -self.z_index_global)
-      self.position = self.timed_position - self.rect_size/2
-    else:
-      glTranslatef(-x, -y, -self.z_index_global)
-      self.position = self.timed_position
+    glPopMatrix()
   else:
     self.rect_size = Vector2()
 

+ 1 - 0
tests/README.md

@@ -50,3 +50,4 @@
 - [Use Camera3D node.](https://github.com/Ethosa/nodesnim/blob/master/tests/test48.nim)
 - [Use TileMap Isometric mode](https://github.com/Ethosa/nodesnim/blob/master/tests/test49.nim)
 - [Make your own node](https://github.com/Ethosa/nodesnim/blob/master/tests/test50.nim)
+- [Use Sprite 3D node.](https://github.com/Ethosa/nodesnim/blob/master/tests/test51.nim)