Sprite.alignIn(background, Phaser.BOTTOM_RIGHT, -20, -20) The optional offsetX and offsetY arguments allow you to apply extra spacing to the finalĪligned position of the Game Object. This allows you to neatly align Game Objects, irrespective of their position value. The Game Objects are placed in such a way that their bounds align with theĬontainer, taking into consideration rotation, scale and the anchor property. Phaser.BOTTOM_CENTER and Phaser.BOTTOM_RIGHT. Phaser.CENTER, Phaser.RIGHT_CENTER, Phaser.BOTTOM_LEFT, Phaser.TOP_LEFT, Phaser.TOP_CENTER, Phaser.TOP_RIGHT, Phaser.LEFT_CENTER, It simply modifies its position coordinates so it aligns with it. Please note that aligning a Sprite to another Game Object does not make it a child of Or it can include other Sprites, Images, Text objects, BitmapText, Such as World.bounds or Camera.view, for aligning Game Objects within the worldĪnd camera bounds. The container must be a Game Object, or Phaser.Rectangle object. 'container', to one of 9 possible positions. Source: src/gameobjects/components/PhysicsBody.js line 101 bottom : numberĪligns this Game Object within another Game Object, or Rectangle, known as the If you need a different result then adjust or re-create the Body shape offsets manually or reset the anchor after enabling physics. So the physics body is centered on the Game Object. Important: Enabling a Game Object for P2 or Ninja physics will automatically set its anchor property to 0.5, You can alternatively call (object), or add this Game Object to a physics enabled Group. To enable this Game Object for physics you need to call (object, system) where object is this objectĪnd system is the Physics system you are using. Once a Game Object is enabled for physics you access all associatedīy default Game Objects won't add themselves to any physics system and their body property will be null. Source: src/gameobjects/Graphics.js line 54 Extendsīody is the Game Objects physics body. Phaser.Graphics#height to avoid an unusual race condition You may have to modify Phaser.Graphics#scale rather than Phaser.Graphics#width or In their complexity and quantity of them in your game. While they are extremely useful, you need to be careful You should avoid doing this, as it will constantly generate new textures, which will consume memory.Īs you can tell, Graphics objects are a bit of a trade-off. If your Graphics object updates frequently then You can then use this Texture for Sprites or other display objects. This will 'bake' the Graphics object into a Texture, and return it. Performance by calling Graphics.generateTexture. If your Graphics object doesn't change much (or at all) once you've drawn your shape to it, then you will help Both of these are expensive processes, especially with complex shapes. Graphics data is decomposed into polygons. Under Canvas it will use the HTML Canvas context drawing operations to draw the path. When a Graphics object is rendered it will render differently based on if the game is running under Canvas or This will draw a circle shape to the Graphics object, with a diameter of 100, located at x: 50, y: 50. For example: graphics.beginFill(0xff0000) To 'draw' to it you first specify a lineStyle or fillStyle (or both), and then draw a shape. When you initially create a Graphics object it willīe empty. They also include lines, arcs and curves. Primitives include forms of geometry, such as Rectangles,Ĭircles and Polygons. A Graphics object is a way to draw primitives to your game.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |