Skip to content

ebitencm is setanarut/cm physics space drawing package

License

Notifications You must be signed in to change notification settings

setanarut/ebitencm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoDoc

ebitencm

ebitencm is Drawer for setanarut/cm Chipmunk physics space.

Features

  • Color theme customization for Fill and Stroke colors.
  • Detailed drawing options.
  • drawer.GeoM{} structure is provided for screen transformation. (Cameras)

Usage

First create a drawer

var drawer *ebitencm.Drawer = ebitencm.NewDrawer()

Then

func (g *Game) Draw(screen *ebiten.Image) {
	drawer.DrawSpace(space, screen)
}

Dragging

If you want to enable dragging, call the HandleMouseEvent() function within the Update method, passing the *cm.Space object. This will allow objects to be dragged using a mouse or touch device.

func (g *Game) Update() error {
	drawer.HandleMouseEvent(space)

Camera transform

Use Drawer.GeoM{} for all vertices transform. The cursor position is calculated according to this matrix.

// move the all space objects 100 pixels to the left (move camera to right)
drawer.GeoM.Translate(-100, 0)

Here is an example with the setanarut/kamera package.

func (g *Game) Update() error {
	g.space.Step(1 / 60.0)
	g.cam.LookAt(x, y)
	// Apply camera transform to drawer
	g.drawer.GeoM.Reset()
	g.cam.ApplyCameraTransform(g.drawer.GeoM)
	// Enable cursor dragging
	g.drawer.HandleMouseEvent(g.space)

Examples

Browse to the examples folder for all examples.