Re: Image Not Appearing
- Posted by jimcbrown (admin) Dec 21, 2011
- 1962 views
EDIT: I made it an object, now I get the error, sequence lengths are not the same (4 != 5). What does that mean?
Means you should use equal(). I argued for getting rid of that "error" years ago, and i was disregarded. I thought it had been obsoleted in v4, but apparently not.
useless
I'm still a bit confused. Anyone able to show me what exactly I'm doing wrong with my code?
The error reported is the lengths of the sequences you are comparing using "=" . Euphoria has never liked to do that, and i learned early on to never use "=" to compare sequences. Euphoria has functions to do comparisons: equal() and compare(). Look them up in your favorite version of the Eu help files.
Basically, change code like
if screen = Screens[1]
to
if equal(screen,Screens[1])
If you are needing < or > for stuff and getting errors, use compare(). Other that that, all i can do is copy/paste the manual to you here in the forum, which i don't want to do.
useless
without warning without type_check include std/get.e include std/sort.e include std/rand.e include std/math.e include std/mathcons.e include std/eds.e include std/filesys.e include std/wildcard.e include Sdl_Wrap.ew include SDL_image.ew constant TRUE = 1 constant FALSE = 0 constant MAX_HEALTH = 100 constant MAX_LIVES = 3 constant ENEMY_LIVES = 1 constant MAX_WIDTH = 800 constant MAX_HEIGHT = 600 constant MAX_DEPTH = 32 atom dummy atom surface,buffer atom keyState,curKey,prevKey atom run atom title,logo --gfx atom ship,missle,enemy --gfx atom backdrop --gfx atom shiprect,misslerect,enemyrect --rects integer shipx,shipy,shipwidth,shipheight integer misslex,missley,misslewidth,missleheight integer enemyx,enemyy,enemywidth,enemyheight atom shipvelx,shipvely atom enemyvelx,enemyvely atom misslevelx,misslevely atom format integer Missle_Fired = FALSE atom health = MAX_HEALTH atom lives = MAX_LIVES atom score sequence sTitle = "4000 A.D. - Geek Punk Games" sequence sIcon = "" integer enemypoints integer ticks,last_tick atom deltatime sequence Screens = {"Logo","Title","Game"} object screen procedure CalcRect(atom rect, integer sx, integer sy, integer tx, integer ty) poke(rect,and_bits(sx,255)) poke(rect+1,floor(sx/256)) poke(rect+2,and_bits(sy,255)) poke(rect+3,floor(sy/256)) poke(rect+4,and_bits(tx,255)) poke(rect+5,floor(tx/256)) poke(rect+6,and_bits(ty,255)) poke(rect+7,floor(ty/256)) end procedure procedure Init() dummy = SDL_Init(SDL_INIT_EVERYTHING) if dummy = -1 then puts(1,"Could not init SDL") end if surface = SDL_SetVideoMode(MAX_WIDTH,MAX_HEIGHT,MAX_DEPTH,SDL_HWSURFACE) SDL_WM_SetCaption(sTitle,sIcon) format = peek4u(surface+4) shiprect = allocate(16) enemyrect = allocate(16) misslerect = allocate(16) title = IMG_LoadJPG("Title.jpg") logo = IMG_LoadJPG("Logo.jpg") backdrop = IMG_LoadJPG("Backdrop.jpg") ship = IMG_LoadJPG("Ship.jpg") enemy = IMG_LoadJPG("Enemy.jpg") missle = IMG_LoadJPG("Missle.jpg") --get rid of background color on image(the whitespace) dummy = SDL_SetColorKey(ship,SDL_SRCCOLORKEY,SDL_MapRGB(format,255,255,255)) if dummy = -1 then puts(1,"Could not apply color key") end if dummy = SDL_SetColorKey(enemy,SDL_SRCCOLORKEY,SDL_MapRGB(format,255,255,255)) if dummy = -1 then puts(1,"Could not apply color key") end if dummy = SDL_SetColorKey(missle,SDL_SRCCOLORKEY,SDL_MapRGB(format,255,255,255)) if dummy = -1 then puts(1,"Could not apply color key") end if end procedure procedure Run() run = 1 screen = Screens[1] while run = 1 do ticks = SDL_GetTicks() SDL_PumpEvents() keyState = SDL_GetKeyState(NULL) if peek(keyState+SDLK_ESCAPE) > 0 then run = 0 end if dummy = SDL_BlitSurface(logo,NULL,surface,NULL) if dummy = -1 then puts(1,"Could not blit surface") end if if peek(keyState+SDLK_RETURN) > 0 and equal(screen,Screens[1]) then screen = Screens[2] end if if equal(screen,Screens[2]) then dummy = SDL_BlitSurface(title,NULL,surface,NULL) if dummy = -1 then puts(1,"Could not blit surface") end if end if end while end procedure procedure Quit() SDL_FreeSurface(ship) SDL_FreeSurface(enemy) SDL_FreeSurface(missle) SDL_FreeSurface(title) SDL_FreeSurface(logo) SDL_FreeSurface(backdrop) free(shiprect) free(enemyrect) free(misslerect) SDL_Quit() end procedure Init() Run() Quit()
Alright, this is my modified code, still not showing the image.
Here's what I had to do to get this modified code to run. First I tracked down SDL_IMAGE.ZIP from the archives and downloaded it. Then it wouldn't run because it couldn't find SDL_image.dll (? I changed it to use the Linux version of the libraries in /usr/lib and then I got machine exceptions when calling SDL_SetColorKey(). No idea why this happened, so I just commented the calls out.
Then I saw lots of errors blitting, and after some work (adding SDL_Error() calls as well as the x/y stuff to prevent the screen from spamming me with errors) I realized that it was because those images were null - because the .jpgs didn't exist.
I quickly copied some jpegs with the right names. No more errors but nothing showed up. At this point I found a good cplusplus guide to SDL, http://gameprogrammingtutorials.blogspot.com/2010/01/sdl-tutorial-series-part-4-how-to-load.html. and saw the missing SDL_Flip() call.
Once I added that in, everything works (at least for me).
I feel bitter.