Collision problem with image loaded

17 views
Skip to first unread message

sebastien charret

unread,
Nov 14, 2013, 3:07:13 PM11/14/13
to fantom...@googlegroups.com
Hello,

I have read your book and thanks for it friendly monkey's approach, it help me out to learn game programming quickly.

I have made my first project with phantom engine (great framework, it saves a lot of time and do the thing easy) and I have a problem with the paddle collision.

If I create a simple rectangle to be the paddle, everything works fine but if load a sprite, my ball will collide 47 pixel above the paddle.

I tried to manage this error with changes on the paddle and nothing happends.


Problem line 178.

Can you check whether i mess something?

Thanks for the help.

Seb.

Michael Hartlef

unread,
Nov 15, 2013, 11:43:50 AM11/15/13
to fantom...@googlegroups.com
Hi Seb,

I will have a look at your project soon.

sebastien charret

unread,
Nov 16, 2013, 9:35:51 AM11/16/13
to fantom...@googlegroups.com
Thanks Michael.

Michael Hartlef

unread,
Nov 16, 2013, 11:27:34 AM11/16/13
to fantom...@googlegroups.com
Ok, I see not much could be done differently. The collision was basically good on HTML5 . I just changed a view things:

I have added this method the engine class:

Method OnObjectRender:Int(obj:ftObject)

If KeyDown(KEY_C)

If obj.GetColType() = ftEngine.ctCircle

DrawCircle(obj.GetPosX(), obj.GetPosY(), obj.GetRadius())

Else

DrawLine(obj.GetPosX()+obj.x1c, obj.GetPosY()+obj.y1c, obj.GetPosX()+obj.x2c, obj.GetPosY()+obj.y2c)

DrawLine(obj.GetPosX()+obj.x2c, obj.GetPosY()+obj.y2c, obj.GetPosX()+obj.x3c, obj.GetPosY()+obj.y3c)

DrawLine(obj.GetPosX()+obj.x3c, obj.GetPosY()+obj.y3c, obj.GetPosX()+obj.x4c, obj.GetPosY()+obj.y4c)

DrawLine(obj.GetPosX()+obj.x4c, obj.GetPosY()+obj.y4c, obj.GetPosX()+obj.x1c, obj.GetPosY()+obj.y1c)

Endif

Endif


Return 0

End



When you press now the C key, every object that has the render event activated, will draw an extra circle or box to show their collision bodies.


With the raquette, don't change it width and height. Then add these two lines to its CreateRaquette method:


raquette.SetColType(ftEngine.ctBox)

raquette.ActivateRenderEvent(True)



For the ball, just add this line tot he CreateBall method:


ball.ActivateRenderEvent(True)


The information about the collision you print is the Y-Coordinate of the ball, the center of the ball. Not the Center of the collision.


So, if that is still not what you want, then please try to explain again, where the problem is for you.


Reply all
Reply to author
Forward
0 new messages