Getting started - Introduction - Installing Defold - The editor - Glossary - Defold for Flash users - Getting help Project setup - Creating a project - Project settings - Libraries Core concepts - Building blocks - Addressing - Message passing - Application lifecycle Assets and resources - Importing assets - Importing 2D graphics - Importing 3D models - Adapting to different screen sizes - Live update - Atlas - Font - Resource management - Tile source - Texture filtering - Texture profiles Animations - Overview - Flipbook Animation - Model animation - Property animation (tweens) - Spine animation Components - Overview - Collection factory - Collection proxy - Collision object - Camera - Factory - Label - Mesh - Model - Particle FX - Sound - Spine - Sprite - Tilemap Gui - GUI overview - Box nodes - Text nodes - Pie nodes - Spine nodes - ParticleFX nodes - Template nodes - Scripts - Clipping - Layouts Physics - Physics overview - Collision objects - Collision shapes - Collision groups - Collision messages - Resolving collisions - Ray casts - Joints and constraints Sound - Sound - FMOD Input - Overview - Key and text input - Mouse and touch - Gamepads Game logic - Scripts - Properties - Script properties - Lua in Defold - Modules - Debugging - Writing code Saving and loading files - Working with files Networking - Overview - HTTP Requests - Socket connections - WebSocket connections - Online services Rendering - Render - Material - Shader - Texture filtering Workflow - Adapting to different screen sizes - Bundling an application - Bob the builder - Hot reloading - Optimizing an application - Profiling - Refactoring - The mobile dev app - Version control - Writing code - Working offline Debugging - Debugging game logic - Debugging native code - Debugging native code on Android - Debugging native code on iOS - Reading game and system logs - Profiling Platforms - Android - iOS - Nintendo Switch - Linux - HTML5 - macOS - Windows Monetization - Ads - In-app purchases - Web Monetization Extensions - Advertising Info - Camera - Facebook - Facebook Instant Games - Firebase Analytics - Google Play Game Services - Google Play Instant - In-app purchases - Inter-app communication - Push notifications - App review and ratings - WebMonetization - WebSocket - Webview Native extensions - Introduction - Details - Defold SDK - Adding auto-complete definition - Best Practices - Debugging - Build Variants - Manifest Merging Editor extensions - Editor scripts
Read this manual in English
Sprites
Sprite 组件可以是屏幕上显示的简单图片或者逐帧动画.
Sprite 组件使用 图集 或者 瓷砖图源 进行图像显示.
Sprite 属性
除了 Id , Position 和 Rotation 还有如下属性:
Image
sprite所使用的图集或者瓷砖图源资源.
DefaultAnimation
sprite的默认动画.
Material
sprite的渲染材质.
Blend Mode
组件渲染时使用的混合模式.
混合模式
The Blend Mode property defines how the component graphics should be blended with the graphics behind it. These are the available blend modes and how they are calculated:
Alpha
Normal blending: src.a * src.rgb + (1 - src.a) * dst.rgb
Add
Brighten the background with the color values of the corresponding pixels of the component: src.rgb + dst.rgb
Multiply
Darken the background with values of the the corresponding pixels of the component: src.rgb * dst.rgb
运行时操作
运行时可以使用各种各样的函数和属性 (参见 API 文档 )来控制Sprite. 函数:
sprite.play_flipbook()
- 在sprite组件上播放动画.
sprite.set_hflip()
和 sprite.set_vflip()
- 翻转Sprite动画.
还可以使用 go.get()
和 go.set()
来控制Sprite:
cursor
初始化动画播放头 (number
).
image
sprite图 (hash
). 可以通过 go.set()
方法使用图集或者瓷砖图集资源来修改此属性. 请参考 这个例子的 API 文档 .
material
sprite材质 (hash
). 可以通过 go.set()
方法使用材质资源来修改此属性. 请参考 这个例子的 API 文档 .
playback_rate
动画播放速率 (number
).
scale
Sprite缩放 (vector3
).
size
Sprite大小 (vector3
) (只读).
材质常量
The default sprite material has the following constants that can be changed using go.set() or go.animate() (refer to the Material manual for more details ). Examples:
go . set ( "#sprite" , "tint" , vmath . vector4 ( 1 , 0 , 0 , 1 ))
go . animate ( "#sprite" , "tint" , go . PLAYBACK_LOOP_PINGPONG , vmath . vector4 ( 1 , 0 , 0 , 1 ), go . EASING_LINEAR , 2 )
tint
3D网格颜色 (vector4
). 四元数 x, y, z, 和 w 分别对应红, 绿, 蓝和不透明度.
相关项目配置
在 game.project 文件里有些关于Sprite的 设置项目 .