全局阵列无法按我认为的方式工作 [英] Global Array is not working the way i think it should

查看:56
本文介绍了全局阵列无法按我认为的方式工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我使用Dragonfire SDK开发了15个益智游戏.
我将拼图盒的图像存储在一个整数数组中,但是当我尝试显示盒子的图像时,屏幕上会出现红色框,而不是原始图像,这意味着该图像未加载(或间接加载了图片不存在)..背景已正确加载..
继承人的代码,请帮助

Hello everyone, im using Dragonfire sdk to develop 15 puzzle Game.
i''m storing the images of the puzzle boxes in an integer array, but when i try to display the images of boxes, red box appears on the screen instead of the the original image which means the image is not loaded (or indirectly the image doesn''t exist).. the background is loaded properly..
heres the code please help

//===============================================
#include "DragonFireSDK.h"
//===============================================

#define MAXROWS 4
#define MAXCOLS 4

//===============================================

int boxes[15] = {	 ImageAdd("Assets/1.png"),
					ImageAdd("Assets/1.png"),
					ImageAdd("Assets/3.png"),
					ImageAdd("Assets/4.png"),
					ImageAdd("Assets/5.png"),
					ImageAdd("Assets/6.png"),
					ImageAdd("Assets/7.png"),
					ImageAdd("Assets/8.png"),
					ImageAdd("Assets/9.png"),
					ImageAdd("Assets/10.png"),
					ImageAdd("Assets/11.png"),
					ImageAdd("Assets/12.png"),
					ImageAdd("Assets/13.png"),
					ImageAdd("Assets/14.png"),
					ImageAdd("Assets/15.png")
					};

//===============================================

struct board {
	int grid[MAXROWS][MAXCOLS];
	int posx;
	int posy;
	int image;
	int view;
} base;

//===============================================

struct box {
	int posx;
	int posy;
	int image;
	int view;
	int id;
	box *up;
	box *down;
	box *left;
	box *right;
} *head , *temp , *p ;

//===============================================

void InitializeBoard(){
	base.image = ImageAdd("Assets/BG+F.png");
	base.posx = 0;
	base.posy = 0;
	base.view = ViewAdd(base.image, base.posx, base.posy);


	head = 0;
}

void InitializeBoxes(){
	for (int count = 0; count<15 ; count++)
	
	{
		if (head == 0 && count == 0)
		{
			temp = new box;
			temp->posx = 22 ;
			temp->posy = 132 ;
			temp->image = boxes[count] ;
			temp->view = ViewAdd(temp->image, temp->posx, temp->posy) ;
			temp->id = count ;
			temp->up = 0 ;
			temp->left = 0 ;
			temp->right = 0 ;
			temp->down = 0 ;
		}


	}

}

void AppMain()
{
	InitializeBoard();
	InitializeBoxes();
}


//===============================================

void OnTimer()
{

}

//===============================================

推荐答案

在此:
http://dragonfiresdk.wikispaces.com/ImageAdd%28char+*filename%29 [ ^ ]

我可以看到您要完成的事情,而您做错了所有事情.我以为你不懂C ++?您不能像这样动态声明和加载数组,它不能那样工作.您必须声明它,然后在运行时在函数中加载它.
From looking at this:
http://dragonfiresdk.wikispaces.com/ImageAdd%28char+*filename%29[^]

I can see what you''re trying to accomplish, and you''re doing it all wrong. I''m thinking you don''t know C++? You can''t declare and load an array dynamically like that, it doesn''t work that way. You have to declare it then load it at run-time in a function.


问题在这里,您尚未初始化i的值.

这是您更新的代码.

Problem here is, you have not initialized value of i.

Here is your updated code.

int array1 [5] = {1,2,3,4,5};

initialize()
{
int x;
for(int i=0; i<5;i++)
x=array1[i];
}


@all回答
谢谢大家,但我发现你们所有人都没有鼓励,反而让您感到答案很粗鲁.
我只是一个16岁的小伙子试图学习编码..但也许我应该退出:/
@all who replied
thanks guys but i found none of you encouraging rather i felt rudeness of tone in your answers..
im just a 16 years old guy trying to learn coding.. but may be i should just quit :/


这篇关于全局阵列无法按我认为的方式工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