- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在lynda.com上关注一个教程,其中详细介绍了如何为八哥游戏添加声音(如果您有Lynda,则由Lee Brimelow制作)。在教程中,他像这样将声音嵌入Assets.as类中
[Embed(source="../media/sounds/laser-shot-silenced.mp3")]
private static var LaserSound:Class;
public static var LaserSFX:Sound;
[Embed(source="../media/sounds/mariah-carey-dubstep.mp3")]
private static var Track1:Class;
public static var Track1SFX:Sound;
public static function init():void
{
skyTexture = Texture.fromBitmap(new sky());
ta = new TextureAtlas(Texture.fromBitmap(new atlas()),
XML(new atlasXML()));
TextField.registerBitmapFont(new BitmapFont(Texture.fromBitmap(new komaka()),
XML(new komikaXML()));
LaserSFX = new LaserSound();
Track1SFX = new Track1();
}
public function initialize():void
{
LaserSFX = new LaserSound();
Track1SFX = new Track1();
import Assets;
import com.reyco1.physinjector.PhysInjector;
import com.reyco1.physinjector.data.PhysicsObject;
import com.reyco1.physinjector.data.PhysicsProperties;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.utils.Dictionary;
import objects.Enemy;
import objects.GameBackground;
import objects.Laser;
import objects.Scarlet;
import objects.SnowBall;
import Assets;
import starling.core.Starling;
import starling.display.Button;
import starling.display.Image;
import starling.display.Sprite;
import starling.events.Event;
import starling.events.Touch;
import starling.events.TouchEvent;
import starling.events.TouchPhase;
import starling.utils.deg2rad;
public class InGame extends Sprite
{
private var startBtn:Button;
private var replayBtn:Button;
private var gameOver:Image;
private var bg:GameBackground;
private var scarlet:Scarlet;
private var enemies:Array;
private var lasers:Array;
private var presents:Array;
private var lasersLayer:Sprite;
private var enemiesLayer:Sprite;
private var enemySpawnDelay:Number;
private var enemySpawnCounter:Number;
private var difficulty:Number;
private var difficultyRate:Number;
private var gameState:String;
private var playerSpeed:Number;
private const MIN_SPEED:Number = 650;
private var gameArea:Rectangle;
private var touchArea:Rectangle;
private var shape:starling.display.Sprite = new starling.display.Sprite();
private var target:Point = new Point(100, 100);
private var touch:Touch;
private var touchX:Number;
private var touchY:Number;
protected var sack:Image;
protected var physics:PhysInjector;
private var paused:Boolean = true;
public function InGame()
{
super();
this.addEventListener(starling.events.Event.ADDED_TO_STAGE, onAddedToStage);
}
private function onAddedToStage(event:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
drawGame();
}
private function drawGame():void
{
presents = new Array();
bg = new GameBackground();
this.addChild(bg);
gameOver = new Image(Assets.getTexture("GameOver"));
gameOver.x = 83;
gameOver.y = 130;
this.addChild(gameOver);
scarlet = new Scarlet;
scarlet.x = stage.stageWidth/2;
scarlet.y = stage.stageHeight/2;
this.addChild(scarlet);
setChildIndex(scarlet, 2)
startBtn = new Button(Assets.getTexture("PlayBtn"));
startBtn.x = stage.stageWidth * 0.5 - startBtn.width * 0.5;
startBtn.y = stage.stageHeight * 0.5 - startBtn.height * 0.5 + 35;
this.addChild(startBtn);
replayBtn = new Button(Assets.getTexture("ReplayBtn"));
replayBtn.x = 393;
replayBtn.y = 287;
this.addChild(replayBtn);
//defines area scarlet can fly in
gameArea = new Rectangle(0, 15, stage.stageWidth, stage.stageHeight - 150);
PhysInjector.STARLING = true;
physics = new PhysInjector(Starling.current.nativeStage, new b2Vec2(0, 40), true);
addEventListener(Event.ENTER_FRAME, updatePhysics);
addSack();
addPresents();
}
private function addSack():void
{
sack = new Image(Assets.getTexture("Sack"));
sack.x = 0;
sack.y = 510;
addChild(sack);
physics.injectPhysics(sack, PhysInjector.SQUARE, new PhysicsProperties({isDynamic:false, friction:0.5, restitution:0.5}));
}
private function addPresents():void
{
for(var i:int = 0; i < 10; i++)
{
var present:Image = new Image(Assets.getTexture("Present01"));
//present.x = 0;
present.y = 434;
if(i < 4)
present.x = i * present.width;
else if (i < 7 && i > 3)
{
present.x = (i-3.5) * present.width;
present.y = present.height * 4.5;
}
else if (i >= 7 && i < 9)
{
present.x = (i-6) * present.width;
present.y = present.height * 3.5;
}
else if (i > 8)
{
present.x = (i-7.5) * present.width;
present.y = present.height * 2.5;
}
addChild(present);
setChildIndex(present, 1);
presents.push(present);
var presentP:PhysicsObject = physics.injectPhysics(present, PhysInjector.SQUARE, new PhysicsProperties({isDynamic:true, isDraggable:false, friction:0.2, restitution:0.5}));
}
}
public function disposeTemporarily():void
{
this.visible = false;
}
public function initialize():void
{
//LaserSFX = new LaserSound();
//Track1SFX = new Track1();
this.visible = true;
scarlet.x = -stage.stageWidth;
scarlet.y = stage.stageHeight * 0.5;
gameState = "idle";
playerSpeed = 0;
difficultyRate = 0.3;
difficulty = 1;
enemySpawnDelay = enemySpawnCounter = 100;
enemySpawnCounter = 100;
enemies = new Array();
lasers = new Array();
addEventListener(Event.ENTER_FRAME, update);
lasersLayer = new Sprite();
enemiesLayer = new Sprite();
addChild(lasersLayer);
addChild(enemiesLayer);
replayBtn.visible = false;
gameOver.visible = false;
startBtn.addEventListener(Event.TRIGGERED, onStartBtnClick);
stage.addEventListener(TouchEvent.TOUCH, shootLaser);
replayBtn.addEventListener(Event.TRIGGERED, onReplayBtnClick);
this.addEventListener(TouchEvent.TOUCH, onTouch);
}
private function onStartBtnClick(event:Event):void
{
startBtn.visible = false;
startBtn.removeEventListener(Event.TRIGGERED, onStartBtnClick);
launchScarlet();
enemies.length = 0;
makeEnemies();
paused = false;
}
private function onReplayBtnClick(event:Event):void
{
replayBtn.visible = false;
replayBtn.removeEventListener(Event.TRIGGERED, onReplayBtnClick);
launchScarlet();
enemies.length = 0;
makeEnemies();
paused = false;
}
private function launchScarlet():void
{
this.addEventListener(TouchEvent.TOUCH, onTouch);
this.addEventListener(Event.ENTER_FRAME, onGameTick);
}
private function onTouch(event:TouchEvent):void
{
touch = event.getTouch(stage);
if(touch){
touchX = touch.globalX;
touchY = touch.globalY;
target.x = event.touches[0].globalX;
target.y = event.touches[0].globalY;
}
}
private function onGameTick(event:Event):void
{
switch(gameState)
{
case"idle":
//Take off
if (scarlet.x < stage.stageWidth * 0.5 * 0.5)
{
scarlet.x += ((stage.stageWidth * 0.5 * 0.5 + 10) - scarlet.x) * 0.5;
scarlet.y = stage.stageHeight * 0.5;
playerSpeed += (MIN_SPEED - playerSpeed) * 0.05;
}
else
{
gameState = "flying";
}
break;
case"flying":
playerSpeed -= (playerSpeed - MIN_SPEED) * 0.01;
scarlet.y -= (scarlet.y - touchY) * 0.4;
if (-(scarlet.y - touchY) < 150 && -(scarlet.y - touchY) > -150)
{
scarlet.rotation = deg2rad(-(scarlet.y - touchY) * 0.075);
}
if (scarlet.y > gameArea.bottom - scarlet.height * 0.5)
{
scarlet.y = gameArea.bottom - scarlet.height * 0.5;
scarlet.rotation = deg2rad(0);
}
if (scarlet.y < gameArea.top + scarlet.height * 0.5)
{
scarlet.y = gameArea.top + scarlet.height * 0.5;
scarlet.rotation = deg2rad(0);
}
break;
case"over":
paused = true;
scarlet.visible = false;
replayBtn.visible = true;
gameOver.visible = true;
//if(presents.length == 0)
// trace("your a loser");
break;
}
}
//addapted from "Shoot"
private function shootLaser(event:TouchEvent):void
{
touch = event.getTouch(this, TouchPhase.ENDED);
if(touch){
var newLaser:Laser = new Laser();
newLaser.x = scarlet.x - 35;
newLaser.y = scarlet.y - 20;
newLaser.xVel = 50;
newLaser.addEventListener(Laser.PURGE_EVENT, purgeLaserHandler);
lasersLayer.addChild(newLaser);
lasers.push(newLaser);
}
}
private function purgeLaserHandler(event:Event):void
{
var targetLaser:Laser = Laser(event.target);
purgeLaser(targetLaser);
}
private function purgeLaser(targetLaser:Laser):void
{
targetLaser.removeEventListener(Laser.PURGE_EVENT, purgeLaserHandler);
try
{
var i:int;
for (i = 0; i < lasers.length; i++)
{
if (lasers[i].name == targetLaser.name)
{
lasers.splice(i, 1);
lasersLayer.removeChild(targetLaser);
i = lasers.length;
}
}
}
catch(e:Error)
{
trace("Failed to delete enemy!", e);
}
}
private function makeEnemies():void
{
enemySpawnCounter++;
if (enemySpawnCounter > enemySpawnDelay)
{
enemySpawnCounter = 0;
enemySpawnDelay -= difficultyRate/5;
difficulty += difficultyRate/5;
makeEnemy();
}
else if (enemySpawnCounter <= enemySpawnDelay)
{
enemySpawnCounter == enemySpawnDelay
}
}
private function makeEnemy():void
{
var i:int;
for (i = 0; i < Math.floor(difficulty); i++)
{
var newEnemy:Enemy = new SnowBall();
newEnemy.x = 925;
newEnemy.y = Math.random() * 375 + 50;
newEnemy.xVel = (-Math.random() * difficulty) - 5;
newEnemy.sinMeter = Math.random() * 10;
newEnemy.bobValue = Math.random() * difficulty;
newEnemy.addEventListener(Enemy.PURGE_EVENT, purgeEnemyHandler);
enemiesLayer.addChild(newEnemy);
enemies.push(newEnemy);
//To make an enemy with gravity
//var enemyP:PhysicsObject = physics.injectPhysics(newEnemy, PhysInjector.CIRCLE, new PhysicsProperties({density:1.5, friction:0.2, restitution:0.5}));
//enemyP.physicsProperties.linearVelocity = new b2Vec2(-20, -8);
}
}
private function purgeEnemyHandler(event:Event):void
{
var targetSnowBall:Enemy = Enemy(event.target);
purgeSnowBall(targetSnowBall);
}
private function purgeSnowBall(targetSnowBall:Enemy):void
{
targetSnowBall.removeEventListener(Enemy.PURGE_EVENT, purgeEnemyHandler);
try
{
var i:int;
for (i = 0; i < enemies.length; i++)
{
if (enemies[i].bobValue == targetSnowBall.bobValue)
{
enemies.splice(i, 1);
//enemiesLayer.removeChild(targetSnowBall);
targetSnowBall.visible = false; // Quick Fix
i = enemies.length;
}
}
}
catch(e:Error)
{
trace("Failed to delete enemy!", e);
}
}
private function laserHitTest(laser:Laser):void
{
for each (var enemy:Enemy in enemies)
{
if (enemy.status != "Dead" && enemy.bounds.intersects(laser.bounds))
{
enemy.status == "Dead";
enemy.destroy();
purgeSnowBall(enemy);
}
}
}
private function presentHitTest(presentP:Image):void
{
var i:int = 0;
for each (var enemy:Enemy in enemies)
{
if (enemy.status != "Dead" && enemy.bounds.intersects(presentP.bounds))
{
enemy.status == "Dead";
enemy.destroy();
purgeSnowBall(enemy);
//purgePresents();
//var presentPhys:PhysicsObject = physics.injectPhysics(presentP, PhysInjector.SQUARE, new PhysicsProperties({isDynamic:true, friction:0.2, restitution:0.5}));
clearPhysics(presentP);
presentP.visible = false; //works but is only a cheap hack
}i++;
}
}
private function purgePresents():void
{
// present.removeEventListener(Laser.PURGE_EVENT, purgeLaserHandler);
var i:int = 0;
for each (var present:Image in presents)
{
if (present.x < -10)
{
clearPhysics(present);
//removeChild(present, true); //Causes Crash in DynamicRegistration.changePropertyOnRegistrationPoint because no parent class
present.visible = false; //Quick fix
presents = presents.splice(i, 1);
// 1. Clear current present of physics
// 2. Make current present invisible (or remove from stage)
// 3. Remove current present from presents array
}
else if(present.y > stage.stageHeight)
{
clearPhysics(present);
//removeChild(present, true);
present.visible = false;
presents = presents.splice(i, 1);
}
i++;
}
}
private function updatePhysics():void
{
physics.update();
}
public function clearPhysics(present:Object):void
{
//removeEventListener(Event.ENTER_FRAME, updatePhysics);
if(physics.bodies.indexOf(present) != -1)
physics.removePhysics(present);
trace("removing physi");
}
private function update():void
{
trace(presents.length);
for each (var enemy:Enemy in enemies)
{
enemy.update();
}
for each (var present:Image in presents)
{
presentHitTest(present);
}
purgePresents();
for each (var laser:Laser in lasers)
{
laser.update();
laserHitTest(laser);
}
if (enemies.length > 15)
{
gameState = "over";
}
if(!paused)
makeEnemies();
}
//addapted from "Shoot"
}
import flash.display.Bitmap;
import flash.media.Sound;
import flash.utils.Dictionary;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
public class Assets
{
[Embed(source="../media/sounds/laser-shot-silenced.mp3")]
private static var LaserSound:Class;
public static var LaserSFX:Sound;
[Embed(source="../media/sounds/mariah-carey-dubstep.mp3")]
private static var Track1:Class;
public static var Track1SFX:Sound;
[Embed(source="../media/graphics/bgWelcome.png")]
public static const BgWelcome:Class;
[Embed(source="../media/graphics/bgInGame.png")]
public static const BgInGame:Class;
[Embed(source="../media/graphics/welcome_scarlet.png")]
public static const WelcomeScarlet:Class;
[Embed(source="../media/graphics/welcome_title.png")]
public static const WelcomeTitle:Class;
[Embed(source="../media/graphics/welcome_startButton.png")]
public static const WelcomeStartBtn:Class;
[Embed(source="../media/graphics/inGame_playButton.png")]
public static const PlayBtn:Class;
[Embed(source="../media/graphics/inGame_replayButton.png")]
public static const ReplayBtn:Class;
[Embed(source="../media/graphics/gameOver.png")]
public static const GameOver:Class;
[Embed(source="../media/graphics/present01.png")]
public static const Present01:Class;
[Embed(source="../media/graphics/sack.png")]
public static const Sack:Class;
[Embed(source="../media/graphics/snowBall.png")]
public static const SnowBall:Class;
[Embed(source="../media/graphics/laser.png")]
public static const Laser:Class;
private static var gameTextures:Dictionary = new Dictionary();
private static var gameTextureAtlas:TextureAtlas;
[Embed(source="../media/graphics/mySpritesheet.png")]
public static const AtlasTextureGame:Class;
[Embed(source="../media/graphics/mySpritesheet.xml", mimeType="application/octet-stream")]
public static const AtlasXmlGame:Class;
public static function getAtlas():TextureAtlas
{
if(gameTextureAtlas == null)
{
var texture:Texture = getTexture("AtlasTextureGame");
var xml:XML = XML(new AtlasXmlGame());
gameTextureAtlas = new TextureAtlas(texture, xml);
}
return gameTextureAtlas;
}
public static function getTexture(name:String):Texture
{
if (gameTextures[name] == undefined)
{
var bitmap:Bitmap = new Assets[name]();
gameTextures[name] = Texture.fromBitmap(bitmap);
}
return gameTextures[name];
}
}
最佳答案
我想您所遵循的教程试图使一切变得非常简单,但是这样做却使它也有些混乱,因为它没有解释它的工作方式和原因。因此,让我们对其进行扩展,使您的Assets类更加灵活和有用。
您的Assets类有2个静态方法来获取和访问您的纹理和textureatlses。通过编写例如可以在任何地方访问这些方法:
Assets.getTexture("PlayBtn");
private static var gameTextures:Dictionary = new Dictionary();
private static var gamesounds:Dictionary = new Dictionary();
public static function getSound(name:String):Sound
{
if (gamesounds[name] == undefined)
{
var sound:Sound = new Assets[name]();
gamesounds[name] = sound;
}
return gamesounds[name];
}
var laser:Sound = Assets.getSound("LaserSound");
laser.play();
关于actionscript-3 - 从Assets类外部初始化八哥的声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24875629/
我在我的应用程序中使用rails 4 和 ruby 1.9.3 以及fancybox2-rails gem,但是 Assets 管道存在一个普遍问题。如果我运行 rake task 进行预编译,那
我把我所有的 Assets 都放在我的包里例如myBundle/Resources/public/css/ 然后像这样加载它们: {% block stylesheets %} {{ parent()
我正在创建RoR-6应用程序,并从此行的application.html.erb文件中引发以下错误: javascript_include_tag 'application', 'data-turbo
我正在对 Play Subproject 功能进行更多扩展测试,如下所述:http://www.playframework.com/documentation/2.0/SBTSubProjects .
我是 symfony 2 和 Assetic 的新手。我想在 CSS 中使用 assetic 和 Sass。我使用自定义字体。我在资源下的包中创建文件夹“assets/css”,里面有 _base.s
这是我的目录结构(这只是一个测试项目): stan@mypc:/generate_assets$ sudo tree -L 3 -p . ├── [drwxr-xr-x] assets │ └─
我使用 node.js connect/express。 有人知道支持 TypeScript 源代码即时编译和缩小的 Assets 管理器吗? 知道如何以编程方式调用编译器吗? 我一直在使用 conn
因此,我们在 Assets 管道摘要方面遇到了一个小问题,因为我们有许多 HTML 模板作为 Assets (对于 AngularJS),并且我们使用 asset_path 在 Javascript
我想从iPad的照片库中获取图像URL。 当我尝试从Image Piicker的信息中获取 UIImagePickerControllerReferenceURL 时 我将URL设为: assets
我正在使用带有Assetic的Symfony 2.1.10版,并且在上次 Composer 更新之后,当我尝试运行php app/console assetic:dump时出现以下错误 Dumping
我的 Assets 管道有问题,我已经有一个名为 Assets 的资源/ Controller 。所以我已将 assets.prefix 选项更改为“/externals”。 config.asset
更新到 Expo sdk 34 后,出现此错误:TypeError:Asset.fromModule 不是函数。 (在“Asset.fromModule(image)”中,“Asset.fromMod
将 Play 框架项目从 2.2.4 迁移到 2.3.8 后遇到问题: 这是运行命令“activatorcompile”的错误输出: [error] ...\workspace\testproject
我在将 Google Analytics 添加到我的 Rails 4 应用程序时遇到了一些困难(参见 this post)。 我通过在 /public/assets/google-analytics.
我正在使用 Symfony2 和 Assetic。最近我一直在做很多 CSS 工作,所以在某个时候我需要命令 $ php app/console assetic:dump --env=prod --n
我正在 Android 开发中迈出第一步,并遇到了 Assets 一词。 据我了解, Assets 只是一个未被解析或引用为资源的文件。 这个词有更准确的定义吗?我应该在哪些情况下在我的应用程序中使用
我添加了 danial-farid--angular-file-upload通过 Rails Assets 将库添加到我的 Rails 4 应用程序。主库加载正常,但 sprockets 找不到它包含
这是我的代码,尽管编码非常粗糙: public void loadStack(AssetManager manager, String path) { String[] lis
我正在使用 Assets 管理我的 Symfony 2 框架中的 CSS 文件。它在生产模式下运行良好。 我的问题是在 Debug模式下,assetic 不断将我的文件合并为一个输出文件。这使得跟踪特
我想以编程方式从重复的相册中删除 Assets (照片不是)。我可以使用照片框架删除相册 我想知道如何从相册中删除 Assets 而不从照片应用中完全删除它。我想在多个地方使用它,例如将 Assets
我是一名优秀的程序员,十分优秀!