Thursday, 08 January 2009
 
  Home arrow Forum  
Main Menu
Home
News
Forum
Documentation
Download
Links
Administrator
Login Form
Welcome, Guest. Please login or register.
January 08, 2009, 10:03:38 AM
Username: Password:
Login with username, password and session length

Forgot your password?
sprites and matrixes?
DSLua Community
Welcome, Guest. Please login or register.
January 08, 2009, 10:03:38 AM
1724 Posts in 316 Topics by 10268 Members
Latest Member: sheemerpise
DSLua Community  |  General DS Programming Chats  |  Code Hashing  |  sprites and matrixes? « previous next »
Pages: [1]
Author Topic: sprites and matrixes?  (Read 1019 times)
angor
Waxing Crescent
**
Posts: 55


WWW
« on: April 25, 2006, 07:04:45 AM »

For the snoball game i am developing i am using matrixes for the snoball variables. This allows to create flexible code and to automatize tasks.

I tried to use the same technique with sprites, but DS LUA crashes without explanation Sad

1) sprite loading (works ->balls appear on screen)

   Sprite.LoadPalette( SCREEN_BOTTOM, PALETTE_BALL, "ball1x.pal" )
   BallFrames  = FrameStrip.Create( SCREEN_BOTTOM, 8, 8, "256" )
   BallFrames:LoadBin( "ball1x.raw", 1 )
   ball_spr = {}
   for i = 1,4*BALL_NMAX do
      ball_spr [ i ] = { Sprite.Create( BallFrames, 0, PALETTE_BALL, SCR_XMAX, SCR_YMAX ) }
   end

2)    ball variables are contained in other matrix (works -> verified by printing values on screen)
   ball = {}
   for i = 1,4*BALL_NMAX do
      ball  [ i ] = {player = 0, xpos=SCR_XMAX  ,  ypos=SCR_YMAX, dir=0, on=BALL_OFF  }
   end   

2) But when i try to redraw the sprites the system crashes!
    for i = 1,4*BALL_NMAX do
       ball_spr [ i ]:MoveTo( ball [ i ].xpos, ball [ i ].ypos )
    end

Note: the same ":Move" funtion works fine with sprites that are not values inside a matrix

Any idea of what i do wrong?

« Last Edit: April 25, 2006, 07:06:51 AM by angor » Logged
Zhen
Waxing Crescent
**
Posts: 57


WWW
« Reply #1 on: April 25, 2006, 03:13:01 PM »

I think that you need to use or:

1)

ball_spr [ i ] = Sprite.Create( BallFrames, 0, PALETTE_BALL, SCR_XMAX, SCR_YMAX )

or

2)

ball_spr [ i ][ 1 ]:MoveTo( ball [ i ].xpos, ball [ i ].ypos )

because if you put data in a matrix using table constructor without indices, Lua assigned it to 1,2.. an so on.

e.g:   mat = { a, b, c }    --[[ is the same that --]]  mat = { [1] = a, [2] = b, [3] = c }
   --[[ and it's the same that, --]]                          mat[1] = a   mat[2] = b   mat[3] = c

Zhen
Logged
waruwaru
Administrator
Waxing Crescent
*****
Posts: 94


« Reply #2 on: April 25, 2006, 03:27:20 PM »

Yep, I think Zhen got it.  In step 1, you created a sprite and kept it in a table.  In step 2, you reassign ball_spr to a new table without a sprite.  So, when you try to access the sprite in step 3, it no longer exists.

Thanks,
Waruwaru
Logged
angor
Waxing Crescent
**
Posts: 55


WWW
« Reply #3 on: April 26, 2006, 06:02:37 AM »

Thanks for the feedback. I have implemented it and it works fine!

BTW, have you tested the game yet? I have released the firts beta Smiley
Logged
Pages: [1]
« previous next »
    Jump to:  



    (C) 2009 DSLua

    DSLua - Best scripting language for Nintendo DS home-brew!