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 代码示例

  1. // Example program:
  2. // Using SDL_Point in some places of your code
  3. #include "SDL.h"
  4. #include <stdio.h>
  5. int main(int argc, char *argv[]) {
  6. SDL_Window *window;
  7. SDL_Point window_position = { // Position of window
  8. SDL_WINDOWPOS_CENTERED,
  9. SDL_WINDOWPOS_CENTERED
  10. };
  11. SDL_Point window_size = {640, 480}; // Size of window
  12. SDL_Point mouse_position; // Mouse position coords
  13. SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
  14. // Create an application window with the following settings:
  15. window = SDL_CreateWindow(
  16. "SDL_Point usage", // window title
  17. window_position.x, // initial x position
  18. window_position.y, // initial y position
  19. window_size.x, // width, in pixels
  20. window_size.y, // height, in pixels
  21. SDL_WINDOW_OPENGL // flags - see below
  22. );
  23. // Check that the window was successfully made
  24. if (window == NULL) {
  25. SDL_Log("Could not create window: %s", SDL_GetError());
  26. return 1;
  27. }
  28. SDL_GetMouseState( // Sets mouse_position to...
  29. &mouse_position.x, // ...mouse arrow coords on window
  30. &mouse_position.y
  31. );
  32. SDL_Log("Mouse position: x=%i y=%i", // Print mouse position
  33. mouse_position.x, mouse_position.y
  34. );
  35. // Close and destroy the window
  36. SDL_DestroyWindow(window);
  37. // Clean up
  38. SDL_Quit();
  39. return 0;
  40. }

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来简化代码,这往往很有用。

Related Structures 相关结构

SDL_Rect

Related Functions 相关函数

SDL_EnclosePoints()