Monday 9 April 2012

Object List - Test Objects

To test the object and sprite creation functions, we replace the old test code we had

testSprite = createSprite( IconImage() )
setSpriteSize( testSprite , IconSize() , - 1)
setSpritePosition( testSprite , 100 , 100 )
setSpriteDepth( testSprite , DEPTH_WORK )
setSpriteAnimation( testSprite , 64 , 64 , 252 )

with some new test code

testObject1 = AddWorkObject( 1 , 0 )
CreateWorkObjectSprite( Object1 , 100 , 100 )

The first line uses variable testObject1 to store the array position of the new object, it uses 1 for the object ID which will use frame 1, and it uses 0 for the sprite reference - indicating it does not have a sprite assigned at this stage.

The second line creates a new sprite for testObject1 and positions it at 100,100 on the workspace.

We can add a second object using the following (immediately after)

testObject2 = AddWorkObject( 10 , 0 )
CreateWorkObjectSprite( Object2 , 200 , 200 )

I have used 10 here for the object number so it shows this is separate from the array position.  The result is stored in the variable testObject2.

Now we need to remove the following lines from the main loop

testFrame = testFrame + 1
if testFrame = 253 then testFrame = 1
setSpriteFrame( testSprite , testFrame )

which are no longer needed.  Compiling and running the project should produce.
Which shows testObject1 using frame 1 and testObject2 using frame 10 in their correct positions.

No comments:

Post a Comment