Back
Close
Previous: Introduction Next: Animating entities

Graphical Entities

Every sprite, shape, text, etc are entities displayable in the viewer. They implement diverse methods to be manipulated:

  • Position
  • Rotation
  • Anchor
  • Scale
  • Opacity
  • Z index

Examples

Creating a circle

// Creates a green circle
Circle circle = graphicEntityModule.createCircle()
			.setRadius(50)
			.setLineWidth(0)
			.setFillColor(0x00FF00);

Moving a circle

MyPlayer player = gameManager.getPlayer(turn % 2);
circle
	.setX(player.getX())
	.setY(player.getY());

With a Curve

circle
	.setX(player.getX(), Curve.LINEAR)
	.setY(player.getY(), Curve.LINEAR);

Creating a group of sprites

Sprite planet1 = graphicEntityModule.createSprite()
				.setImage("planet")
				.setX(-20);
Sprite planet2 = graphicEntityModule.createSprite()
				.setImage("planet")
				.setX(30);
				.setY(-10);
Sprite planet3 = graphicEntityModule.createSprite()
				.setImage("planet")
				.setY(20);

// The planets are around the point (960,540).
Group system = graphicEntityModule.createGroup(planet1, planet2, planet3)
					.setX(960)
					.setY(540);

Spinning a group of spinning sprites around a point

	planet1.setRotation(planet1.getRotation() - Math.PI / 4);
	planet2.setRotation(planet2.getRotation() + Math.PI);
	planet3.setRotation(planet3.getRotation() + Math.PI / 16);
	
	system.setRotation(system.getRotation() + Math.PI / 2);
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants