- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
情况:我正在尝试在 MainMenu
类中使用 load_image
方法,因此在我的主类中我可以调用 load_image
方法,同时在主菜单中。
问题:在 load_image
方法中,我收到错误:
error C2440: 'return' : cannot convert from 'SDL_Surface' to 'SDL_Surface MainMenu::*'
这发生在第 47 行,用红色强调“optimizedImage”。
这是头文件:
#ifndef MAINMENU_H
#define MAINMENU_H
#include <iostream>
#include <string>
#include "SDL.h"
#include "SDL_image.h"
using namespace std;
class MainMenu
{
private:
string menuOption[3];
string background;
string img1;
string img2;
string img3;
SDL_Surface *screen;
SDL_Surface *bkgrnd;
SDL_Surface *item;
public:
MainMenu(SDL_Surface *screen, string bgImg, string optionImg1, string optionImg2, string optionImg3)
: background(bgImg), img1(optionImg1), img2(optionImg2), img3(optionImg3)
{
}
~MainMenu();
SDL_Surface *load_image(string filename);
void apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination);
bool load_files();
void Draw();
};
#endif
这是 .cpp 文件:
#include <iostream>
#include <string>
#include "MainMenu.h"
#include "glut.h"
#include "SDL.h"
#include "SDL_image.h"
MainMenu::~MainMenu()
{
}
SDL_Surface MainMenu::*load_image(string filename)
{
//Temporary storage for the image tgat loaded
SDL_Surface* loadedImage = NULL;
//The optimized image that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = IMG_Load(filename.c_str());
//If nothing went wrong in loading the image
if (loadedImage != NULL)
{
//Create an optimized image
optimizedImage = SDL_DisplayFormat(loadedImage);
//Free the old image
SDL_FreeSurface(loadedImage);
//if the image was optimized just fine
if (optimizedImage != NULL)
{
//Map the color key
Uint32 colorkey = SDL_MapRGB( optimizedImage->format,0,0xFF,0xFF);
//Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent
SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY, colorkey);
}
return optimizedImage;
}
return optimizedImage;
}
void MainMenu::apply_surface(int x, int y, SDL_Surface* source, SDL_Surface* destination)
{
SDL_Rect offset;
//Give the offsets to the rectangle
offset.x = x;
offset.y = y;
SDL_BlitSurface(source, NULL, destination, &offset);
}
bool MainMenu::load_files()
{
//Load images
item = load_image(img1);
bkgrnd = load_image(background);
if (item == NULL || bkgrnd == NULL)
{
return false;
}
return true;
}
void MainMenu::Draw()
{
apply_surface(0, 0, bkgrnd, screen);
apply_surface(320, 0, bkgrnd, screen );
apply_surface(0, 240, bkgrnd, screen );
apply_surface(320, 240, bkgrnd, screen );
apply_surface(180, 140, item, screen );
}
最佳答案
在您的 cpp 文件中,更改此内容:
SDL_Surface MainMenu::*load_image(string filename)
对此:
SDL_Surface* MainMenu::load_image(string filename)
函数的返回类型是SDL_Surface*
,不是SDL_Surface
关于c++ - 无法从 'SDL_Surface' 转换为 'SDL_Surface MainMenu::*',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18176520/
一段时间以来一直试图在网上找到它。 我有一个带有一些内容的 SDL_Surface(其中一个是文本,另一个是 Sprite 的一部分)。在游戏循环中,我可以很好地将数据显示在屏幕上。但是然后它再次循环
情况:我正在尝试在 MainMenu 类中使用 load_image 方法,因此在我的主类中我可以调用 load_image 方法,同时在主菜单中。 问题:在 load_image 方法中,我收到错误
我想将 SDL_Surface 加载到带有填充的 OpenGL 纹理中(以便 NPOT->POT),然后在表面上应用颜色键。我要么最终对所有像素进行颜色键控,不管它们的颜色如何,要么根本不对任何颜色进
所以我正在编写一个用表面表填充屏幕的代码;这是代码: main.c #ifdef __cplusplus #include #else #include #endif #include #inc
我在创建 SDL_Surface 的动态表时遇到困难。看看这段代码: SDL_Surface **testA = new SDL_Surface *[2]; for(int i=0;i<2;i++)
我可以通过这样做来释放我的 SDL_Surface* 冲浪吗: SDL_Surface* surf; for(int i = 0; i < 5; i++){ surf
有什么方法可以将 SDL 表面复制到另一个表面,例如创建备份拷贝,而无需在修改拷贝时修改原件? *surface = *original_surface 不工作。 SDL_Surface 没有任何构造
我想使用一个集合来引用一些 TileObjects(一个用户定义的类),这样我就可以遍历它们并采取相应的行动,或者找到一个特定的对象并将其删除,等等。 问题是,我想做的一件事是访问成员函数“rende
假设我有一个只有一张图片的 SDL_Surface。如果我想让 SDL_Surface 拥有该图像的三个拷贝,一个在另一个下面怎么办? 我想出了这个函数,但它没有显示任何东西: void Elemen
我一直在使用 sdl ttf,现在,我正在创建一个用于多行文本渲染的文本渲染器函数。 我正在为每条线创建一个表面,在“全局”表面中进行 blitting,然后将该“全局”表面转换为纹理。 实际上我的问
所以这是我的问题。我有一个 DrawMgr 类,我在其中调用 DrawCube 函数,我在另一个类的函数中调用 SDL_Surface。我的主要问题是,当我开始将鼠标移到我创建的窗口上时,它会出现段错
我正在使用 SDL 和 OpenGL。我使用 SDL ttf 创建带有文本的表面,然后使用该表面创建纹理。 我正在尝试将 alpha channel (不透明度)应用于文本,我正在使用这种方式:
在我的应用程序中,我需要从 SDL_Surface 返回鼠标的相对位置,问题是返回的鼠标位置是相对于 SDL 窗口而不是 SDL_Surface 的。我想我的问题是最简单/最有效的方法是什么。有任何问
源始终为 320x240,目标始终为 640x480。 void DoDoubleScaling(SDL_Surface* dest, SDL_Surface* source) { asser
我想将所有 SDL_Surface 初始化为一个函数,以便拥有最清晰的 main 可能,但它似乎不起作用。我这样做是这样的: void setImages(SDL_Surface* mur, SDL_
检查 SDL_LockSurface 函数的实现时我偶然发现了这个: /* This needs to be done here in case pixels changes value */ sur
我正在尝试使用 SDL 制作一个非常小且简单的片段。这个就像一个魅力: SDL_Window * window = SDL_CreateWindow("SDLTest", 0, 0, SCREEN_W
我正在尝试从 SDL_Surface 获取像素的 RGB/RGBA 颜色。我在互联网上找到了这段代码,但它返回了奇怪的数字(67372036 表示 0 红色、0 绿色、255 蓝色的像素) Uint3
我真的不知道哪里出了问题(主要是因为我不知道给我报错的那一行是干什么的)。 我认为我不必向您展示那么多代码。我正在做的是尝试获取像素的 RGBA 值以查看 Alpha 值有多大。我正在使用它来确定它们
运行我的小行星游戏几分钟后,代表我的飞船的 SDL_Surface 消失了。以某种方式保存船的旋转图像(rot)的表面被设置为 NULL。我不知道为什么!在我添加 if(rot != NULL &&
我是一名优秀的程序员,十分优秀!