SDL_Point
A structure that defines a two dimensional point.
该结构定义一个二维点
Data Fields 字段
| int | x | the x coordinate of the point |
|---|---|---|
| int | y | the y coordinate of the point |
Code Examples 代码示例
// Example program:// Using SDL_Point in some places of your code#include "SDL.h"#include <stdio.h>int main(int argc, char *argv[]) {SDL_Window *window;SDL_Point window_position = { // Position of windowSDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED};SDL_Point window_size = {640, 480}; // Size of windowSDL_Point mouse_position; // Mouse position coordsSDL_Init(SDL_INIT_VIDEO); // Initialize SDL2// Create an application window with the following settings:window = SDL_CreateWindow("SDL_Point usage", // window titlewindow_position.x, // initial x positionwindow_position.y, // initial y positionwindow_size.x, // width, in pixelswindow_size.y, // height, in pixelsSDL_WINDOW_OPENGL // flags - see below);// Check that the window was successfully madeif (window == NULL) {SDL_Log("Could not create window: %s", SDL_GetError());return 1;}SDL_GetMouseState( // Sets mouse_position to...&mouse_position.x, // ...mouse arrow coords on window&mouse_position.y);SDL_Log("Mouse position: x=%i y=%i", // Print mouse positionmouse_position.x, mouse_position.y);// Close and destroy the windowSDL_DestroyWindow(window);// Clean upSDL_Quit();return 0;}
Remarks 注意
An SDL_Point defines single two dimensional point. It can be used not only for points, but also for size. SDL_Point is used by SDL_EnclosePoints() to check if array of points is inside rectangle (SDL_Rect). You can also make your own functions using SDL_Point to simplify your code, it’s very helpful.
一个SDL_Point结构定义了一个二维的点。但它不仅可以用来表示点,也可以用来表示大小。SDL_Point也在函数SDL_EnclosePoints()中被用来检查一组点是否在一个矩形(SDL_Rect)之内。你也可以在你自己的函数中使用现成的SDL_Point来简化代码,这往往很有用。
