x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 

ASpriteCE 1.6.05

Freeware
ASpriteCE has over 60 methods, properties and events to handle nearly every aspect of a 2D game.
Category(s):
You must be registered and logged into HPC:Factor in order to contribute to the SCL.

Description

ASpriteCE has over 60 methods, properties and events to handle nearly every aspect of a 2D game. As a quick introduction to the control, we'll define an animated sprite and display it over a background.



We'll use the starfield at left as a background and animate the "star" sprite above. Note that the star sprite consists of 8 frames - each 16x15 pixels in size.

1. To begin, create a new eVB project and save it to an empty directory. Save the "backdrop.jpg" and "star.gif" images above to the same directory (you can right-click the images above and choose "Save Picture As...")

2. Add the ASpriteCE Game Control to the eVB Toolbox by right-clicking the toolbox and selecting "Components...", then select "ASpriteCE Game Library." This will add the ASpriteCE icon to your toolbox. Select the ASpriteCE icon in the toolbox and then paint the control onto Form1.

3. Add the following code to the Form1 code window. DrawInit is used to initialize the control, passing the window handle of Form1. Note that zero's are passed for the CustomWidth and CustomHeight properties - this is because we are not implementing scrolling. After using DrawSetDrawColor to set the draw color to white, we use TextDisplay to draw some text to the background. Our star sprite is defined and the animation rate is set using SpriteDefine and SpriteFrameRate (see comments). Finally, the control's timer is set to do 20 fps using TimerStartTimer .

Const SPRITE_STAR = 0
Private Sub Form_Load()
Game1.DrawInit Form1.hWnd, 0, 0
Game1.DrawBackgroundImage App.Path & "\backdrop.jpg", 0, 0
Game1.DrawSetDrawColor 255, 255, 255
Game1.TextDisplay "Hello, ASprite!!!", 0, 0, True, True
' define the star sprite - each frame is 16x15, there are 8 frames
' and 8 frames per row (1 row of frames).
Game1.SpriteDefine SPRITE_STAR, App.Path & "\star.gif", 0, 0, 16, 15, 8, 8
Game1.SpriteSetPosition SPRITE_STAR, 20, 20
Game1.SpriteFrameRate(SPRITE_STAR) = 1
' start the timer, 20 frames-per-second
Game1.TimerStartTimer (50)
End Sub

4. OK, we're all ready to try the application! Select File/Make from the eVB menu, then save your .vb program along with backdrop.jpg and star.gif to a directory on your device. Then start the vb program on the device. You should see the star "spinning" on the background with the message "Hello, ASprite!" next to it.


Moving Sprites and Detecting Collisions

To move a sprite, use the SpriteSetDirection method:

Game1.SpriteSetDirection lSpriteNum, iAngle, iVelocity

iAngle is a value from 0 to 359 degrees, with 0 degrees pointing right at the 3 o'clock position. iVelocity is the number of pixels the sprite will be moved for each TimerFired event (as set by TimerStartTimer)

When the movement of two sprites causes them to collide, the control fires a SpriteCollision event, passing the lSpriteNum identifiers of the two sprites involved in the collision. In some cases, you may also want to detect when the stylus is tapped or moved over a sprite - use the SpriteCollisionMouse event for this.

The iAngle Parameter for SpriteSetDirection is depicted above.


Getting Input from the User

ASpriteCE makes button and stylus input easy to implement through these events:

Event Fired When...
InputMouseDown stylus is tapped to the screen
InputMouseReleased stylus is lifted from the screen
InputMouseMove stylus is moved across the screen
InputKeyPressed a button is pressed by the user
InputKeyReleased a button is released by the user

Let's add functionality to our example that makes our sprite move in the direction of the stylus when the stylus is tapped on the screen. We'll create a MoveStarTowardsPoint method that directs the star sprite towards a specific x,y coordinate. The UtilGetAngleBetween method is used to calculate the angle between the sprite's current position and the desired location. We call the MoveStarTowardsPoint method from the InputMouseDown and InputMouseMove events to handle mouse input. Finally, the InputMouseUp, SpriteCollisionEdge and SpriteCollisionMouse events are used to stop movement of the sprite.

Private Sub MoveStarTowardsPoint(ByVal x As Long, ByVal y As Long)
' move the sprite towards a coordinate
Dim iAngle As Integer, iXPosStar As Integer, iYPosStar As Integer
Game1.SpriteGetPositionEx SPRITE_STAR, 8, iXPosStar, iYPosStar
iAngle = Game1.UtilGetAngleBetween(iXPosStar, iYPosStar, x, y)
Game1.SpriteSetDirection SPRITE_STAR, iAngle, 4
End Sub
Private Sub Game1_InputMouseDown(ByVal x As Long, ByVal y As Long)
MoveStarTowardsPoint x, y
End Sub
Private Sub Game1_InputMouseMove(ByVal x As Long, ByVal y As Long)
MoveStarTowardsPoint x, y
End Sub
Private Sub Game1_InputMouseUp(ByVal x As Long, ByVal y As Long)
Game1.SpriteSetDirection SPRITE_STAR, 0, 0
End Sub
Private Sub Game1_SpriteCollisionMouse(ByVal lSpriteNum As Long, _
ByVal x As Long, ByVal y As Long, ByVal bOnMouseMove As Long)
Game1.SpriteSetDirection SPRITE_STAR, 0, 0
End Sub

Distributing Your Game
The ASpriteCE Game Control integrates well with the eVB "Application Install Wizard" to easily create a setup for your application. Simply follow the wizard through to completion (the wizard is under the Tools/Remote Tools menu of eVB) and ASpriteCE will be shipped in the CAB files for each processor. There are some important things to note, however:

- there is a bug in the eVB Application Install Wizard that will unregister a device's VB runtime files on uninstall. One way around this is to simply not include the VB runtime in Step 7 of the wizard, as it already exists in the ROM of most devices.

- assigning an icon to your eVB application is not easy - see this MSDN article for details on how to do it.

- as stated earlier, ASpriteCE relies on the ATLCE300.DLL and GX.DLL. You will want to ship these with your application as well in case the target device does not already have them.

What's Next?
As you can see, ASpriteCE greatly simplifies the creation of sprite-based multimedia games in eVB. This quick introduction hopefully got you well on your way to creating your next great game. As a next step, check out the code samples that ship with the control, including a fully developed tiled game that demonstrates almost every aspect of the control.

Installation Instructions

Installing the Control

1. Download the ASpriteCE setup program and extract the ZIP contents to a folder.

2. Run install.vbs by double-clicking it. This will add required registry entries for ASpriteCE.

3. ASpriteCE depends on atlce300.dll and gx.dll. If they're not in your \Windows directory, add them. Atlce300.dll is shipped with Microsoft Embedded Visual Tools - in \Windows CE Tools\wce300\MS Pocket PC\. Gx.dll is part of the Game API (GAPI) can be downloaded from this Microsoft Download Page.

4. Add ASpriteCE to your device using the Control Manager.

- In eVB, select Tools/Remote Tools/Control Manager.

- Select your PocketPC device in the left pane then select Control/Add New Control.

- Browse to the folder you unzipped in step 1, then to the "bin" subfolder. Select the DLL version for your processor.

Tags

DLLStubdevelopmentlibrary

   
License Freeware
The program is completely free to use.
   
Website http://www.spritehand.com/
Not working? Try this website on the WayBack Machine
   
Popularity 2671
Total Downloads  0
   
Submitted By torch
Submitted On 19 January 2023

Comments

No comments have been submitted against this application. Be the first!

You must be signed-in to post comments in the SCL. Not registered? Join our community.

Software Compatibility List: The SCL is provided for free to the Handheld PC Communty and we do not carry advertising to support our services. If you have found the SCL useful, please consider donating.