Skip to content

Commit

Permalink
Merge pull request #1699 from rcmaniac25/sprite_sample
Browse files Browse the repository at this point in the history
SpriteSample loads a majority of it's content from a .scene file.
  • Loading branch information
seanpaultaylor committed Jan 24, 2015
2 parents 4ed4ab6 + 32a313a commit f13c398
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 134 deletions.
4 changes: 3 additions & 1 deletion gameplay/src/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,14 @@ Sprite* Sprite::create(Properties* properties)
float heightPercentage = 0.0f;
if (properties->exists("width"))
{
if (properties->getType("width") == Properties::NUMBER) //TODO: Verify that this works for "100" but fails for "100%"
if (properties->getType("width") == Properties::NUMBER)
{
// Number only (200)
width = properties->getFloat("width");
}
else
{
// Number and something else (200%)
widthPercentage = properties->getFloat("width") / 100.0f;
}
}
Expand Down
2 changes: 1 addition & 1 deletion gameplay/src/TileSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ TileSet* TileSet::create(Properties* properties)
Vector2 cell;
Vector2 source;
if (tileProperties->getVector2("cell", &cell) && tileProperties->getVector2("source", &source) &&
(cell.x > 0 && cell.y > 0 && cell.x < set->_columnCount && cell.y < set->_rowCount))
(cell.x >= 0 && cell.y >= 0 && cell.x < set->_columnCount && cell.y < set->_rowCount))
{
set->_tiles[(int)cell.y * set->_columnCount + (int)cell.x] = source;
}
Expand Down
199 changes: 199 additions & 0 deletions samples/browser/res/common/sprites/sprite.scene
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
scene spriteSampleScene
{
// Width and height are expected to be 1280x720

node camera
{
camera
{
type = ORTHOGRAPHIC
nearPlane = 0
farPlane = 100

// zoomX default is game width
// zoomY default is game height
// aspectRatio default is game width / game height
}

// width and height are divided in half
translate = 640, 360, 0
}

// Background sprite
node background
{
sprite
{
path = res/common/sprites/background.png

// game width * 5
width = 6400
height = 720
}
}

// Level floor
node floor
{
tileset
{
path = res/common/sprites/level.png

tileWidth = 70
tileHeight = 70

rows = 3
columns = 7

tile
{
cell = 0, 0
source = 568, 284
}
tile
{
cell = 1, 0
source = 568, 284
}
tile
{
cell = 2, 0
source = 568, 284
}
tile
{
cell = 3, 0
source = 568, 284
}
tile
{
cell = 4, 0
source = 497, 284
}

tile
{
cell = 0, 1
source = 568, 0
}
tile
{
cell = 1, 1
source = 568, 0
}
tile
{
cell = 2, 1
source = 568, 0
}
tile
{
cell = 3, 1
source = 568, 0
}
tile
{
cell = 4, 1
source = 710, 142
}
tile
{
cell = 5, 1
source = 497, 284
}

tile
{
cell = 0, 2
source = 568, 0
}
tile
{
cell = 1, 2
source = 568, 0
}
tile
{
cell = 2, 2
source = 568, 0
}
tile
{
cell = 3, 2
source = 568, 0
}
tile
{
cell = 4, 2
source = 568, 0
}
tile
{
cell = 5, 2
source = 710, 142
}
tile
{
cell = 6, 2
source = 497, 284
}
}
}

node player
{
sprite
{
path = res/common/sprites/player1.png

width = 72
height = 97

source = 67, 196, 66, 92
frameCount = 13
}

// Position player at lower-left. Y position is floor's tileset height (tileHeight * rows)
translate = 0, 210, 0
}

node rocket
{
sprite
{
path = res/common/sprites/rocket.png

width = 128
height = 128

blendMode = BLEND_ADDITIVE
anchor = 0.5, 0.3
offset = OFFSET_ANCHOR
}

translate = 1280, 0, 0
rotate = 0, 0, 1, -45
}

node water
{
// Sprite drawable set in code because Effect isn't supported

translate = 0, -50, 0
}

node text
{
text
{
font = res/ui/arial.gpb

text = P1
size = 18
color = 0, 0, 1, 1
}
}

// Set active camera
activeCamera = camera
}
24 changes: 18 additions & 6 deletions samples/browser/sample-browser.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,6 @@
<ClInclude Include="src\WaterSample.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\ParticlesSample.h" />
<ClInclude Include="src\FontSample.h" />
<ClInclude Include="src\SpriteSample.h" />
<ClInclude Include="src\SceneCreateSample.h">
<Filter>src</Filter>
</ClInclude>
Expand All @@ -357,6 +354,15 @@
<ClInclude Include="src\AudioSample.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\FontSample.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\ParticlesSample.h">
<Filter>src</Filter>
</ClInclude>
<ClInclude Include="src\SpriteSample.h">
<Filter>src</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\MeshPrimitiveSample.cpp">
Expand Down Expand Up @@ -419,9 +425,6 @@
<ClCompile Include="src\WaterSample.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\ParticlesSample.cpp" />
<ClCompile Include="src\FontSample.cpp" />
<ClCompile Include="src\SpriteSample.cpp" />
<ClCompile Include="src\SceneCreateSample.cpp">
<Filter>src</Filter>
</ClCompile>
Expand All @@ -431,6 +434,15 @@
<ClCompile Include="src\AudioSample.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\FontSample.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\ParticlesSample.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="src\SpriteSample.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Image Include="res\common\terrain\dirt.dds">
Expand Down
Loading

0 comments on commit f13c398

Please sign in to comment.