deltaluca / nape

Haxe/AS3 Physics Engine
http://napephys.com
Other
542 stars 77 forks source link

placement of code is not shown on screen #105

Closed lewislepton closed 8 years ago

lewislepton commented 8 years ago

hello,

this is an odd thing i have always come across with nape. whilst i donst think its a bug or anything like that, maybe you could help with it.

so i am using kha, a haxe framework, the building and rending of shapes etc is fine, got it perfectly working. but any collision with another shapes seems completely off.

here is the code i am using for say the ball & the player

Player.hx

package char;

import kha.graphics2.Graphics;
using kha.graphics2.GraphicsExtension;
import kha.Color;
import kha.Assets;
import kha.math.Vector2;

import kha2d.Animation;
import kha2d.Sprite;
import kha.math.Vector2;

import nape.phys.Body;
import nape.phys.BodyType;
import nape.shape.Polygon;
import nape.geom.Vec2;
import nape.space.Space;

import ll.Timer;

class Player {
  public var up:Bool;
  public var down:Bool;
  public var left:Bool;
  public var right:Bool;

  public var x:Int;
  public var y:Int;
  public var xVel = 0.0;
  public var yVel = 0.0;
  public var speed = 60;
  public var friction = 6.0;

  public var body:Body;

  public function new(space:Space){
    body = new Body();
    body.space = space;
    body.shapes.add(new Polygon(Polygon.rect(128, 128, 64, 64)));
  }

  public function render(graphics:Graphics){
    graphics.color = Color.Green;
    graphics.drawRect(body.position.x, body.position.y, 64, 64);
  }
}

Ball.hx

package char;

import kha.graphics2.Graphics;
using kha.graphics2.GraphicsExtension;
import kha.Color;
import kha.Assets;
import kha.math.Vector2;

import nape.phys.Body;
import nape.phys.BodyType;
import nape.shape.Circle;
import nape.geom.Vec2;
import nape.space.Space;

class Ball {
  public var body:Body;
  public function new(space:Space){
    body = new Body();
    body.space = space;
    body.shapes.add(new Circle(32));
    body.position.x = 256;
    body.position.y = 256;
  }

  public function render(graphics:Graphics){
    graphics.color = Color.Cyan;
    graphics.drawCircle(body.position.x, body.position.y, 32);
  }
}

i also have a GIF to show exactly what i mean, but when the player is hitting or going near the ball, it is not even near the rendered shapes but starts to move, its odd.

oddness

it would be great if you or someone else knew the problem. im asking around with some kha folk too ;) so will close and comment if i find the problem beforehand

thanks

lewislepton commented 8 years ago

fixed. really simple and stupid mistake that was moving the physics lower ground away by say 128, 128 on the x, y. and the block was staying at 0,0

doh!!!