ebitencm

package module
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2025 License: MIT Imports: 9 Imported by: 0

README

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.

Documentation

Index

Constants

View Source
const GrabableMaskBit uint = 1 << 31

Variables

View Source
var GrabFilter cm.ShapeFilter = cm.ShapeFilter{
	Group:      cm.NoGroup,
	Categories: GrabableMaskBit,
	Mask:       cm.AllCategories,
}

Functions

func ScreenToWorld added in v1.3.0

func ScreenToWorld(screenPoint v.Vec, cameraGeoM ebiten.GeoM) v.Vec

ScreenToWorld converts screen-space coordinates to world-space

func ToFColor added in v1.8.0

func ToFColor(c color.RGBA) cm.FColor

Types

type Drawer

type Drawer struct {
	// Ebitengine screen
	Screen *ebiten.Image

	// Drawing colors
	Theme          *Theme
	DrawingOptions *DrawingOptions
	// GeoM for drawing vertices. Useful for cameras
	GeoM *ebiten.GeoM

	DrawTriangleStrokeOpt *ebiten.DrawTrianglesOptions
	DrawTriagleFillOpt    *ebiten.DrawTrianglesOptions
	// contains filtered or unexported fields
}

func NewDrawer

func NewDrawer() *Drawer

func (*Drawer) DrawSpace added in v1.8.0

func (drw *Drawer) DrawSpace(space *cm.Space, screen *ebiten.Image)

DrawSpace draws all shapes in space with the drawer implementation

func (*Drawer) HandleMouseEvent

func (d *Drawer) HandleMouseEvent(space *cm.Space)

func (*Drawer) SetFillAntialias added in v1.2.1

func (d *Drawer) SetFillAntialias(antialias bool)

func (*Drawer) SetOpacity added in v1.8.0

func (d *Drawer) SetOpacity(alpha float32)

SetOpacity overwrites all Theme color alphas [0-1}]

func (*Drawer) SetScreen added in v1.3.0

func (d *Drawer) SetScreen(screen *ebiten.Image)

func (*Drawer) SetStrokeAntialias added in v1.2.1

func (d *Drawer) SetStrokeAntialias(antialias bool)

type DrawingOptions added in v1.8.0

type DrawingOptions struct {
	AllDotsDisabled            bool
	AllFillsDisabled           bool
	AllStrokesDisabled         bool
	CollisionNormalDisabled    bool
	CollisionNormalLength      float64
	CollisionNormalStrokeWidth float32
	ConstraintDisabled         bool
	ConstraintsDotRadius       float64
	ConstraintsStrokeWidth     float32
	DynamicBodyDisabled        bool
	DynamicBodyStrokeWidth     float32
	StaticBodyDisabled         bool
	StaticBodyStrokeWidth      float32
}

func DefaultDrawingOptions added in v1.8.0

func DefaultDrawingOptions() *DrawingOptions

type Theme added in v1.4.0

type Theme struct {
	CollisionNormal               cm.FColor
	ConstraintDampedSpringDot     cm.FColor
	ConstraintDampedSpringSegment cm.FColor
	ConstraintGrooveJointDot      cm.FColor
	ConstraintGrooveJointSegment  cm.FColor
	ConstraintPinJointDot         cm.FColor
	ConstraintPinJointSegment     cm.FColor
	ConstraintPivotJointDot       cm.FColor
	ConstraintSlideJointDot       cm.FColor
	ConstraintSlideJointSegment   cm.FColor
	DynamicBodyFill               cm.FColor
	DynamicBodyIdleFill           cm.FColor
	DynamicBodySleepingFill       cm.FColor
	DynamicBodyStroke             cm.FColor
	StaticBodyFill                cm.FColor
	StaticBodyStroke              cm.FColor
}

func DefaultTheme added in v1.4.0

func DefaultTheme() *Theme

Directories

Path Synopsis
examples
balls_cam command
basic command
bench command
player command
strokeTest command
theojansen_cam command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL