Pages traduites Pages à traduire Pages en cours de traduction
A propos
 

Ceci est une ancienne révision du document !



Fonctions et propriétés des surfaces de dessin (DrawingSurface)

La famille de fonctions DrawingSurface vous permet de dessiner directement sur les dynamic sprites et les arrière-plans du jeu. Vous obtenez une surface de dessin en appelant DynamicSprite.GetDrawingSurface ou Room.GetDrawingSurfaceForBackground, et vous pouvez ensuite utiliser les méthodes suivantes pour dessiner sur ces surfaces.

IMPORTANT : Vous DEVEZ appeler la méthode Release lorsque vous avez fini de dessiner sur une surface. Ceci permet à AGS de mettre à jour les copies en cache de l'image et de les charger en mémoire vidéo si nécessaire.


Clear (drawing surface)

(Anciennement RawClearScreen, désormais obsolète)

DrawingSurface.Clear(optional int couleur)

Remplit la surface avec la COULEUR spécifiée (correspond aux numéros dans l'onglet Colours de l'éditeur). Le contenu en cours de la surface sera effacé.

Si vous n'entrez pas de paramètre COULEUR, ou utilisez COLOR_TRANSPARENT, la surface deviendra entièrement transparente.

Exemple :

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.Clear(14);
surface.DrawingColor = 13;
surface.DrawCircle(160,100,50); 
surface.Release();

rend l'arrière-plan de la pièce entièrement jaune, puis dessine un cercle rose en son milieu.

Voir aussi : DrawingSurface.DrawingColor


CreateCopy

(Anciennement RawSaveScreen, désormais obsolète)

DrawingSurface* DrawingSurface.CreateCopy()

Crée une copie de la surface actuelle, de façon à pouvoir la récupérer plus tard pour la restaurer. Ceci peut être utile si vous voulez faire une copie de sauvegarde de l'arrière-plan avant de dessiner dessus, ou pour sauvegarder une étape de votre dessin et la restaurer plus tard.

Contrairement à la commande obsolète RawSaveScreen des versions précédentes d'AGS, les surfaces créées par cette commande ne sont pas perdues lorsque le joueur change de pièce ou restaure une partie. Toutefois, les surfaces qui contiennent des copies d'arrière-plans peuvent être très lourdes , occupant une grande place dans la mémoire et peuvent significativement alourdir le jeu. Ainsi, il est fortement recommandé d'utiliser Release sur la surface copiée dès que vous en avez fini avec elle.

Exemple :

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
DrawingSurface *backup = surface.CreateCopy();
surface.DrawTriangle(0,0,160,100,0,200);
Wait(80);
surface.DrawSurface(backup);
backup.Release();
surface.Release();

fera une copie de sauvegarde de l'arrière-plan de la pièce, dessinera un triangle dessus, attendra un moment puis restaurera l'arrière-plan original.

Voir aussi : DrawingSurface.DrawSurface


DrawCircle

(Anciennement RawDrawCircle, désormais obsolète)

DrawingSurface.DrawCircle(int x, int y, int rayon)

Dessine un cercle plein de rayon RAYON centré à (X,Y) de la couleur de dessin courante.

Exemple :

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = 14;
surface.DrawCircle(160,100,50); 
surface.Release();

dessinera un cercle jaune au centre de l'écran, d'un rayon de 50 pixels.

Voir aussi : DrawingSurface.DrawLine, DrawingSurface.DrawingColor


DrawImage

(Anciennement RawDrawImage, désormais obsolète) (Anciennement RawDrawImageResized, désormais obsolète) (Anciennement RawDrawImageTransparent, désormais obsolète)

DrawingSurface.DrawImage(int x, int y, int slot, optional int transparency,
                         optional int width, optional int height)

Draws image SLOT from the sprite manager onto the surface at location (X,Y).

Optionally, you can also specify the transparency of the image. This is a number from 0-100; using a transparency of 50 will draw the image semi-transparent; using 0 means it will not be transparent.

You can also resize the image as you draw it. In order to do this, simply specify a width and height that you wish to resize the image to when it is drawn.

NOTE: This command only works if the image to be drawn is the same colour depth as the surface that you are drawing onto.

NOTE: Transparency does not work in 256-colour games, or with 256-colour sprites.

NOTE: The X and Y co-ordinates given are ROOM co-ordinates, not SCREEN co-ordinates. This means that in a scrolling room you can draw outside the current visible area.

Exemple :

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawImage(100, 100, oDoor.Graphic, 40);
surface.Release();

will draw the oDoor object's graphic onto the room background at (100, 100), at 40% transparency.

Voir aussi : DrawingSurface.DrawLine, DrawingSurface.DrawString, DrawingSurface.DrawSurface, Room.ColorDepth


DrawLine

(Anciennement RawDrawLine, désormais obsolète)

DrawingSurface.DrawLine(int from_x, int from_y, int to_x, int to_y,
                        optional int thickness) 

Draws a line from (FROM_X, FROM_Y) to (TO_X, TO_Y) in the surface's current drawing colour.

The thickness parameter allows you to specify how thick the line is, the default being 1 pixel.

NOTE: The X and Y co-ordinates given are ROOM co-ordinates, not SCREEN co-ordinates. This means that in a scrolling room you can draw outside the current visible area.

Exemple :

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = 14;
surface.DrawLine(0, 0, 160, 100);
surface.Release();

will draw a line from the left top of the screen (0,0) to the middle of the screen (160,100);

Voir aussi : DrawingSurface.DrawCircle, DrawingSurface.DrawRectangle, DrawingSurface.DrawTriangle, DrawingSurface.DrawingColor


DrawMessageWrapped

(Anciennement RawPrintMessageWrapped, désormais obsolète)

DrawingSurface.DrawMessageWrapped(int x, int y, int width,
                                  FontType font, int message_number)

Draws the room message MESSAGE_NUMBER onto the surface at (x,y), using the specified FONT.

WIDTH is the width of the virtual textbox enclosing the text, and is the point that the text will wrap at. This command is designed for writing a long message to the screen with it wrapping normally like a standard label would do.

The text will be printed using the current drawing colour.

Exemple :

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = 14;
surface.DrawMessageWrapped(80, 40, 160, Game.NormalFont, 10); 
surface.Release();

will display message 10 in the centre of the screen, starting from Y = 40.

Voir aussi : DrawingSurface.DrawString, DrawingSurface.DrawingColor, DrawingSurface.DrawStringWrapped


DrawPixel

DrawingSurface.DrawPixel(int x, int y) 
Draws a single pixel onto the surface at (X,Y) in the current colour. The pixel thickness respects the UseHighResCoordinates property.

NOTE: This command is not fast enough to use repeatedly to build up an image. Only use it for single pixel adjustments.

Exemple :
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = 14;
surface.DrawPixel(50, 50);
surface.Release();

draws a yellow pixel in the top left of the room background

Voir aussi : DrawingSurface.DrawingColor, DrawingSurface.DrawLine, DrawingSurface.GetPixel, DrawingSurface.UseHighResCoordinates


DrawRectangle

(Anciennement RawDrawRectangle, désormais obsolète)

DrawingSurface.DrawRectangle(int x1, int y1, int x2, int y2)

Draws a filled rectangle in the current colour with its top-left corner at (x1,y1) and its bottom right corner at (x2, y2)

NOTE: The X and Y co-ordinates given are ROOM co-ordinates, not SCREEN co-ordinates. This means that in a scrolling room you can draw outside the current visible area.

Exemple :

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = 14;
surface.DrawRectangle(0, 0, 160, 100);
surface.Release();

will draw a rectangle over the top left hand quarter of the screen.

Voir aussi : DrawingSurface.DrawImage, DrawingSurface.DrawLine


DrawString

(Anciennement RawPrint, désormais obsolète)

DrawingSurface.DrawString(int x, int y, FontType font, string text, ...)

Draws the text onto the surface at (x, y), using the supplied font number. The text will be drawn in the current drawing colour.

You can insert the value of variables into the message. For more information, see the string formatting section.

Exemple :

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = 14;
surface.DrawString(0, 100, Game.NormalFont, "Text written into the background!");
surface.Release();

will write some text onto the middle-left of the room background

Voir aussi : GetTextWidth, DrawingSurface.DrawStringWrapped, DrawingSurface.DrawingColor


DrawStringWrapped

DrawingSurface.DrawStringWrapped(int x, int y, int width,
                                 FontType font, Alignment,
                                 const string text)
Draws the text onto the surface at (x,y), using the specified FONT.

width is the width of the virtual textbox enclosing the text, and is the point that the text will wrap at. You can use the alignment parameter to determine how the text is horizontally aligned.

The text will be printed using the current drawing colour.

Exemple :
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = 14;
surface.DrawStringWrapped(80, 40, 160, Game.NormalFont, eAlignCentre, "Hello, my name is Bob."); 
surface.Release();

will display the text in the centre of the screen, starting from Y = 40.

Compatibility: Supported by AGS 3.0.1 and later versions.

Voir aussi : DrawingSurface.DrawString, DrawingSurface.DrawingColor, DrawingSurface.DrawMessageWrapped


DrawSurface

(Anciennement RawDrawFrameTransparent, désormais obsolète) (Anciennement RawRestoreScreen, désormais obsolète)

DrawingSurface.DrawSurface(DrawingSurface *source, optional int transparency)

Draws the specified surface on top of this surface, optionally using transparency percent transparency.

This allows you to perform day-to-night fading and other special effects.

NOTE: You cannot use the transparency parameter with 256-colour surfaces.

NOTE: This command can be a bit on the slow side, so don't call it from repeatedly_execute.

TIP: If you want to gradually fade in a second background, create a copy of the original surface and then restore it after each iteration, otherwise the backgrounds will converge too quickly.

Exemple :

DrawingSurface *mainBackground = Room.GetDrawingSurfaceForBackground(0);
DrawingSurface *nightBackground = Room.GetDrawingSurfaceForBackground(1);
mainBackground.DrawSurface(nightBackground, 50);
mainBackground.Release();
nightBackground.Release();

