Jump to content
IGNORED

Small tip when declaring sprite constants


Recommended Posts

Hi all,

 

I've changed the way I declare my sprite constants in my code.

 

Instead of like the examples;

' particle/text layer 0
DIM background% :background=1
DIM water% :water=2
DIM poulpe1% :poulpe1=3
DIM poulpe2% :poulpe2=4
DIM poulpe3% :poulpe3=5
DIM poulpe4% :poulpe4=6

 

 

Do this;

' particle/text layer 0
DIM background% :background=1
DIM water% :water=background+1
DIM poulpe1% :poulpe1=water+1
DIM poulpe2% :poulpe2=poulpe1+1
DIM poulpe3% :poulpe3=poulpe2+1
DIM poulpe4% :poulpe4=poulpe3+1
The outcome of doing it the second way, is if you need to add a sprite in the middle of your list, you don't have to adjust all the following variables. You just have to put your sprite declaration in the middle and +1 from the one before it. Then adjust the one after it to +1 from your new variable
Once you have lots of sprites, this really helps speed things up. It's also less error prone.

Example after inserting a new sprite;

' particle/text layer 0
DIM background% :background=1
DIM water% :water=background+1
DIM poulpe1% :poulpe1=water+1
DIM NEWSPRITE% : NEWSPRITE=poulpe1+1
DIM poulpe2% :poulpe2=NEWSPRITE+1
DIM poulpe3% :poulpe3=poulpe2+1
DIM poulpe4% :poulpe4=poulpe3+1
Hope this helps
  • Like 4
Link to comment
Share on other sites

 

Hi all,

 

<snip>

 

Hope this helps

 

 

That is a top tip. We tried to make some sensible use of ENUM, but it never quite worked out and always seemed like a chore and not as foolproof as it might have been (thanks to Raptor's way of declaring multiple objects of same type) - your way could get around this fairly easily, good stuff. I think it's probably time to update some of the tutorials :0) (although maybe I'm a little worried that it might be confusing to an absolute beginner, hmmmm... but it's definitely worthy of mention in the "working with rB+" section!)

 

I know I'll be doing it your way from now on at least, cheers.

Edited by sh3-rg
Link to comment
Share on other sites

 

That is a top tip. We tried to make some sensible use of ENUM, but it never quite worked out and always seemed like a chore and not as foolproof as it might have been (thanks to Raptor's way of declaring multiple objects of same type) - your way could get around this fairly easily, good stuff. I think it's probably time to update some of the tutorials :0)

It also helps if you have multiple sprites defined for 1 sprite in the object list.

 

Then in code for the following sprite declaration you can do something like NEWSPRITE+16 and so on. Or NEWSPRITE+NUMBEROFBADDIESCONST where NUMBEROFBADDIESCONST=16

Edited by Sporadic
  • Like 1
Link to comment
Share on other sites

It also helps if you have multiple sprites defined for 1 sprite in the object list.

 

Then in code for the following sprite declaration you can do something like NEWSPRITE+16 and so on. Or NEWSPRITE+NUMBEROFBADDIESCONST where NUMBEROFBADDIESCONST=16

 

Exactly, it makes more sense at that point as it's not such a special case anymore.

 

Going to add your info as a page on the site now, thanks again.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...