I have an image mySprite.png. The image is a 5x5 grid of 32x32 px sprites. This image has been uploaded to the project library.
Assuming I have a render () function inside a class, how would this class draw itself as one sprite from this sprite sheet resource?
The short answer is that you want to use BitmapData.copyPixels () to copy only a small section from your original sprite sheet into your sprite screen, which is actually on the screen.
Sort of:
private function DrawSpriteIndex( displayBitmap:Bitmap, spriteSheet:Bitmap, spriteIndex:int ):void { var spriteW:int = 32; var spriteH:int = 32; var sheetW:int = 5; displayBitmap.bitmapData.copyPixels(spriteSheet.bitmapData, new Rectangle( (spriteIndex % sheetW) * spriteW, Math.floor(spriteIndex / sheetW) * spriteH, 32, 32), new Point(0,0) ); }
You may find these links useful - they helped me when I found out about this:
32x32 .
- ():
var spriteMask:Sprite = new Sprite(); spriteMask.graphics.drawRect(0,0,32,32); spriteSheetContainer.mask = spriteMask; function render():void { // this function is on the container of the sprite sheet (spriteSheetContainer in this example) // run offsetX & Y iteration logic. I would assume something that uses a frame counter, modulus, and the sprite layout grid dimensions _spriteSheet.x = offsetX; // move the sprite around under the mask _spriteSheet.y = offsetY; }
, , .
Source: https://habr.com/ru/post/1713774/More articles:ΠΠΎΡΠ΅ΠΌΡ Π² ΠΌΠ΅ΡΠΎΠ΄Π΅ ΠΎΠ±ΡΠ°ΡΠ½ΠΎΠ³ΠΎ Π²ΡΠ·ΠΎΠ²Π° ΠΏΡΠΈ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠΈ AsyncCallback Ρ BeginInvoke Ρ ΠΏΠΎΠ»ΡΡΠ°Ρ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΡ "ΠΠ΅ΠΏΠΎΠ»Π°Π΄ΠΊΠ° Ρ ΠΏΠ΅ΡΠ΅ΠΊΡΠ΅ΡΡΠ½ΡΠΌ ΠΏΠΎΡΠΎΠΊΠΎΠΌ", Π½Π΅Π΄Π΅ΠΉΡΡΠ²ΠΈΡΠ΅Π»ΡΠ½ΠΎΠ΅ ΠΈΡΠΊΠ»ΡΡΠ΅Π½ΠΈΠ΅? - multithreadingHow to fail Maven by missing parameter? - javaΠΠ½ΡΠ΅Π³ΡΠ°ΡΠΈΡ Jabber/XMPP Ρ Π΄ΡΡΠ³ΠΈΠΌΠΈ ΡΠΈΡΡΠ΅ΠΌΠ°ΠΌΠΈ (Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΡ, ΡΠΎΠ²ΠΌΠ΅ΡΡΠ½ΠΎΠ΅ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠ΅ ΠΏΠ°ΡΠΎΠ»Π΅ΠΉ) - authenticationForce user to enter property with Maven - maven-2WPF-ΠΠ°ΠΊ ΠΏΠΎΠΊΠ°Π·Π°ΡΡ ΠΎΠ±ΡΠ΅Π·Π°Π½Π½ΡΠΉ ΡΠ΅Π³ΠΈΠΎΠ½ ΠΈΡΡΠΎΡΠ½ΠΈΠΊΠ° ΠΈΠ·ΠΎΠ±ΡΠ°ΠΆΠ΅Π½ΠΈΡ Π² ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ΅ ΡΠΏΡΠ°Π²Π»Π΅Π½ΠΈΡ? - imageInstall Django using mod_wsgi - pythonDelphi 2005 Web Services Issue - wsdl.NET Compact Framework 3.5 animated transparent wait cursor - .netjqgrid. change theme - themesdjango @login_required decorator error - pythonAll Articles