this will draw background frame 1 onto frame 0 at 50% opacity.

Voir aussi : DrawingSurface.DrawImage, SetAmbientTint


DrawTriangle

(Anciennement RawDrawTriangle, désormais obsolète)

DrawingSurface.DrawTriangle(int x1, int y1, int x2, int y2, int x3, int y3)

Draws a filled triangle in the current colour with corners at the points (x1,y1), (x2,y2) and (x3,y3).

Well, don't look at me, you might find it useful for something :-)

Exemple :

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = 14;
surface.DrawTriangle(0,0,160,100,0,200); 
surface.Release();

will draw a triangle with corners at the points (0,0),(160,100),(0,200).

Voir aussi : DrawingSurface.DrawImage, DrawingSurface.DrawLine, DrawingSurface.DrawRectangle


Release (drawing surface)

DrawingSurface.Release()
Tells AGS that you have finished drawing onto this surface, and that AGS can now upload the changed image into video memory.

After calling this method, you can no longer use the DrawingSurface instance. To do any further drawing, you need to get the surface again.

Exemple :
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = 14;
surface.DrawLine(0, 0, 50, 50);
surface.Release();

draws a yellow diagonal line across the top-left of the current room background, then releases the image.

Voir aussi : DynamicSprite.GetDrawingSurface, Room.GetDrawingSurfaceForBackground


DrawingColor property

(Anciennement RawSetColor, désormais obsolète)

int DrawingSurface.DrawingColor

Gets/sets the current drawing colour on this surface. Set this before using commands like DrawLine, which use this colour for their drawing.

You can set this either to an AGS Colour Number (as you'd get from the Colours pane in the editor) or to the special constant COLOR_TRANSPARENT, which allows you to draw transparent areas onto the surface.

Exemple :

DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.DrawingColor = 14;
surface.DrawLine(0, 0, 160, 100);
surface.DrawingColor = Game.GetColorFromRGB(255, 255, 255);
surface.DrawLine(0, 199, 160, 100);
surface.Release();

will draw a yellow line from the left top of the screen (0,0) to the middle of the screen (160,100), and a white line from the bottom left to the middle.

Voir aussi : DrawingSurface.DrawCircle, DrawingSurface.DrawLine, DrawingSurface.DrawRectangle, Game.GetColorFromRGB


GetPixel

int DrawingSurface.GetPixel(int x, int y) 
Returns the AGS Colour Number of the pixel at (X,Y) on the surface.

NOTE: In high-colour games, the first 32 colour numbers have a special meaning due to an AGS feature which maintains compatibility with 8-bit games. Therefore, if you draw onto the surface using a blue colour number 0-31 you will get a different number when you GetPixel – and in fact the colour drawn may not be what you expect. To get around this, add 1 Red or Green component to adjust the colour number out of this range.

NOTE: This command is relatively slow. Don't use it to try and process an entire image.

Exemple :
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
Display("The colour of the middle pixel is %d.", surface.GetPixel(160, 100));
surface.Release();

displays the pixel colour of the centre pixel on the screen.

Compatibility: Supported by AGS 3.0.1 and later versions.

Voir aussi : DrawingSurface.DrawingColor, DrawingSurface.DrawPixel, DrawingSurface.UseHighResCoordinates


Height property (drawing surface)

readonly int DrawingSurface.Height
Gets the height of the surface.

Exemple :
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
Display("The background is %d x %d!", surface.Width, surface.Height);
surface.Release();

displays the size of the surface to the player

Voir aussi : DrawingSurface.UseHighResCoordinates, DrawingSurface.Width


UseHighResCoordinates property

bool DrawingSurface.UseHighResCoordinates
Gets/sets whether you want to use high-resolution co-ordinates with this surface.

By default, this property will be set such that drawing surface co-ordinates use the same co-ordinate system as the rest of the game, as per the “Use low-res co-ordinates in script” game setting. However, if your game is 640×400 or higher you can customize whether this drawing surface uses native co-ordinates or the low-res 320×200 co-ordinates by changing this property.

Setting this property affects ALL other commands performed on this drawing surface, including the Width and Height properties.

Exemple :
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
surface.UseHighResCoordinates = true;
surface.DrawingColor = 14;
surface.DrawLine(0, 0, 320, 200);
surface.Release();

draws a yellow line from the top left of the screen to the middle of the screen. If we hadn't set UseHighResCoordinates to true, this would draw a line from the top left to the bottom right of the screen.

Voir aussi : DrawingSurface.DrawCircle, DrawingSurface.DrawLine, DrawingSurface.DrawRectangle, DrawingSurface.DrawTriangle


Width property (drawing surface)

readonly int DrawingSurface.Width
Gets the width of the surface.

Exemple :
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
Display("The background is %d x %d!", surface.Width, surface.Height);
surface.Release();

displays the size of the surface to the player

Voir aussi : DrawingSurface.Height, DrawingSurface.UseHighResCoordinates

 
ags50.1304280405.txt.gz · Dernière modification: 01/05/2011 22:06 par kitai
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki