Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Getting sprite from Spritesheet


tslusny
 Share

Recommended Posts

Nevermind, fixed it. Correctly it should look like this:

```

Public Function GetSprite(ByVal Sprite As Long, ByVal Spritesheet As Long)

Dim firstsprite As Long

If Sprite <= 8 Then

GetSprite = Sprite

Exit Function

Else

firstsprite = 8 * (Spritesheet - 1)

GetSprite = Sprite - firstsprite

End If

End Function
```

Hello all ![:)](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/smile.png) Ik that i should know this, but i really do not like maths ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png)

So what i am trying to do?

This is my function:

```

Public Function GetSpriteFromSpritesheet(ByVal Sprite As Long, ByVal Spritesheet As Long)

If Sprite <= 8 Then

GetSpriteFromSpritesheet = Sprite

Exit Function

Else

GetSpriteFromSpritesheet = Sprite / Spritesheet

End If

End Function

```

**Example values passed into:**

Sprite: 256

Spritesheet: 32

Result is: 8

This above value is perfectly correct, but when i put for example this:

Sprite: 255

Spritesheet: 32

Result is: 7,96875

This above value should be 7 and not 7,96875.

**What i am doing wrong?**
Link to comment
Share on other sites

Nevermind, fixed it. Correctly it should look like this:

```

Public Function GetSprite(ByVal Sprite As Long, ByVal Spritesheet As Long)

Dim firstsprite As Long

If Sprite <= 8 Then

GetSprite = Sprite

Exit Function

Else

firstsprite = 8 * (Spritesheet - 1)

GetSprite = Sprite - firstsprite

End If

End Function
```
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...