我打算用javascript/canvas编写一个游戏,我只有一个问题:在加载图像和使用canvas方法绘图时,我应该考虑哪些性能考虑因素.因为我的游戏将使用非常简单的艺术几何(圆形,正方形,线条),所以这两种方法都很容易使用.我还计划在游戏中实现一个简单的粒子引擎,所以我希望能够在不受性能影响的情况下绘制大量的小对象.
思考?
我只是想知道如何转换SDL_Surface(通过IMG_Load从png加载)并将其粘贴在四边形上.这就是我所拥有的(大多数只是从我发现的教程中粘贴的复制品).
#include "SDL.h"
#include "SDL_opengl.h"
#include "SDL_image.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
SDL_Surface *screen;
// Slightly different SDL initialization
if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new*
screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ); // *changed*
if ( !screen ) {
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}
// Set the OpenGL state after creating the context with SDL_SetVideoMode …Run Code Online (Sandbox Code Playgroud)